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

#### 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

#### 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:

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

#### Dave B.

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

Ah, the intricacies of coding.

#### rbryant

#4
Thanks a lot Eugene.

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

From this:
CODE:

To this?
CODE:

#### Eugene

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

CODE:

#### 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

#### Eugene

#7
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.

#### 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).