Transform DataSeries into binary
Author: rbryant
Creation Date: 11/26/2018 10:27 AM
profile picture

rbryant

#1
Dear all

I want to create a dataseries from another one (eg MACD) which is 1 if MACD (in this example) is above 0, and 0 if MACD is below 0. What is the easiest way to do this, please?

Thanks and regards
Rod
profile picture

Eugene

#2
Hi Rod,

Found this by typing "binary" in the forum search box. This post's been waiting for you for over 7 years! :)

Kaufman's Adaptive Moving Average Binary Wave

I think the pattern is easy enough to grasp even for newbies - maybe except for the "?" ternary operator:

CODE:
Please log in to see this code.


This simply means that if k[bar] is declining then we assign the AMALow the current value of k[bar], and retain it otherwise. Here's a quick explanation with examples:

http://www.tutorialsteacher.com/csharp/csharp-ternary-operator
profile picture

Dave B.

#3
Funny how the two (2) examples in the tutorial don't produce the exact same result.

Ah, the intricacies of coding.
profile picture

rbryant

#4
Thanks a lot Eugene.

Can this code be simplified to what I show below, if no filter is required?

From this:
CODE:
Please log in to see this code.

To this?
CODE:
Please log in to see this code.
profile picture

Eugene

#5
Here's a simplified example using random numbers:

CODE:
Please log in to see this code.
profile picture

rbryant

#6
Thanks Eugene.

I love this - simple as can be:
QUOTE:
bWave[bar] = dice > 0 ? 1.0 : -1.0;


What is the purpose of this part:
QUOTE:
bWave[bar] = bWave[bar] != bWave[bar-1] ? bWave[bar] : bWave[bar - 1];


Thanks and regards

Rod
profile picture

Eugene

#7
Rod, I read that as
QUOTE:
I love this...
... [bar]

...and this reminded me of that song title by Toby Keith :lol:

QUOTE:
What is the purpose of this part:

Please disregard, it's irrelevant to this context. I've removed it from the sample code.
profile picture

rbryant

#8
lol. thanks.
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).