TTM_Wave For ThinkorSwim

Dix

New member
In my watchlists I would like to add a column where I can see the values of the TTM Wave for each stock. Can someone assist with the code part? I know how to add columns to my watchlists, etc. Essentially I want to run a pre-market scan to see for example TTM Waves that are greater than +2 or less than -2 for example. I know how to build the scan but also want to add the TTM Wave values to my watchlist for easier sorting. Thanks!
 
It's already available as one of the built-in watchlist columns in ThinkorSwim. You just have to add it.

zWbQDmQ.png
 
Thanks Ben. I literally checked before writing this post and it wasn't there which was weird. Anyway I restarted my TOS and viola! it was there. Thanks.

I thought I had it figured out but still need help. The values I would like to extract are the high wave values and low wave values. In the screen show below, when I add the TTM Wave column it gives me the 0.2188 value however I would like to obtain the 8.38275 value. On the flip side, when that value is negative I would like to extract that negative value when it drops below zero. Hopefully this makes sense. Thanks!

Jr33Y43.png
 
Code:
plot value = TTM_Wave()."Wave1" is greater than TTM_Wave()."Wave1" from 1 bars ago;
AssignBackgroundColor(if value == 1 then color.yellow else color.Dark_Red);
value. Assignvaluecolor(if value == 1then color. Black else color.Current);
 
Found this code for adding vertical lines on a MACD cross.
Can anyone adapt this script, if it's even possible, to draw vertical lines on the upper chart, when the ttm_wave A B C histogram crosses the zero line?
Maybe have inputs to select which waves to toggle on or off. Thanks!
A-wave (Wave1)
C-wave (Wave2High)
B-wave - (Wave2Low)

Code:
def condM1CrossUndr0 = reference macd().Value < 0 and reference macd().Value > reference
macd().Avg;
Addlabel(condM1CrossUndr0, "M1”, Color.Green);
addverticalLine(condM1CrossUndr0[1]==0 and condm1CrossUndr0,"",color.green);
 
Last edited:
I cobbled this together, and believe it works. When all waves are above the zero line you'll see a vertical dark green line on your upper chart. If one one the waves is equal-to, or below I changed the line to black to make it disappear. Is there a better way to do do that?
Code:
# Draw Vertical Signal when All Histogram Waves are above the Zero Line

AddVerticalLine(close, ”” , (if TTM_Wave()."Wave1" >0 and TTM_Wave()."Wave2high" >0 and  TTM_Wave()."Wave2low" >0 then Color.DARK_GREEN else Color.BLACK));
 
Last edited:
I cobbled this together, and believe it works. When all waves are above the zero line you'll see a vertical dark green line on your upper chart. If one one the waves is equal-to, or below I changed the line to black to make it disappear. Is there a better way to do do that?
Code:
# Draw Vertical Signal when All Histogram Waves are above the Zero Line

AddVerticalLine(close, ”” , (if TTM_Wave()."Wave1" >0 and TTM_Wave()."Wave2high" >0 and  TTM_Wave()."Wave2low" >0 then Color.DARK_GREEN else Color.BLACK));

post1
i doubt more than one signal will cross on the same bar. Usually you pick 1 signal to look for a cross and the others to see if they are greater than something.
but here is something to try.

input wave_crossing_level = 0;

def ttmw1 = TTM_Wave()."Wave1" ;
def ttmwhi = TTM_Wave()."Wave2high" ;
def ttmwlo = TTM_Wave()."Wave2low";

def allup = if ttmw1 > 0 and ttmwhi > 0 and ttmwlo > 0 then 1 else 0;

AddVerticalLine( allup, "--", color.DARK_GREEN );

# check for ttms crossing a level
def ttmw1x = ttmw1 crosses wave_crossing_level;
def ttmwhix = ttmwhi crosses wave_crossing_level;
def ttmwlox = ttmwlo crosses wave_crossing_level;

def allcross = if ( ttmw1x + ttmwhix + ttmwlox ) == 3 then 1 else 0;

AddVerticalLine( allcross, "cross", color.magenta );


-------------
post2
the 1st parameter of a addverticalline is yes no, to show it or not show. You could add conditions here that would cause the line to be visible or not.
by putting close in there, something that always has a number above 0, it is interpreted as true, and always shows.

If I am pulling external data, I always set it equal to a variable. Then I can reference that variable in multiple places, And not have to read the same external data again.
I try to set up long formulas equal to a variable and then reference the variable in plot formulas.
Separating things out ahead of time makes it a lot easier for understanding the code. it also helps if it needs debugging, plotting values in a bubble, to make sure it has the right value.

def ttmw1 = TTM_Wave()."Wave1" ;
def ttmwhi = TTM_Wave()."Wave2high" ;
def ttmwlo = TTM_Wave()."Wave2low";

def allup = if ttmw1 > 0 and ttmwhi > 0 and ttmwlo > 0 then 1 else 0;

AddVerticalLine( allup, "--", DARK_GREEN );

https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Look---Feel/AddVerticalLine
 
Here is my conversion for ThinkorSwim. You need to choose Histograms of Waves A, B and C instead of lines in indicator properties and select colors that you would like to show trend changes.
TcBioPR.png

#https://www.tradingview.com/script/nYOzTA1Y-UCS-TTM-Wave-A-B-C/
Ruby:
#[URL]https://www.tradingview.com/script/nYOzTA1Y-UCS-TTM-Wave-A-B-C/[/URL]
declare lower;
input usewa = yes;
input usewb = yes;
input usewc = yes;
script nz {
    input data = 0;
    def ret_val = if IsNaN(data) then 0 else data;
    plot return = ret_val;
}
# WAVE CALC
# Wave A
def fastMA1 = if usewa == yes then ExpAverage(close, 8) else nz(0);
def slowMA1 = if usewa == yes then ExpAverage(close, 34) else nz(0);
def macd1 = if usewa == yes then fastMA1 - slowMA1 else  nz(0);
def signal1 = if  usewa == yes then ExpAverage(macd1, 34) else nz(0);
def hist1 = if usewa == yes then macd1 - signal1 else nz(0);

def fastMA2 = if usewa == yes then ExpAverage(close, 8) else nz(0);
def slowMA2 = if usewa == yes then ExpAverage(close, 55) else nz(0);
def macd2 = if usewa == yes then fastMA2 - slowMA2 else nz(0);
def signal2 = if usewa == yes then ExpAverage(macd2, 55) else nz(0);
def hist2 = if usewa == yes then macd2 - signal2 else nz(0);

# Wave B
def fastMA3 = if usewb == yes then ExpAverage(close, 8) else nz(0);
def slowMA3 = if usewb == yes then ExpAverage(close, 89) else nz(0);
def macd3 = if usewb == yes then fastMA3 - slowMA3 else nz(0);
def signal3 = if usewb == yes then ExpAverage(macd3, 89) else nz(0);
def hist3 = if usewb == yes then macd3 - signal3 else nz(0);

def fastMA4 = if usewb == yes then ExpAverage(close, 8) else nz(0);
def slowMA4 = if usewb == yes then ExpAverage(close, 144) else nz(0);
def macd4 = if usewb == yes then fastMA4 - slowMA4 else nz(0);
def signal4 = if usewb == yes then ExpAverage(macd4, 144) else nz(0);
def hist4 = if usewb == yes then macd4 - signal4 else nz(0);

# Wave C
def fastMA5 = if usewc == yes then ExpAverage(close, 8) else nz(0);
def slowMA5 = if usewc == yes then ExpAverage(close, 233) else nz(0);
def macd5 = if usewc == yes then fastMA5 - slowMA5 else nz(0);
def signal5 = if usewc == 0 then ExpAverage(macd5, 233) else nz(0);
def hist5 = if usewc == 0 then macd5 - signal5 else nz(0);

def fastMA6 = if usewc == yes then ExpAverage(close, 8) else nz(0);
def slowMA6 = if  usewc == yes then ExpAverage(close, 377) else nz(0);
def macd6 = if usewc == yes then fastMA6 - slowMA6 else nz(0);

# PLOTs
plot WaveC1 = macd6;
plot WaveC2 = hist5;
plot WeveB1 = hist4;
plot WaveB2 = hist3;
plot WaveA1 = hist2;
plot WaveA2 = hist1;
 
Last edited by a moderator:
Here is my conversion for ThinkorSwim. You need to choose Histograms of Waves A, B and C instead of lines in indicator properties and select colors that you would like to show trend changes.

#https://www.tradingview.com/script/nYOzTA1Y-UCS-TTM-Wave-A-B-C/
Ruby:
#[URL]https://www.tradingview.com/script/nYOzTA1Y-UCS-TTM-Wave-A-B-C/[/URL]
declare lower;
input usewa = yes;
input usewb = yes;
input usewc = yes;
script nz {
    input data = 0;
    def ret_val = if IsNaN(data) then 0 else data;
    plot return = ret_val;
}
# WAVE CALC
# Wave A
def fastMA1 = if usewa == yes then ExpAverage(close, 8) else nz(0);
def slowMA1 = if usewa == yes then ExpAverage(close, 34) else nz(0);
def macd1 = if usewa == yes then fastMA1 - slowMA1 else  nz(0);
def signal1 = if  usewa == yes then ExpAverage(macd1, 34) else nz(0);
def hist1 = if usewa == yes then macd1 - signal1 else nz(0);

def fastMA2 = if usewa == yes then ExpAverage(close, 8) else nz(0);
def slowMA2 = if usewa == yes then ExpAverage(close, 55) else nz(0);
def macd2 = if usewa == yes then fastMA2 - slowMA2 else nz(0);
def signal2 = if usewa == yes then ExpAverage(macd2, 55) else nz(0);
def hist2 = if usewa == yes then macd2 - signal2 else nz(0);

# Wave B
def fastMA3 = if usewb == yes then ExpAverage(close, 8) else nz(0);
def slowMA3 = if usewb == yes then ExpAverage(close, 89) else nz(0);
def macd3 = if usewb == yes then fastMA3 - slowMA3 else nz(0);
def signal3 = if usewb == yes then ExpAverage(macd3, 89) else nz(0);
def hist3 = if usewb == yes then macd3 - signal3 else nz(0);

def fastMA4 = if usewb == yes then ExpAverage(close, 8) else nz(0);
def slowMA4 = if usewb == yes then ExpAverage(close, 144) else nz(0);
def macd4 = if usewb == yes then fastMA4 - slowMA4 else nz(0);
def signal4 = if usewb == yes then ExpAverage(macd4, 144) else nz(0);
def hist4 = if usewb == yes then macd4 - signal4 else nz(0);

# Wave C
def fastMA5 = if usewc == yes then ExpAverage(close, 8) else nz(0);
def slowMA5 = if usewc == yes then ExpAverage(close, 233) else nz(0);
def macd5 = if usewc == yes then fastMA5 - slowMA5 else nz(0);
def signal5 = if usewc == 0 then ExpAverage(macd5, 233) else nz(0);
def hist5 = if usewc == 0 then macd5 - signal5 else nz(0);

def fastMA6 = if usewc == yes then ExpAverage(close, 8) else nz(0);
def slowMA6 = if  usewc == yes then ExpAverage(close, 377) else nz(0);
def macd6 = if usewc == yes then fastMA6 - slowMA6 else nz(0);

# PLOTs
plot WaveC1 = macd6;
plot WaveC2 = hist5;
plot WeveB1 = hist4;
plot WaveB2 = hist3;
plot WaveA1 = hist2;
plot WaveA2 = hist1;
In order to show Waves A only , you can use following code to replace last six lines of the code above
#plot WaveC1 = macd6;
#plot WaveC2 = hist5;
#plot WeveB1 = hist4;
#plot WaveB2 = hist3;
plot WaveA1 = hist2;
plot WaveA2 = hist1;

In order to show Waves B only, you can use following code to replace last six lines of the code above
#plot WaveC1 = macd6;
#plot WaveC2 = hist5;
plot WeveB1 = hist4;
plot WaveB2 = hist3;
#plot WaveA1 = hist2;
#plot WaveA2 = hist1;

In order to show Waves C only, you can use following code to replace last six lines of the code above

plot WaveC1 = macd6;
plot WaveC2 = hist5;
#plot WeveB1 = hist4;
#plot WaveB2 = hist3;
#plot WaveA1 = hist2;
#plot WaveA2 = hist1;
 
Last edited by a moderator:
In order to show Waves A only , you can use following code to replace last six lines of the code above
#plot WaveC1 = macd6;
#plot WaveC2 = hist5;
#plot WeveB1 = hist4;
#plot WaveB2 = hist3;
plot WaveA1 = hist2;
plot WaveA2 = hist1;

In order to show Waves B only, you can use following code to replace last six lines of the code above
#plot WaveC1 = macd6;
#plot WaveC2 = hist5;
plot WeveB1 = hist4;
plot WaveB2 = hist3;
#plot WaveA1 = hist2;
#plot WaveA2 = hist1;

In order to show Waves C only, you can use following code to replace last six lines of the code above

plot WaveC1 = macd6;
plot WaveC2 = hist5;
#plot WeveB1 = hist4;
#plot WaveB2 = hist3;
#plot WaveA1 = hist2;
#plot WaveA2 = hist1;
Another option to show three waves at the same time is to load the Indicator three times, turn off the other two Waves. For example, check Wave A, and uncheck Waves B and C in order to show Wave A only.
 
Here is the code for Wave A only, which will speed up your system in case you do not need Waves B and C.

Ruby:
declare lower;
input usewa = yes;
script nz {
    input data = 0;
    def ret_val = if IsNaN(data) then 0 else data;
    plot return = ret_val;
}
# WAVE CALC
# Wave A
def fastMA1 = if usewa == yes then ExpAverage(close, 8) else nz(0);
def slowMA1 = if usewa == yes then ExpAverage(close, 34) else nz(0);
def macd1 = if usewa == yes then fastMA1 - slowMA1 else  nz(0);
def signal1 = if  usewa == yes then ExpAverage(macd1, 34) else nz(0);
def hist1 = if usewa == yes then macd1 - signal1 else nz(0);

def fastMA2 = if usewa == yes then ExpAverage(close, 8) else nz(0);
def slowMA2 = if usewa == yes then ExpAverage(close, 55) else nz(0);
def macd2 = if usewa == yes then fastMA2 - slowMA2 else nz(0);
def signal2 = if usewa == yes then ExpAverage(macd2, 55) else nz(0);
def hist2 = if usewa == yes then macd2 - signal2 else nz(0);

plot WaveA1 = hist2;
plot WaveA2 = hist1;
 
Last edited:
Here is the code for Wave B only, which will speed up your system in case you do not need Waves A and C.

Ruby:
declare lower;
input usewb = yes;
script nz {
    input data = 0;
    def ret_val = if IsNaN(data) then 0 else data;
    plot return = ret_val;
}
# WAVE CALC

# Wave B
def fastMA3 = if usewb == yes then ExpAverage(close, 8) else nz(0);
def slowMA3 = if usewb == yes then ExpAverage(close, 89) else nz(0);
def macd3 = if usewb == yes then fastMA3 - slowMA3 else nz(0);
def signal3 = if usewb == yes then ExpAverage(macd3, 89) else nz(0);
def hist3 = if usewb == yes then macd3 - signal3 else nz(0);

def fastMA4 = if usewb == yes then ExpAverage(close, 8) else nz(0);
def slowMA4 = if usewb == yes then ExpAverage(close, 144) else nz(0);
def macd4 = if usewb == yes then fastMA4 - slowMA4 else nz(0);
def signal4 = if usewb == yes then ExpAverage(macd4, 144) else nz(0);
def hist4 = if usewb == yes then macd4 - signal4 else nz(0);

plot WeveB1 = hist4;
plot WaveB2 = hist3;
 
Last edited:
Here is the code for Wave C only, which will speed up your system in case you do not need Waves A and B.
Code:
declare lower;
input usewc = yes;
script nz {
    input data = 0;
    def ret_val = if IsNaN(data) then 0 else data;
    plot return = ret_val;
}
# WAVE CALC
# Wave C
def fastMA5 = if usewc == yes then ExpAverage(close, 8) else nz(0);
def slowMA5 = if usewc == yes then ExpAverage(close, 233) else nz(0);
def macd5 = if usewc == yes then fastMA5 - slowMA5 else nz(0);
def signal5 = if usewc == 0 then ExpAverage(macd5, 233) else nz(0);
def hist5 = if usewc == 0 then macd5 - signal5 else nz(0);

def fastMA6 = if usewc == yes then ExpAverage(close, 8) else nz(0);
def slowMA6 = if  usewc == yes then ExpAverage(close, 377) else nz(0);
def macd6 = if usewc == yes then fastMA6 - slowMA6 else nz(0);

# PLOTs
plot WaveC1 = macd6;
plot WaveC2 = hist5;
 
Last edited:
Here is my conversion for ThinkorSwim. You need to choose Histograms of Waves A, B and C instead of lines in indicator properties and select colors that you would like to show trend changes.
TcBioPR.png

#https://www.tradingview.com/script/nYOzTA1Y-UCS-TTM-Wave-A-B-C/
Ruby:
#[URL]https://www.tradingview.com/script/nYOzTA1Y-UCS-TTM-Wave-A-B-C/[/URL]
declare lower;
input usewa = yes;
input usewb = yes;
input usewc = yes;
script nz {
    input data = 0;
    def ret_val = if IsNaN(data) then 0 else data;
    plot return = ret_val;
}
# WAVE CALC
# Wave A
def fastMA1 = if usewa == yes then ExpAverage(close, 8) else nz(0);
def slowMA1 = if usewa == yes then ExpAverage(close, 34) else nz(0);
def macd1 = if usewa == yes then fastMA1 - slowMA1 else  nz(0);
def signal1 = if  usewa == yes then ExpAverage(macd1, 34) else nz(0);
def hist1 = if usewa == yes then macd1 - signal1 else nz(0);

def fastMA2 = if usewa == yes then ExpAverage(close, 8) else nz(0);
def slowMA2 = if usewa == yes then ExpAverage(close, 55) else nz(0);
def macd2 = if usewa == yes then fastMA2 - slowMA2 else nz(0);
def signal2 = if usewa == yes then ExpAverage(macd2, 55) else nz(0);
def hist2 = if usewa == yes then macd2 - signal2 else nz(0);

# Wave B
def fastMA3 = if usewb == yes then ExpAverage(close, 8) else nz(0);
def slowMA3 = if usewb == yes then ExpAverage(close, 89) else nz(0);
def macd3 = if usewb == yes then fastMA3 - slowMA3 else nz(0);
def signal3 = if usewb == yes then ExpAverage(macd3, 89) else nz(0);
def hist3 = if usewb == yes then macd3 - signal3 else nz(0);

def fastMA4 = if usewb == yes then ExpAverage(close, 8) else nz(0);
def slowMA4 = if usewb == yes then ExpAverage(close, 144) else nz(0);
def macd4 = if usewb == yes then fastMA4 - slowMA4 else nz(0);
def signal4 = if usewb == yes then ExpAverage(macd4, 144) else nz(0);
def hist4 = if usewb == yes then macd4 - signal4 else nz(0);

# Wave C
def fastMA5 = if usewc == yes then ExpAverage(close, 8) else nz(0);
def slowMA5 = if usewc == yes then ExpAverage(close, 233) else nz(0);
def macd5 = if usewc == yes then fastMA5 - slowMA5 else nz(0);
def signal5 = if usewc == 0 then ExpAverage(macd5, 233) else nz(0);
def hist5 = if usewc == 0 then macd5 - signal5 else nz(0);

def fastMA6 = if usewc == yes then ExpAverage(close, 8) else nz(0);
def slowMA6 = if  usewc == yes then ExpAverage(close, 377) else nz(0);
def macd6 = if usewc == yes then fastMA6 - slowMA6 else nz(0);

# PLOTs
plot WaveC1 = macd6;
plot WaveC2 = hist5;
plot WeveB1 = hist4;
plot WaveB2 = hist3;
plot WaveA1 = hist2;
plot WaveA2 = hist1;

Here is my conversion for ThinkorSwim. You need to choose Histograms of Waves A, B and C instead of lines in indicator properties and select colors that you would like to show trend changes.
TcBioPR.png

#https://www.tradingview.com/script/nYOzTA1Y-UCS-TTM-Wave-A-B-C/
Ruby:
#[URL]https://www.tradingview.com/script/nYOzTA1Y-UCS-TTM-Wave-A-B-C/[/URL]
declare lower;
input usewa = yes;
input usewb = yes;
input usewc = yes;
script nz {
    input data = 0;
    def ret_val = if IsNaN(data) then 0 else data;
    plot return = ret_val;
}
# WAVE CALC
# Wave A
def fastMA1 = if usewa == yes then ExpAverage(close, 8) else nz(0);
def slowMA1 = if usewa == yes then ExpAverage(close, 34) else nz(0);
def macd1 = if usewa == yes then fastMA1 - slowMA1 else  nz(0);
def signal1 = if  usewa == yes then ExpAverage(macd1, 34) else nz(0);
def hist1 = if usewa == yes then macd1 - signal1 else nz(0);

def fastMA2 = if usewa == yes then ExpAverage(close, 8) else nz(0);
def slowMA2 = if usewa == yes then ExpAverage(close, 55) else nz(0);
def macd2 = if usewa == yes then fastMA2 - slowMA2 else nz(0);
def signal2 = if usewa == yes then ExpAverage(macd2, 55) else nz(0);
def hist2 = if usewa == yes then macd2 - signal2 else nz(0);

# Wave B
def fastMA3 = if usewb == yes then ExpAverage(close, 8) else nz(0);
def slowMA3 = if usewb == yes then ExpAverage(close, 89) else nz(0);
def macd3 = if usewb == yes then fastMA3 - slowMA3 else nz(0);
def signal3 = if usewb == yes then ExpAverage(macd3, 89) else nz(0);
def hist3 = if usewb == yes then macd3 - signal3 else nz(0);

def fastMA4 = if usewb == yes then ExpAverage(close, 8) else nz(0);
def slowMA4 = if usewb == yes then ExpAverage(close, 144) else nz(0);
def macd4 = if usewb == yes then fastMA4 - slowMA4 else nz(0);
def signal4 = if usewb == yes then ExpAverage(macd4, 144) else nz(0);
def hist4 = if usewb == yes then macd4 - signal4 else nz(0);

# Wave C
def fastMA5 = if usewc == yes then ExpAverage(close, 8) else nz(0);
def slowMA5 = if usewc == yes then ExpAverage(close, 233) else nz(0);
def macd5 = if usewc == yes then fastMA5 - slowMA5 else nz(0);
def signal5 = if usewc == 0 then ExpAverage(macd5, 233) else nz(0);
def hist5 = if usewc == 0 then macd5 - signal5 else nz(0);

def fastMA6 = if usewc == yes then ExpAverage(close, 8) else nz(0);
def slowMA6 = if  usewc == yes then ExpAverage(close, 377) else nz(0);
def macd6 = if usewc == yes then fastMA6 - slowMA6 else nz(0);

# PLOTs
plot WaveC1 = macd6;
plot WaveC2 = hist5;
plot WeveB1 = hist4;
plot WaveB2 = hist3;
plot WaveA1 = hist2;
plot WaveA2 = hist1;
Where can I change it to histogram instead of lines? Thx. BTW, this is awesome.
 
Here is my conversion for ThinkorSwim. You need to choose Histograms of Waves A, B and C instead of lines in indicator properties and select colors that you would like to show trend changes.

I see you had trouble making a fully functional conversion, so i made one.

I used an input to pick a wave, A , B, or C.
you can't shift histograms vertically, so you can't show several of them stacked, on 1 chart. maybe that is why you didn't program the plots as histograms.
you can use an input, to select 1 of them to be displayed. that is how the original was programmed.
used an input and switch-case to pick 1 of the waves to show.
(an alternative could be to use addchart() to draw all the bars and shift the waves vertically, to show all 3 on 1 chart)

the original code had na and was intended to set a double.nan value, if an input was false, so a value wouldn't be plotted. there was no need to make a sub script to evaluate 0.

added inputs for all of the function lengths.
added labels to show which wave is picked.

looked at the pine study and copied the colors used in the waves.

orig colors
wave A - green / yellow
wave B - pink / blue
wave C - red / orange


Ruby:
# TTM_Wave_A_B_C_00b

# https://www.tradingview.com/script/nYOzTA1Y-UCS-TTM-Wave-A-B-C/

declare lower;

def na = double.nan;

input wave = { default "A" , "B" , "C" };

def wave_a;
def wave_b;
def wave_c;
switch (wave) {
case "A":
 wave_a = 1;
 wave_b = 0;
 wave_c = 0;
case "B":
 wave_a = 0;
 wave_b = 1;
 wave_c = 0;
case "C":
 wave_a = 0;
 wave_b = 0;
 wave_c = 1;
}


# WAVE CALC
# Wave A
input a1_fast_len = 8;
input a1_slow_len = 34;
input a1_signal_len = 34;
def fastMA1 = ExpAverage(close, a1_fast_len);
def slowMA1 = ExpAverage(close, a1_slow_len);
def macd1 = fastMA1 - slowMA1;
def signal1 = ExpAverage(macd1, a1_signal_len);
def hist1 = macd1 - signal1;

input a2_fast_len = 8;
input a2_slow_len = 55;
input a2_signal_len = 55;
def fastMA2 = ExpAverage(close, a2_fast_len);
def slowMA2 = ExpAverage(close, a2_slow_len);
def macd2 = fastMA2 - slowMA2;
def signal2 = ExpAverage(macd2, a2_signal_len);
def hist2 = macd2 - signal2;

# Wave B
input b3_fast_len = 8;
input b3_slow_len = 89;
input b3_signal_len = 89;
def fastMA3 = ExpAverage(close, b3_fast_len);
def slowMA3 = ExpAverage(close, b3_slow_len);
def macd3 = fastMA3 - slowMA3;
def signal3 = ExpAverage(macd3, b3_signal_len);
def hist3 = macd3 - signal3;

input b4_fast_len = 8;
input b4_slow_len = 144;
input b4_signal_len = 144;
def fastMA4 = ExpAverage(close, b4_fast_len);
def slowMA4 = ExpAverage(close, b4_slow_len);
def macd4 = fastMA4 - slowMA4;
def signal4 = ExpAverage(macd4, b4_signal_len);
def hist4 = macd4 - signal4;

# Wave C
input c5_fast_len = 8;
input c5_slow_len = 233;
input c5_signal_len = 233;
def fastMA5 = ExpAverage(close, c5_fast_len);
def slowMA5 = ExpAverage(close, c5_slow_len);
def macd5 = fastMA5 - slowMA5;
def signal5 = ExpAverage(macd5, c5_signal_len);
def hist5 = macd5 - signal5;

input c6_fast_len = 8;
input c6_slow_len = 377;
input c6_signal_len = 377;
def fastMA6 = ExpAverage(close, c6_fast_len);
def slowMA6 = ExpAverage(close, c6_slow_len);
def macd6 = fastMA6 - slowMA6;


addlabel( wave_a , "Wave A",  color.green);
addlabel( wave_b , "Wave B",  color.pink);
addlabel( wave_c , "Wave C",  color.red);

# orig colors
# wave A - green / yellow
# wave B - pink / blue
# wave C - red / orange

plot WaveA1 = if wave_a then hist2 else na;
plot WaveA2 = if wave_a then hist1 else na;
wavea1.SetPaintingStrategy(PaintingStrategy.histogram);
wavea2.SetPaintingStrategy(PaintingStrategy.histogram);
WaveA1.SetDefaultColor(Color.green);
WaveA2.SetDefaultColor(Color.yellow);

plot WaveB1 = if wave_b then hist4 else na;
plot WaveB2 = if wave_b then hist3 else na;
waveb1.SetPaintingStrategy(PaintingStrategy.histogram);
waveb2.SetPaintingStrategy(PaintingStrategy.histogram);
Waveb1.SetDefaultColor(Color.pink);
Waveb2.SetDefaultColor(Color.blue);

plot WaveC1 = if wave_c then macd6 else na;
plot WaveC2 = if wave_c then hist5 else na;
wavec1.SetPaintingStrategy(PaintingStrategy.histogram);
wavec2.SetPaintingStrategy(PaintingStrategy.histogram);
Wavec1.SetDefaultColor(Color.red);
Wavec2.SetDefaultColor(Color.orange);
#


https://www.tradingview.com/pine-script-reference/#var_na
na
Double.NaN value (Not a Number).
TYPE
na
EXAMPLE
n < 10 ? na : close // CORRECT close == na ? close[1] : close // INCORRECT! na(close) ? close[1] : close // CORRECT
REMARKS
Use it for return values ONLY. DON'T TRY TO COMPARE WITH IT! If you need to check if some value is NaN, use built-in function na.
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
375 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top