Is there a dashboard for MACD?
Last edited by a moderator:
Is there any indicator similar to bottom pane for MACD?
Ruby:# Choose how the candles are being colored (green/red) in Multiple user defined TimeFrames by one of 4 methods. # Labels show current color status # Trend method is similar but not exactly like TTM_Trend # Move study from lower to upper and select "upper" at the input useupperlower to display dots on upper price panel. Uncheck at input screen "use left axis" # Using the study on the lower panel, select "lower" at the input useupperlower to lower to display dots on lower panel # Dots can be turned off/on at the input screen # Summary line shows only if all colors are the same, otherwise blank. declare lower; input method = {default "MACD", "Close_Close[1]", "HAOpen_HAClose", "Trend", "HHLLS"}; input useupper_lower = {default lower, upper}; input showdotplot = yes; input agg1 = AggregationPeriod.MIN; input agg2 = AggregationPeriod.TWO_MIN; input agg3 = AggregationPeriod.THREE_MIN; #Heiken Ashi defined def HAclose1 = ohlc4(period = agg1); def HAopen1 = CompoundValue( 1, ( HAopen1[1] + HAclose1[1] ) / 2, HAclose1 ); def HAclose2 = ohlc4(period = agg2); def HAopen2 = CompoundValue( 1, ( HAopen2[1] + HAclose2[1] ) / 2, HAclose2 ); def HAclose3 = ohlc4(period = agg3); def HAopen3 = CompoundValue( 1, ( HAopen3[1] + HAclose3[1] ) / 2, HAclose3 ); #Trend defined input trend_lookback = 6; def HH1 = (Highest(high(period = agg1) , trend_lookback) + Lowest(low(period = agg1), trend_lookback)) / 2; def Trend1 = close(period = agg1) > HH1; def HH2 = (Highest(high(period = agg2) , trend_lookback) + Lowest(low(period = agg2), trend_lookback)) / 2; def Trend2 = close(period = agg2) > HH2; def HH3 = (Highest(high(period = agg3) , trend_lookback) + Lowest(low(period = agg3), trend_lookback)) / 2; def Trend3 = close(period = agg3) > HH3; #MACD input fastlength = 12; input slowlength = 26; input macdlength = 9; input averagetype = AverageType.EXPONENTIAL; def Value1 = MovingAverage(averagetype, close(period = agg1), fastlength) - MovingAverage(averagetype, close(period = agg1), slowlength); def Avg1 = MovingAverage(averagetype, Value1, macdlength); def MACD1 = Value1 - Avg1; def Value2 = MovingAverage(averagetype, close(period = agg2), fastlength) - MovingAverage(averagetype, close(period = agg2), slowlength); def Avg2 = MovingAverage(averagetype, Value2, macdlength); def MACD2 = Value2 - Avg2; def Value3 = MovingAverage(averagetype, close(period = agg3), fastlength) - MovingAverage(averagetype, close(period = agg3), slowlength); def Avg3 = MovingAverage(averagetype, Value3, macdlength); def MACD3 = Value3 - Avg3; #HHKKS input length = 20; input over_bought = 60; input signal_line = 50; input over_sold = 10; input averageTypehhlls = AverageType.EXPONENTIAL; Assert(length > 1, "'length' must be greater than one: " + length); def HS1 = if high (period = agg1) > high(period= agg1)[1] then (high (period= agg1) - Lowest(high (period= agg1), length)) / (Highest(high (period= agg1), length) - Lowest(high (period= agg1), length)) else 0; def LS1 = if low (period= agg1)< low(period= agg1)[1] then (Highest(low(period= agg1), length) - low(period= agg1)) / (Highest(low(period= agg1), length) - Lowest(low(period= agg1), length)) else 0; def HHS1 = 100 * MovingAverage(averageTypehhlls, HS1, length); def LLS1 = 100 * MovingAverage(averageTypehhlls, LS1, length); def HS2 = if high (period = agg2) > high(period= agg2)[1] then (high (period= agg2) - Lowest(high (period= agg2), length)) / (Highest(high (period= agg2), length) - Lowest(high (period= agg2), length)) else 0; def LS2 = if low (period= agg2)< low(period= agg2)[1] then (Highest(low(period= agg2), length) - low(period= agg2)) / (Highest(low(period= agg2), length) - Lowest(low(period= agg2), length)) else 0; def HHS2 = 100 * MovingAverage(averageTypehhlls, HS2, length); def LLS2 = 100 * MovingAverage(averageTypehhlls, LS2, length); def HS3 = if high (period = agg3) > high(period= agg3)[1] then (high (period= agg3) - Lowest(high (period= agg3), length)) / (Highest(high (period= agg3), length) - Lowest(high (period= agg3), length)) else 0; def LS3 = if low (period= agg3)< low(period= agg3)[1] then (Highest(low(period= agg3), length) - low(period= agg3)) / (Highest(low(period= agg3), length) - Lowest(low(period= agg3), length)) else 0; def HHS3 = 100 * MovingAverage(averageTypehhlls, HS3, length); def LLS3 = 100 * MovingAverage(averageTypehhlls, LS3, length); #Method applied to each aggregation def Agg1per; def Agg2per; def Agg3per; plot Agg1lower; plot Agg2lower; plot Agg3lower; if method == method."Close_Close[1]" { Agg1per = close(period = agg1) > close(period = agg1)[1]; Agg2per = close(period = agg2) > close(period = agg2)[1]; Agg3per = close(period = agg3) > close(period = agg3)[1]; } else if method == method."HAOpen_HAClose" { Agg1per = HAclose1 > HAopen1; Agg2per = HAclose2 > HAopen2; Agg3per = HAclose3 > HAopen3; } else if method == method."Trend" { Agg1per = Trend1; Agg2per = Trend2; Agg3per = Trend3; } else if method == method."HHLLS" { Agg1per = HHS1 > LLS1; Agg2per = HHS2 > LLS2; Agg3per = HHS3 > LLS3; } else { Agg1per = Value1 > Avg1; Agg2per = Value2 > Avg2; Agg3per = Value3 > Avg3; } #Labels with selection to turn them on/off input showlabels = yes; AddLabel(showlabels, if agg1 / 60000 <= 240 then (agg1 / 60000 + " Min") else if agg1 / 60000 == 1440 then "Day" else if agg1 / 60000 == 10080 then "Week" else if agg1 / 60000 == 43200 then "Month" else " ", if (Agg1per == 1 and method == method."HHLLS") or (Agg1per == 1 and method == method."MACD" and Value1 > 0) or (Agg1per == 1 and method != method."MACD" and method != method."HHLLS") then Color.GREEN else if (Agg1per == 1 and method == method."MACD" and Value1 < 0) then Color.DARK_GREEN else if (Agg1per == 0 and method == method."MACD" and Value1 < 0) then Color.DARK_RED else Color.RED); AddLabel(showlabels, if agg2 / 60000 <= 240 then (agg2 / 60000 + " Min") else if agg2 / 60000 == 1440 then "Day" else if agg2 / 60000 == 10080 then "Week" else if agg2 / 60000 == 43200 then "Month" else " ", if (Agg2per == 1 and method == method."HHLLS") or (Agg2per == 1 and method == method."MACD" and Value2 > 0) or (Agg2per == 1 and method != method."MACD" and method != method."HHLLS") then Color.GREEN else if (Agg2per == 1 and method == method."MACD" and Value2 < 0) then Color.DARK_GREEN else if (Agg2per == 0 and method == method."MACD" and Value2 < 0) then Color.DARK_RED else Color.RED); AddLabel(showlabels, if agg3 / 60000 <= 240 then (agg3 / 60000 + " Min") else if agg3 / 60000 == 1440 then "Day" else if agg3 / 60000 == 10080 then "Week" else if agg3 / 60000 == 43200 then "Month" else " ", if (Agg3per == 1 and method == method."HHLLS") or (Agg3per == 1 and method == method."MACD" and Value3 > 0) or (Agg3per == 1 and method != method."MACD" and method != method."HHLLS") then Color.GREEN else if (Agg3per == 1 and method == method."MACD" and Value3 < 0) then Color.DARK_GREEN else if (Agg3per == 0 and method == method."MACD" and Value3 < 0) then Color.DARK_RED else Color.RED); # Label identifying method and color green/red if all green/red otherwise white def aggsum = Agg1per + Agg2per + Agg3per; AddLabel(showlabels, if method == method."Close_Close[1]" then "C_C[1]" else if method == method."HAOpen_HAClose" then "HAC_HAO" else if method == method."Trend" then "Trend" else if method == method."HHLLS" then "HHLLS" else "MACD" , if aggsum == 3 then Color.GREEN else if aggsum == 0 then Color.RED else Color.WHITE); plot lineh = if IsNaN(close) or showdotplot == no then Double.NaN else if useupper_lower == useupper_lower.upper then 7 else Double.NaN; plot linel = if IsNaN(close) or showdotplot == no then Double.NaN else if useupper_lower == useupper_lower.upper then -7 else Double.NaN; lineh.SetDefaultColor(Color.DARK_GRAY); linel.SetDefaultColor(Color.DARK_GRAY); if IsNaN(close) or showdotplot == no { Agg1lower = Double.NaN; Agg2lower = Double.NaN; Agg3lower = Double.NaN; } else { Agg1lower = if !IsNaN(Agg1per) then if useupper_lower == useupper_lower.upper then -8.75 else 6 else Double.NaN; Agg2lower = if !IsNaN(Agg2per) then if useupper_lower == useupper_lower.upper then -9.00 else 5 else Double.NaN; Agg3lower = if !IsNaN(Agg3per) then if useupper_lower == useupper_lower.upper then -9.25 else 4 else Double.NaN; } Agg1lower.SetPaintingStrategy(PaintingStrategy.POINTS); Agg1lower.AssignValueColor(if (Agg1per == 1 and method != method."MACD") or (Agg1per == 1 and method == method."MACD" and Value1 > 0) then Color.GREEN else if (Agg1per == 1 and method == method."MACD" and Value1 < 0) then Color.DARK_GREEN else if (Agg1per == 0 and method == method."MACD" and Value1 < 0) then Color.DARK_RED else Color.RED); Agg2lower.SetPaintingStrategy(PaintingStrategy.POINTS); Agg2lower.AssignValueColor(if (Agg2per == 1 and method != method."MACD") or (Agg2per == 1 and method == method."MACD" and Value2 > 0) then Color.GREEN else if (Agg2per == 1 and method == method."MACD" and Value2 < 0) then Color.DARK_GREEN else if (Agg2per == 0 and method == method."MACD" and Value2 < 0) then Color.DARK_RED else Color.RED); Agg3lower.SetPaintingStrategy(PaintingStrategy.POINTS); Agg3lower.AssignValueColor(if (Agg3per == 1 and method != method."MACD") or (Agg3per == 1 and method == method."MACD" and Value3 > 0) then Color.GREEN else if (Agg3per == 1 and method == method."MACD" and Value3 < 0) then Color.DARK_GREEN else if (Agg3per == 0 and method == method."MACD" and Value3 < 0) then Color.DARK_RED else Color.RED); plot linediv = if IsNaN(close) or showdotplot == no then Double.NaN else if useupper_lower == useupper_lower.upper then -8.5 else 6.25; plot sumagg = if IsNaN(close) or showdotplot == no then Double.NaN else if aggsum == 3 or aggsum == 0 then if useupper_lower == useupper_lower.upper then -8.25 else 6.5 else Double.NaN; sumagg.SetPaintingStrategy(PaintingStrategy.POINTS); sumagg.AssignValueColor(if aggsum == 3 then Color.GREEN else if aggsum == 0 then Color.RED else Color.WHITE); #Squeeze Added input showsqueeze = yes; def bbupper = reference BollingerBands().UpperBand; def kcupper = KeltnerChannels().Upper_Band; def Squeeze = bbupper - kcupper < 0; plot Squeezeplot = if showsqueeze and Squeeze then linediv else Double.NaN; Squeezeplot.SetDefaultColor(Color.BLACK); Squeezeplot.SetPaintingStrategy(PaintingStrategy.POINTS); Squeezeplot.SetLineWeight(1); Squeezeplot.HideBubble(); #Count of Periods in consecutive squeeze rec countsq = if Squeeze then countsq[1] + 1 else 0; rec count1sq = if !Squeeze then count1sq[1] + 1 else 0; #Expansion Bubbles input n = 5; def n1 = n + 1; def c = close; input showsqueezebubble = yes; AddChartBubble(showsqueezebubble and !IsNaN(c[n1]) and IsNaN(c[n]), linediv[n1] , ( if Squeeze[n1] then "S \n" + Round(countsq[n1], 2) else "NS \n" + count1sq[n1]) , if aggsum[n1] == 3 then Color.GREEN else if aggsum[n1] == 0 then Color.RED else Color.WHITE, up = No); Alert(Between(aggsum[1], 0, 2) and aggsum == 3 and !Squeeze, "Candles - All Green", Alert.BAR, Sound.Ding); Alert(Between(aggsum[1], 1, 3) and aggsum == 0 and !Squeeze, "Candles - All Red ", Alert.BAR, Sound.Ding);
Hi Need your help with same indicator. I have tried to add more timeframe but I am not a coding guy so I am missing logic here can you help? I am only seeing Green and red color I am not getting dark green and dark red results with more time framesYes, thank you! I made the correction in the above post. to Agg2per and Agg3per value1 > 0 to value2 > 0 and value3 > 0, respectively
# Labels show current color status
# Choose how the candles are being colored (green/red) in Multiple user defined TimeFrames by one of 4 methods.
# Trend method is similar but not exactly like TTM_Trend
# Move study from lower to upper and select "upper" at the input useupperlower to display dots on upper price panel. Uncheck at input screen "use left axis"
# Using the study on the lower panel, select "lower" at the input useupperlower to lower to display dots on lower panel
# Dots can be turned off/on at the input screen
# Summary line shows only if all colors are the same, otherwise blank.
declare lower;
input method = {default "MACD", "Close_Close[1]", "HAOpen_HAClose", "Trend", "HHLLS"};
input useupper_lower = {default lower, upper};
input showdotplot = yes;
input agg1 = AggregationPeriod.MIN;
input agg2 = AggregationPeriod.TWO_MIN;
input agg3 = AggregationPeriod.THREE_MIN;
input agg4 = AggregationPeriod.FIVE;
input agg5 = AggregationPeriod.TEN_MIN;
input agg6 = AggregationPeriod.FIFTEEN_MIN;
#Heiken Ashi defined
def HAclose1 = ohlc4(period = agg1);
def HAopen1 = CompoundValue( 1, ( HAopen1[1] + HAclose1[1] ) / 2, HAclose1 );
def HAclose2 = ohlc4(period = agg2);
def HAopen2 = CompoundValue( 1, ( HAopen2[1] + HAclose2[1] ) / 2, HAclose2 );
def HAclose3 = ohlc4(period = agg3);
def HAopen3 = CompoundValue( 1, ( HAopen3[1] + HAclose3[1] ) / 2, HAclose3 );
def HAclose4 = ohlc4(period = agg4);
def HAopen4 = CompoundValue( 1, ( HAopen4[1] + HAclose4[1] ) / 2, HAclose4 );
def HAclose5 = ohlc4(period = agg5);
def HAopen5 = CompoundValue( 1, ( HAopen5[1] + HAclose5[1] ) / 2, HAclose5 );
def HAclose6 = ohlc4(period = agg6);
def HAopen6 = CompoundValue( 1, ( HAopen3[1] + HAclose6[1] ) / 2, HAclose6 );
#Trend defined
input trend_lookback = 12;
def HH1 = (Highest(high(period = agg1) , trend_lookback) + Lowest(low(period = agg1), trend_lookback)) / 2;
def Trend1 = close(period = agg1) > HH1;
def HH2 = (Highest(high(period = agg2) , trend_lookback) + Lowest(low(period = agg2), trend_lookback)) / 2;
def Trend2 = close(period = agg2) > HH2;
def HH3 = (Highest(high(period = agg3) , trend_lookback) + Lowest(low(period = agg3), trend_lookback)) / 2;
def Trend3 = close(period = agg3) > HH3;
def HH4 = (Highest(high(period = agg4) , trend_lookback) + Lowest(low(period = agg4), trend_lookback)) / 2;
def Trend4 = close(period = agg4) > HH4;
def HH5 = (Highest(high(period = agg5) , trend_lookback) + Lowest(low(period = agg5), trend_lookback)) / 2;
def Trend5 = close(period = agg5) > HH5;
def HH6 = (Highest(high(period = agg6) , trend_lookback) + Lowest(low(period = agg6), trend_lookback)) / 2;
def Trend6 = close(period = agg6) > HH6;
#MACD
input fastlength = 12;
input slowlength = 26;
input macdlength = 9;
input averagetype = AverageType.EXPONENTIAL;
def Value1 = MovingAverage(averagetype, close(period = agg1), fastlength) - MovingAverage(averagetype, close(period = agg1), slowlength);
def Avg1 = MovingAverage(averagetype, Value1, macdlength);
def MACD1 = Value1 - Avg1;
def Value2 = MovingAverage(averagetype, close(period = agg2), fastlength) - MovingAverage(averagetype, close(period = agg2), slowlength);
def Avg2 = MovingAverage(averagetype, Value2, macdlength);
def MACD2 = Value2 - Avg2;
def Value3 = MovingAverage(averagetype, close(period = agg3), fastlength) - MovingAverage(averagetype, close(period = agg3), slowlength);
def Avg3 = MovingAverage(averagetype, Value3, macdlength);
def MACD3 = Value3 - Avg3;
def Value4 = MovingAverage(averagetype, close(period = agg4), fastlength) - MovingAverage(averagetype, close(period = agg4), slowlength);
def Avg4 = MovingAverage(averagetype, Value4, macdlength);
def MACD4 = Value4 - Avg4;
def Value5 = MovingAverage(averagetype, close(period = agg5), fastlength) - MovingAverage(averagetype, close(period = agg5), slowlength);
def Avg5 = MovingAverage(averagetype, Value5, macdlength);
def MACD5 = Value5 - Avg5;
def Value6 = MovingAverage(averagetype, close(period = agg6), fastlength) - MovingAverage(averagetype, close(period = agg6), slowlength);
def Avg6 = MovingAverage(averagetype, Value6, macdlength);
def MACD6 = Value6 - Avg6;
#HHKKS
input length = 20;
input over_bought = 60;
input signal_line = 50;
input over_sold = 10;
input averageTypehhlls = AverageType.EXPONENTIAL;
Assert(length > 1, "'length' must be greater than one: " + length);
def HS1 = if high (period = agg1) > high(period= agg1)[1] then (high (period= agg1) - Lowest(high (period= agg1), length)) / (Highest(high (period= agg1), length) - Lowest(high (period= agg1), length)) else 0;
def LS1 = if low (period= agg1)< low(period= agg1)[1] then (Highest(low(period= agg1), length) - low(period= agg1)) / (Highest(low(period= agg1), length) - Lowest(low(period= agg1), length)) else 0;
def HHS1 = 100 * MovingAverage(averageTypehhlls, HS1, length);
def LLS1 = 100 * MovingAverage(averageTypehhlls, LS1, length);
def HS2 = if high (period = agg2) > high(period= agg2)[1] then (high (period= agg2) - Lowest(high (period= agg2), length)) / (Highest(high (period= agg2), length) - Lowest(high (period= agg2), length)) else 0;
def LS2 = if low (period= agg2)< low(period= agg2)[1] then (Highest(low(period= agg2), length) - low(period= agg2)) / (Highest(low(period= agg2), length) - Lowest(low(period= agg2), length)) else 0;
def HHS2 = 100 * MovingAverage(averageTypehhlls, HS2, length);
def LLS2 = 100 * MovingAverage(averageTypehhlls, LS2, length);
def HS3 = if high (period = agg3) > high(period= agg3)[1] then (high (period= agg3) - Lowest(high (period= agg3), length)) / (Highest(high (period= agg3), length) - Lowest(high (period= agg3), length)) else 0;
def LS3 = if low (period= agg3)< low(period= agg3)[1] then (Highest(low(period= agg3), length) - low(period= agg3)) / (Highest(low(period= agg3), length) - Lowest(low(period= agg3), length)) else 0;
def HHS3 = 100 * MovingAverage(averageTypehhlls, HS3, length);
def LLS3 = 100 * MovingAverage(averageTypehhlls, LS3, length);
def HS4 = if high (period = agg4) > high(period= agg4)[1] then (high (period= agg4) - Lowest(high (period= agg4), length)) / (Highest(high (period= agg4), length) - Lowest(high (period= agg4), length)) else 0;
def LS4 = if low (period= agg4)< low(period= agg4)[1] then (Highest(low(period= agg4), length) - low(period= agg4)) / (Highest(low(period= agg4), length) - Lowest(low(period= agg4), length)) else 0;
def HHS4 = 100 * MovingAverage(averageTypehhlls, HS4, length);
def LLS4 = 100 * MovingAverage(averageTypehhlls, LS4, length);
def HS5 = if high (period = agg5) > high(period= agg5)[1] then (high (period= agg5) - Lowest(high (period= agg5), length)) / (Highest(high (period= agg5), length) - Lowest(high (period= agg5), length)) else 0;
def LS5 = if low (period= agg5)< low(period= agg5)[1] then (Highest(low(period= agg5), length) - low(period= agg5)) / (Highest(low(period= agg5), length) - Lowest(low(period= agg5), length)) else 0;
def HHS5 = 100 * MovingAverage(averageTypehhlls, HS5, length);
def LLS5 = 100 * MovingAverage(averageTypehhlls, LS5, length);
def HS6 = if high (period = agg6) > high(period= agg6)[1] then (high (period= agg6) - Lowest(high (period= agg6), length)) / (Highest(high (period= agg6), length) - Lowest(high (period= agg6), length)) else 0;
def LS6 = if low (period= agg6)< low(period= agg6)[1] then (Highest(low(period= agg6), length) - low(period= agg6)) / (Highest(low(period= agg6), length) - Lowest(low(period= agg6), length)) else 0;
def HHS6 = 100 * MovingAverage(averageTypehhlls, HS6, length);
def LLS6 = 100 * MovingAverage(averageTypehhlls, LS6, length);
#Method applied to each aggregation
def Agg1per;
def Agg2per;
def Agg3per;
def agg4per;
def agg5per;
def agg6per;
plot Agg1lower;
plot Agg2lower;
plot Agg3lower;
plot agg4lower;
plot agg5lower;
plot agg6lower;
if method == method."Close_Close[1]" {
Agg1per = close(period = agg1) > close(period = agg1)[1];
Agg2per = close(period = agg2) > close(period = agg2)[1];
Agg3per = close(period = agg3) > close(period = agg3)[1];
agg4per = close(period = agg4) > close(period = agg4)[1];
agg5per = close(period = agg5) > close(period = agg5)[1];
agg6per = close(period = agg6) > close(period = agg6)[1];
} else if method == method."HAOpen_HAClose" {
Agg1per = HAclose1 > HAopen1;
Agg2per = HAclose2 > HAopen2;
Agg3per = HAclose3 > HAopen3;
agg4per = HAclose4 > HAopen4;
agg5per = HAclose5 > HAopen5;
agg6per = HAclose6 > HAopen3;
} else if method == method."Trend" {
Agg1per = Trend1;
Agg2per = Trend2;
Agg3per = Trend3;
agg4per = Trend4;
agg5per = Trend5;
agg6per = Trend6;
} else if method == method."HHLLS" {
Agg1per = HHS1 > LLS1;
Agg2per = HHS2 > LLS2;
Agg3per = HHS3 > LLS3;
agg4per = HHS4 > LLS4;
agg5per = HHS5 > LLS5;
agg6per = HHS6 > LLS6;
} else {
Agg1per = Value1 > Avg1;
Agg2per = Value2 > Avg2;
Agg3per = Value3 > Avg3;
agg4per = Value4 > Avg4;
agg5per = Value5 > Avg5;
agg6per = Value6 > Avg6;
}
#Labels with selection to turn them on/off
input showlabels = yes;
AddLabel(showlabels,
if agg1 / 60000 <= 240
then (agg1 / 60000 + " Min")
else if agg1 / 60000 == 1440
then "Day"
else if agg1 / 60000 == 10080
then "Week"
else if agg1 / 60000 == 43200
then "Month"
else " ",
if (Agg1per == 1 and method == method."HHLLS") or (Agg1per == 1 and method == method."MACD" and Value1 > 0) or (Agg1per == 1 and method != method."MACD" and method != method."HHLLS")
then Color.GREEN
else if (Agg1per == 1 and method == method."MACD" and Value1 < 0)
then Color.DARK_GREEN
else if (Agg1per == 0 and method == method."MACD" and Value1 < 0)
then Color.DARK_RED
else Color.RED);
AddLabel(showlabels,
if agg2 / 60000 <= 240
then (agg2 / 60000 + " Min")
else if agg2 / 60000 == 1440
then "Day"
else if agg2 / 60000 == 10080
then "Week"
else if agg2 / 60000 == 43200
then "Month"
else " ",
if (Agg2per == 1 and method == method."HHLLS") or (Agg2per == 1 and method == method."MACD" and Value1 > 0) or (Agg2per == 1 and method != method."MACD" and method != method."HHLLS")
then Color.GREEN
else if (Agg2per == 1 and method == method."MACD" and Value2 < 0)
then Color.DARK_GREEN
else if (Agg2per == 0 and method == method."MACD" and Value2 < 0)
then Color.DARK_RED
else Color.RED);
AddLabel(showlabels,
if agg3 / 60000 <= 240
then (agg3 / 60000 + " Min")
else if agg3 / 60000 == 1440
then "Day"
else if agg3 / 60000 == 10080
then "Week"
else if agg3 / 60000 == 43200
then "Month"
else " ",
if (Agg3per == 1 and method == method."HHLLS") or (Agg3per == 1 and method == method."MACD" and Value1 > 0) or (Agg3per == 1 and method != method."MACD" and method != method."HHLLS")
then Color.GREEN
else if (Agg3per == 1 and method == method."MACD" and Value3 < 0)
then Color.DARK_GREEN
else if (Agg3per == 0 and method == method."MACD" and Value3 < 0)
then Color.DARK_RED
else Color.RED);
AddLabel(showlabels,
if agg4 / 60000 <= 240
then (agg4 / 60000 + " Min")
else if agg4 / 60000 == 1440
then "Day"
else if agg4 / 60000 == 10080
then "Week"
else if agg4 / 60000 == 43200
then "Month"
else " ",
if (agg4per == 1 and method == method."HHLLS") or (agg4per == 1 and method == method."MACD" and Value4 > 0) or (agg4per == 1 and method != method."MACD" and method != method."HHLLS")
then Color.GREEN
else if (agg4per == 1 and method == method."MACD" and Value4 < 0)
then Color.DARK_GREEN
else if (agg4per == 0 and method == method."MACD" and Value4 < 0)
then Color.DARK_RED
else Color.RED);
AddLabel(showlabels,
if agg5 / 60000 <= 240
then (agg5 / 60000 + " Min")
else if agg5 / 60000 == 1440
then "Day"
else if agg5 / 60000 == 10080
then "Week"
else if agg5 / 60000 == 43200
then "Month"
else " ",
if (agg5per == 1 and method == method."HHLLS") or (agg5per == 1 and method == method."MACD" and Value4 > 0) or (agg5per == 1 and method != method."MACD" and method != method."HHLLS")
then Color.GREEN
else if (agg5per == 1 and method == method."MACD" and Value5 < 0)
then Color.DARK_GREEN
else if (agg5per == 0 and method == method."MACD" and Value5 < 0)
then Color.DARK_RED
else Color.RED);
AddLabel(showlabels,
if agg6 / 60000 <= 240
then (agg6 / 60000 + " Min")
else if agg6 / 60000 == 1440
then "Day"
else if agg6 / 60000 == 10080
then "Week"
else if agg6 / 60000 == 43200
then "Month"
else " ",
if (agg6per == 1 and method == method."HHLLS") or (agg6per == 1 and method == method."MACD" and Value4 > 0) or (agg6per == 1 and method != method."MACD" and method != method."HHLLS")
then Color.GREEN
else if (agg6per == 1 and method == method."MACD" and Value6 < 0)
then Color.DARK_GREEN
else if (agg6per == 0 and method == method."MACD" and Value6 < 0)
then Color.DARK_RED
else Color.RED);
# Label identifying method and color green/red if all green/red otherwise white
def aggsum = Agg1per + Agg2per + Agg3per + agg4per + agg5per + agg6per;
AddLabel(showlabels,
if method == method."Close_Close[1]"
then "C_C[1]"
else if method == method."HAOpen_HAClose"
then "HAC_HAO"
else if method == method."Trend"
then "Trend"
else if method == method."HHLLS"
then "HHLLS"
else "MACD" ,
if aggsum == 6
then Color.GREEN
else if aggsum == 0
then Color.RED
else Color.WHITE);
plot lineh = if IsNaN(close) or showdotplot == no
then Double.NaN
else if useupper_lower == useupper_lower.upper then 7 else Double.NaN;
plot linel = if IsNaN(close) or showdotplot == no
then Double.NaN
else if useupper_lower == useupper_lower.upper then -7 else Double.NaN;
lineh.SetDefaultColor(Color.DARK_GRAY);
linel.SetDefaultColor(Color.DARK_GRAY);
if IsNaN(close) or showdotplot == no {
Agg1lower = Double.NaN;
Agg2lower = Double.NaN;
Agg3lower = Double.NaN;
agg4lower = Double.NaN;
agg5lower = Double.NaN;
agg6lower = Double.NaN;
} else {
Agg1lower = if !IsNaN(Agg1per) then if useupper_lower == useupper_lower.upper then -8.75 else 6 else Double.NaN;
Agg2lower = if !IsNaN(Agg2per) then if useupper_lower == useupper_lower.upper then -9.00 else 5 else Double.NaN;
Agg3lower = if !IsNaN(Agg3per) then if useupper_lower == useupper_lower.upper then -9.25 else 4 else Double.NaN;
agg4lower = if !IsNaN(agg4per) then if useupper_lower == useupper_lower.upper then -9.50 else 3 else Double.NaN;
agg5lower = if !IsNaN(agg5per) then if useupper_lower == useupper_lower.upper then -9.75 else 2 else Double.NaN;
agg6lower = if !IsNaN(agg6per) then if useupper_lower == useupper_lower.upper then -10.00 else 1 else Double.NaN;
}
Agg1lower.SetPaintingStrategy(PaintingStrategy.POINTS);
Agg1lower.AssignValueColor(if (Agg1per == 1 and method != method."MACD") or (Agg1per == 1 and method == method."MACD" and Value1 > 0)
then Color.GREEN
else if (Agg1per == 1 and method == method."MACD" and Value1 < 0)
then Color.DARK_GREEN
else if (Agg1per == 0 and method == method."MACD" and Value1 < 0)
then Color.DARK_RED
else Color.RED);
Agg2lower.SetPaintingStrategy(PaintingStrategy.POINTS);
Agg2lower.AssignValueColor(if (Agg2per == 1 and method != method."MACD") or (Agg2per == 1 and method == method."MACD" and Value2 > 0)
then Color.GREEN
else if (Agg2per == 1 and method == method."MACD" and Value2 < 0)
then Color.DARK_GREEN
else if (Agg2per == 0 and method == method."MACD" and Value2 < 0)
then Color.DARK_RED
else Color.RED);
Agg3lower.SetPaintingStrategy(PaintingStrategy.POINTS);
Agg3lower.AssignValueColor(if (Agg3per == 1 and method != method."MACD") or (Agg3per == 1 and method == method."MACD" and Value3 > 0)
then Color.GREEN
else if (Agg3per == 1 and method == method."MACD" and Value3 < 0)
then Color.DARK_GREEN
else if (Agg3per == 0 and method == method."MACD" and Value3 < 0)
then Color.DARK_RED
else Color.RED);
agg4lower.SetPaintingStrategy(PaintingStrategy.POINTS);
agg4lower.AssignValueColor(if (agg4per == 1 and method != method."MACD") or (agg4per == 1 and method == method."MACD" and Value4 > 0)
then Color.GREEN
else if (agg4per == 1 and method == method."MACD" and Value4 < 0)
then Color.DARK_GREEN
else if (agg4per == 0 and method == method."MACD" and Value4 < 0)
then Color.DARK_RED
else Color.RED);
agg5lower.SetPaintingStrategy(PaintingStrategy.POINTS);
agg5lower.AssignValueColor(if (agg5per == 1 and method != method."MACD") or (agg5per == 1 and method == method."MACD" and Value5 > 0)
then Color.GREEN
else if (agg5per == 1 and method == method."MACD" and Value5 < 0)
then Color.DARK_GREEN
else if (agg5per == 0 and method == method."MACD" and Value5 < 0)
then Color.DARK_RED
else Color.RED);
agg6lower.SetPaintingStrategy(PaintingStrategy.POINTS);
agg6lower.AssignValueColor(if (agg6per == 1 and method != method."MACD") or (agg6per == 1 and method == method."MACD" and Value6 > 0)
then Color.GREEN
else if (agg6per == 1 and method == method."MACD" and Value6 < 0)
then Color.DARK_GREEN
else if (agg6per == 0 and method == method."MACD" and Value6 < 0)
then Color.DARK_RED
else Color.RED);
plot linediv = if IsNaN(close) or showdotplot == no
then Double.NaN
else if useupper_lower == useupper_lower.upper then -8.5 else 6.25;
plot sumagg = if IsNaN(close) or showdotplot == no
then Double.NaN
else if aggsum == 6 or aggsum == 0 then if useupper_lower == useupper_lower.upper then -8.25 else 6.5 else Double.NaN;
sumagg.SetPaintingStrategy(PaintingStrategy.POINTS);
sumagg.AssignValueColor(if aggsum == 6
then Color.GREEN
else if aggsum == 0
then Color.RED
else Color.WHITE);
#Squeeze Added
input showsqueeze = yes;
def bbupper = reference BollingerBands().UpperBand;
def kcupper = KeltnerChannels().Upper_Band;
def Squeeze = bbupper - kcupper < 0;
plot Squeezeplot = if showsqueeze and Squeeze then linediv else Double.NaN;
Squeezeplot.SetDefaultColor(Color.BLACK);
Squeezeplot.SetPaintingStrategy(PaintingStrategy.POINTS);
Squeezeplot.SetLineWeight(1);
Squeezeplot.HideBubble();
#Count of Periods in consecutive squeeze
rec countsq = if Squeeze then countsq[1] + 1 else 0;
rec count1sq = if !Squeeze then count1sq[1] + 1 else 0;
#Expansion Bubbles
input n = 5;
def n1 = n + 1;
def c = close;
input showsqueezebubble = yes;
AddChartBubble(showsqueezebubble and !IsNaN(c[n1]) and IsNaN(c[n]),
linediv[n1] ,
( if Squeeze[n1] then "S \n" + Round(countsq[n1], 2) else "NS \n" + count1sq[n1]) ,
if aggsum[n1] == 6
then Color.GREEN
else if aggsum[n1] == 0
then Color.RED
else Color.WHITE, up = No);
Alert(Between(aggsum[1], 0, 2) and aggsum == 6 and !Squeeze, "Candles - All Green", Alert.BAR, Sound.Ding);
Alert(Between(aggsum[1], 1, 3) and aggsum == 0 and !Squeeze, "Candles - All Red ", Alert.BAR, Sound.Ding);
@ap09 Hi Need your help with same indicator. I have tried to add more timeframe but I am not a coding guy so I am missing logic here can you help? I am only seeing Green and red color I am not getting dark green and dark red results with more time frames
Ruby:# Labels show current color status # Choose how the candles are being colored (green/red) in Multiple user defined TimeFrames by one of 4 methods. # Trend method is similar but not exactly like TTM_Trend # Move study from lower to upper and select "upper" at the input useupperlower to display dots on upper price panel. Uncheck at input screen "use left axis" # Using the study on the lower panel, select "lower" at the input useupperlower to lower to display dots on lower panel # Dots can be turned off/on at the input screen # Summary line shows only if all colors are the same, otherwise blank. declare lower; input method = {default "MACD", "Close_Close[1]", "HAOpen_HAClose", "Trend", "HHLLS"}; input useupper_lower = {default lower, upper}; input showdotplot = yes; input agg1 = AggregationPeriod.MIN; input agg2 = AggregationPeriod.TWO_MIN; input agg3 = AggregationPeriod.THREE_MIN; input agg4 = AggregationPeriod.FIVE_min; input agg5 = AggregationPeriod.TEN_MIN; input agg6 = AggregationPeriod.FIFTEEN_MIN; #Heiken Ashi defined def HAclose1 = ohlc4(period = agg1); def HAopen1 = CompoundValue( 1, ( HAopen1[1] + HAclose1[1] ) / 2, HAclose1 ); def HAclose2 = ohlc4(period = agg2); def HAopen2 = CompoundValue( 1, ( HAopen2[1] + HAclose2[1] ) / 2, HAclose2 ); def HAclose3 = ohlc4(period = agg3); def HAopen3 = CompoundValue( 1, ( HAopen3[1] + HAclose3[1] ) / 2, HAclose3 ); def HAclose4 = ohlc4(period = agg4); def HAopen4 = CompoundValue( 1, ( HAopen4[1] + HAclose4[1] ) / 2, HAclose4 ); def HAclose5 = ohlc4(period = agg5); def HAopen5 = CompoundValue( 1, ( HAopen5[1] + HAclose5[1] ) / 2, HAclose5 ); def HAclose6 = ohlc4(period = agg6); def HAopen6 = CompoundValue( 1, ( HAopen3[1] + HAclose6[1] ) / 2, HAclose6 ); #Trend defined input trend_lookback = 12; def HH1 = (Highest(high(period = agg1) , trend_lookback) + Lowest(low(period = agg1), trend_lookback)) / 2; def Trend1 = close(period = agg1) > HH1; def HH2 = (Highest(high(period = agg2) , trend_lookback) + Lowest(low(period = agg2), trend_lookback)) / 2; def Trend2 = close(period = agg2) > HH2; def HH3 = (Highest(high(period = agg3) , trend_lookback) + Lowest(low(period = agg3), trend_lookback)) / 2; def Trend3 = close(period = agg3) > HH3; def HH4 = (Highest(high(period = agg4) , trend_lookback) + Lowest(low(period = agg4), trend_lookback)) / 2; def Trend4 = close(period = agg4) > HH4; def HH5 = (Highest(high(period = agg5) , trend_lookback) + Lowest(low(period = agg5), trend_lookback)) / 2; def Trend5 = close(period = agg5) > HH5; def HH6 = (Highest(high(period = agg6) , trend_lookback) + Lowest(low(period = agg6), trend_lookback)) / 2; def Trend6 = close(period = agg6) > HH6; #MACD input fastlength = 12; input slowlength = 26; input macdlength = 9; input averagetype = AverageType.EXPONENTIAL; def Value1 = MovingAverage(averagetype, close(period = agg1), fastlength) - MovingAverage(averagetype, close(period = agg1), slowlength); def Avg1 = MovingAverage(averagetype, Value1, macdlength); def MACD1 = Value1 - Avg1; def Value2 = MovingAverage(averagetype, close(period = agg2), fastlength) - MovingAverage(averagetype, close(period = agg2), slowlength); def Avg2 = MovingAverage(averagetype, Value2, macdlength); def MACD2 = Value2 - Avg2; def Value3 = MovingAverage(averagetype, close(period = agg3), fastlength) - MovingAverage(averagetype, close(period = agg3), slowlength); def Avg3 = MovingAverage(averagetype, Value3, macdlength); def MACD3 = Value3 - Avg3; def Value4 = MovingAverage(averagetype, close(period = agg4), fastlength) - MovingAverage(averagetype, close(period = agg4), slowlength); def Avg4 = MovingAverage(averagetype, Value4, macdlength); def MACD4 = Value4 - Avg4; def Value5 = MovingAverage(averagetype, close(period = agg5), fastlength) - MovingAverage(averagetype, close(period = agg5), slowlength); def Avg5 = MovingAverage(averagetype, Value5, macdlength); def MACD5 = Value5 - Avg5; def Value6 = MovingAverage(averagetype, close(period = agg6), fastlength) - MovingAverage(averagetype, close(period = agg6), slowlength); def Avg6 = MovingAverage(averagetype, Value6, macdlength); def MACD6 = Value6 - Avg6; #HHKKS input length = 20; input over_bought = 60; input signal_line = 50; input over_sold = 10; input averageTypehhlls = AverageType.EXPONENTIAL; Assert(length > 1, "'length' must be greater than one: " + length); def HS1 = if high (period = agg1) > high(period= agg1)[1] then (high (period= agg1) - Lowest(high (period= agg1), length)) / (Highest(high (period= agg1), length) - Lowest(high (period= agg1), length)) else 0; def LS1 = if low (period= agg1)< low(period= agg1)[1] then (Highest(low(period= agg1), length) - low(period= agg1)) / (Highest(low(period= agg1), length) - Lowest(low(period= agg1), length)) else 0; def HHS1 = 100 * MovingAverage(averageTypehhlls, HS1, length); def LLS1 = 100 * MovingAverage(averageTypehhlls, LS1, length); def HS2 = if high (period = agg2) > high(period= agg2)[1] then (high (period= agg2) - Lowest(high (period= agg2), length)) / (Highest(high (period= agg2), length) - Lowest(high (period= agg2), length)) else 0; def LS2 = if low (period= agg2)< low(period= agg2)[1] then (Highest(low(period= agg2), length) - low(period= agg2)) / (Highest(low(period= agg2), length) - Lowest(low(period= agg2), length)) else 0; def HHS2 = 100 * MovingAverage(averageTypehhlls, HS2, length); def LLS2 = 100 * MovingAverage(averageTypehhlls, LS2, length); def HS3 = if high (period = agg3) > high(period= agg3)[1] then (high (period= agg3) - Lowest(high (period= agg3), length)) / (Highest(high (period= agg3), length) - Lowest(high (period= agg3), length)) else 0; def LS3 = if low (period= agg3)< low(period= agg3)[1] then (Highest(low(period= agg3), length) - low(period= agg3)) / (Highest(low(period= agg3), length) - Lowest(low(period= agg3), length)) else 0; def HHS3 = 100 * MovingAverage(averageTypehhlls, HS3, length); def LLS3 = 100 * MovingAverage(averageTypehhlls, LS3, length); def HS4 = if high (period = agg4) > high(period= agg4)[1] then (high (period= agg4) - Lowest(high (period= agg4), length)) / (Highest(high (period= agg4), length) - Lowest(high (period= agg4), length)) else 0; def LS4 = if low (period= agg4)< low(period= agg4)[1] then (Highest(low(period= agg4), length) - low(period= agg4)) / (Highest(low(period= agg4), length) - Lowest(low(period= agg4), length)) else 0; def HHS4 = 100 * MovingAverage(averageTypehhlls, HS4, length); def LLS4 = 100 * MovingAverage(averageTypehhlls, LS4, length); def HS5 = if high (period = agg5) > high(period= agg5)[1] then (high (period= agg5) - Lowest(high (period= agg5), length)) / (Highest(high (period= agg5), length) - Lowest(high (period= agg5), length)) else 0; def LS5 = if low (period= agg5)< low(period= agg5)[1] then (Highest(low(period= agg5), length) - low(period= agg5)) / (Highest(low(period= agg5), length) - Lowest(low(period= agg5), length)) else 0; def HHS5 = 100 * MovingAverage(averageTypehhlls, HS5, length); def LLS5 = 100 * MovingAverage(averageTypehhlls, LS5, length); def HS6 = if high (period = agg6) > high(period= agg6)[1] then (high (period= agg6) - Lowest(high (period= agg6), length)) / (Highest(high (period= agg6), length) - Lowest(high (period= agg6), length)) else 0; def LS6 = if low (period= agg6)< low(period= agg6)[1] then (Highest(low(period= agg6), length) - low(period= agg6)) / (Highest(low(period= agg6), length) - Lowest(low(period= agg6), length)) else 0; def HHS6 = 100 * MovingAverage(averageTypehhlls, HS6, length); def LLS6 = 100 * MovingAverage(averageTypehhlls, LS6, length); #Method applied to each aggregation def Agg1per; def Agg2per; def Agg3per; def agg4per; def agg5per; def agg6per; plot Agg1lower; plot Agg2lower; plot Agg3lower; plot agg4lower; plot agg5lower; plot agg6lower; if method == method."Close_Close[1]" { Agg1per = close(period = agg1) > close(period = agg1)[1]; Agg2per = close(period = agg2) > close(period = agg2)[1]; Agg3per = close(period = agg3) > close(period = agg3)[1]; agg4per = close(period = agg4) > close(period = agg4)[1]; agg5per = close(period = agg5) > close(period = agg5)[1]; agg6per = close(period = agg6) > close(period = agg6)[1]; } else if method == method."HAOpen_HAClose" { Agg1per = HAclose1 > HAopen1; Agg2per = HAclose2 > HAopen2; Agg3per = HAclose3 > HAopen3; agg4per = HAclose4 > HAopen4; agg5per = HAclose5 > HAopen5; agg6per = HAclose6 > HAopen3; } else if method == method."Trend" { Agg1per = Trend1; Agg2per = Trend2; Agg3per = Trend3; agg4per = Trend4; agg5per = Trend5; agg6per = Trend6; } else if method == method."HHLLS" { Agg1per = HHS1 > LLS1; Agg2per = HHS2 > LLS2; Agg3per = HHS3 > LLS3; agg4per = HHS4 > LLS4; agg5per = HHS5 > LLS5; agg6per = HHS6 > LLS6; } else { Agg1per = Value1 > Avg1; Agg2per = Value2 > Avg2; Agg3per = Value3 > Avg3; agg4per = Value4 > Avg4; agg5per = Value5 > Avg5; agg6per = Value6 > Avg6; } #Labels with selection to turn them on/off input showlabels = yes; AddLabel(showlabels, if agg1 / 60000 <= 240 then (agg1 / 60000 + " Min") else if agg1 / 60000 == 1440 then "Day" else if agg1 / 60000 == 10080 then "Week" else if agg1 / 60000 == 43200 then "Month" else " ", if (Agg1per == 1 and method == method."HHLLS") or (Agg1per == 1 and method == method."MACD" and Value1 > 0) or (Agg1per == 1 and method != method."MACD" and method != method."HHLLS") then Color.GREEN else if (Agg1per == 1 and method == method."MACD" and Value1 < 0) then Color.DARK_GREEN else if (Agg1per == 0 and method == method."MACD" and Value1 < 0) then Color.DARK_RED else Color.RED); AddLabel(showlabels, if agg2 / 60000 <= 240 then (agg2 / 60000 + " Min") else if agg2 / 60000 == 1440 then "Day" else if agg2 / 60000 == 10080 then "Week" else if agg2 / 60000 == 43200 then "Month" else " ", if (Agg2per == 1 and method == method."HHLLS") or (Agg2per == 1 and method == method."MACD" and Value2 > 0) or (Agg2per == 1 and method != method."MACD" and method != method."HHLLS") then Color.GREEN else if (Agg2per == 1 and method == method."MACD" and Value2 < 0) then Color.DARK_GREEN else if (Agg2per == 0 and method == method."MACD" and Value2 < 0) then Color.DARK_RED else Color.RED); AddLabel(showlabels, if agg3 / 60000 <= 240 then (agg3 / 60000 + " Min") else if agg3 / 60000 == 1440 then "Day" else if agg3 / 60000 == 10080 then "Week" else if agg3 / 60000 == 43200 then "Month" else " ", if (Agg3per == 1 and method == method."HHLLS") or (Agg3per == 1 and method == method."MACD" and Value3 > 0) or (Agg3per == 1 and method != method."MACD" and method != method."HHLLS") then Color.GREEN else if (Agg3per == 1 and method == method."MACD" and Value3 < 0) then Color.DARK_GREEN else if (Agg3per == 0 and method == method."MACD" and Value3 < 0) then Color.DARK_RED else Color.RED); AddLabel(showlabels, if agg4 / 60000 <= 240 then (agg4 / 60000 + " Min") else if agg4 / 60000 == 1440 then "Day" else if agg4 / 60000 == 10080 then "Week" else if agg4 / 60000 == 43200 then "Month" else " ", if (agg4per == 1 and method == method."HHLLS") or (agg4per == 1 and method == method."MACD" and Value4 > 0) or (agg4per == 1 and method != method."MACD" and method != method."HHLLS") then Color.GREEN else if (agg4per == 1 and method == method."MACD" and Value4 < 0) then Color.DARK_GREEN else if (agg4per == 0 and method == method."MACD" and Value4 < 0) then Color.DARK_RED else Color.RED); AddLabel(showlabels, if agg5 / 60000 <= 240 then (agg5 / 60000 + " Min") else if agg5 / 60000 == 1440 then "Day" else if agg5 / 60000 == 10080 then "Week" else if agg5 / 60000 == 43200 then "Month" else " ", if (agg5per == 1 and method == method."HHLLS") or (agg5per == 1 and method == method."MACD" and Value5 > 0) or (agg5per == 1 and method != method."MACD" and method != method."HHLLS") then Color.GREEN else if (agg5per == 1 and method == method."MACD" and Value5 < 0) then Color.DARK_GREEN else if (agg5per == 0 and method == method."MACD" and Value5 < 0) then Color.DARK_RED else Color.RED); AddLabel(showlabels, if agg6 / 60000 <= 240 then (agg6 / 60000 + " Min") else if agg6 / 60000 == 1440 then "Day" else if agg6 / 60000 == 10080 then "Week" else if agg6 / 60000 == 43200 then "Month" else " ", if (agg6per == 1 and method == method."HHLLS") or (agg6per == 1 and method == method."MACD" and Value6 > 0) or (agg6per == 1 and method != method."MACD" and method != method."HHLLS") then Color.GREEN else if (agg6per == 1 and method == method."MACD" and Value6 < 0) then Color.DARK_GREEN else if (agg6per == 0 and method == method."MACD" and Value6 < 0) then Color.DARK_RED else Color.RED); # Label identifying method and color green/red if all green/red otherwise white def aggsum = Agg1per + Agg2per + Agg3per + agg4per + agg5per + agg6per; AddLabel(showlabels, if method == method."Close_Close[1]" then "C_C[1]" else if method == method."HAOpen_HAClose" then "HAC_HAO" else if method == method."Trend" then "Trend" else if method == method."HHLLS" then "HHLLS" else "MACD" , if aggsum == 6 then Color.GREEN else if aggsum == 0 then Color.RED else Color.WHITE); plot lineh = if IsNaN(close) or showdotplot == no then Double.NaN else if useupper_lower == useupper_lower.upper then 7 else Double.NaN; plot linel = if IsNaN(close) or showdotplot == no then Double.NaN else if useupper_lower == useupper_lower.upper then -7 else Double.NaN; lineh.SetDefaultColor(Color.DARK_GRAY); linel.SetDefaultColor(Color.DARK_GRAY); if IsNaN(close) or showdotplot == no { Agg1lower = Double.NaN; Agg2lower = Double.NaN; Agg3lower = Double.NaN; agg4lower = Double.NaN; agg5lower = Double.NaN; agg6lower = Double.NaN; } else { Agg1lower = if !IsNaN(Agg1per) then if useupper_lower == useupper_lower.upper then -8.75 else 6 else Double.NaN; Agg2lower = if !IsNaN(Agg2per) then if useupper_lower == useupper_lower.upper then -9.00 else 5 else Double.NaN; Agg3lower = if !IsNaN(Agg3per) then if useupper_lower == useupper_lower.upper then -9.25 else 4 else Double.NaN; agg4lower = if !IsNaN(agg4per) then if useupper_lower == useupper_lower.upper then -9.50 else 3 else Double.NaN; agg5lower = if !IsNaN(agg5per) then if useupper_lower == useupper_lower.upper then -9.75 else 2 else Double.NaN; agg6lower = if !IsNaN(agg6per) then if useupper_lower == useupper_lower.upper then -10.00 else 1 else Double.NaN; } Agg1lower.SetPaintingStrategy(PaintingStrategy.POINTS); Agg1lower.AssignValueColor(if (Agg1per == 1 and method != method."MACD") or (Agg1per == 1 and method == method."MACD" and Value1 > 0) then Color.GREEN else if (Agg1per == 1 and method == method."MACD" and Value1 < 0) then Color.DARK_GREEN else if (Agg1per == 0 and method == method."MACD" and Value1 < 0) then Color.DARK_RED else Color.RED); Agg2lower.SetPaintingStrategy(PaintingStrategy.POINTS); Agg2lower.AssignValueColor(if (Agg2per == 1 and method != method."MACD") or (Agg2per == 1 and method == method."MACD" and Value2 > 0) then Color.GREEN else if (Agg2per == 1 and method == method."MACD" and Value2 < 0) then Color.DARK_GREEN else if (Agg2per == 0 and method == method."MACD" and Value2 < 0) then Color.DARK_RED else Color.RED); Agg3lower.SetPaintingStrategy(PaintingStrategy.POINTS); Agg3lower.AssignValueColor(if (Agg3per == 1 and method != method."MACD") or (Agg3per == 1 and method == method."MACD" and Value3 > 0) then Color.GREEN else if (Agg3per == 1 and method == method."MACD" and Value3 < 0) then Color.DARK_GREEN else if (Agg3per == 0 and method == method."MACD" and Value3 < 0) then Color.DARK_RED else Color.RED); agg4lower.SetPaintingStrategy(PaintingStrategy.POINTS); agg4lower.AssignValueColor(if (agg4per == 1 and method != method."MACD") or (agg4per == 1 and method == method."MACD" and Value4 > 0) then Color.GREEN else if (agg4per == 1 and method == method."MACD" and Value4 < 0) then Color.DARK_GREEN else if (agg4per == 0 and method == method."MACD" and Value4 < 0) then Color.DARK_RED else Color.RED); agg5lower.SetPaintingStrategy(PaintingStrategy.POINTS); agg5lower.AssignValueColor(if (agg5per == 1 and method != method."MACD") or (agg5per == 1 and method == method."MACD" and Value5 > 0) then Color.GREEN else if (agg5per == 1 and method == method."MACD" and Value5 < 0) then Color.DARK_GREEN else if (agg5per == 0 and method == method."MACD" and Value5 < 0) then Color.DARK_RED else Color.RED); agg6lower.SetPaintingStrategy(PaintingStrategy.POINTS); agg6lower.AssignValueColor(if (agg6per == 1 and method != method."MACD") or (agg6per == 1 and method == method."MACD" and Value6 > 0) then Color.GREEN else if (agg6per == 1 and method == method."MACD" and Value6 < 0) then Color.DARK_GREEN else if (agg6per == 0 and method == method."MACD" and Value6 < 0) then Color.DARK_RED else Color.RED); plot linediv = if IsNaN(close) or showdotplot == no then Double.NaN else if useupper_lower == useupper_lower.upper then -8.5 else 6.25; plot sumagg = if IsNaN(close) or showdotplot == no then Double.NaN else if aggsum == 6 or aggsum == 0 then if useupper_lower == useupper_lower.upper then -8.25 else 6.5 else Double.NaN; sumagg.SetPaintingStrategy(PaintingStrategy.POINTS); sumagg.AssignValueColor(if aggsum == 6 then Color.GREEN else if aggsum == 0 then Color.RED else Color.WHITE); #Squeeze Added input showsqueeze = yes; def bbupper = reference BollingerBands().UpperBand; def kcupper = KeltnerChannels().Upper_Band; def Squeeze = bbupper - kcupper < 0; plot Squeezeplot = if showsqueeze and Squeeze then linediv else Double.NaN; Squeezeplot.SetDefaultColor(Color.BLACK); Squeezeplot.SetPaintingStrategy(PaintingStrategy.POINTS); Squeezeplot.SetLineWeight(1); Squeezeplot.HideBubble(); #Count of Periods in consecutive squeeze rec countsq = if Squeeze then countsq[1] + 1 else 0; rec count1sq = if !Squeeze then count1sq[1] + 1 else 0; #Expansion Bubbles input n = 5; def n1 = n + 1; def c = close; input showsqueezebubble = yes; AddChartBubble(showsqueezebubble and !IsNaN(c[n1]) and IsNaN(c[n]), linediv[n1] , ( if Squeeze[n1] then "S \n" + Round(countsq[n1], 2) else "NS \n" + count1sq[n1]) , if aggsum[n1] == 6 then Color.GREEN else if aggsum[n1] == 0 then Color.RED else Color.WHITE, up = No); Alert(Between(aggsum[1], 0, 2) and aggsum == 6 and !Squeeze, "Candles - All Green", Alert.BAR, Sound.Ding); Alert(Between(aggsum[1], 1, 3) and aggsum == 0 and !Squeeze, "Candles - All Red ", Alert.BAR, Sound.Ding);
Is there a scan for this indicator, i would like to be able to create a dynamic watchlist that will populate when all three time frames are aligned.See if this helps. Hopefully, the few minor correntions seem to work.
Is it possible to place an arrow (up or down) on price chart if multiple time frame (MTF) MACD (2m, 5m & 10m) are in agreement (up or down) to go long or short for day trading? Currently i am visually trading with other indicators plus MACD agreement but if this can be automated, it will be a great tool (not stand alone but with other confirming indicators). Thanks.
Is there an indicator available for short term day trading which will indicate agreement for MACD histogram (up or down) for 2 minutes, 5 minutes and 10 minutes time frame which will place an up or down arrow on the bar indicating agreement for all three time frames?
#MACD_3_Timeframes_Green_Red
declare lower;
script m {
input aggPeriod = AggregationPeriod.HOUR;
input fastLength = 12;
input slowLength = 26;
input signalLength = 9;
input displace = 0;
plot MACD = ExpAverage(close(period = aggPeriod)[displace], fastLength) -
ExpAverage(close(period = aggPeriod)[displace], slowLength);
plot Signal = ExpAverage(ExpAverage(close(period = aggPeriod)[displace],
fastLength) - ExpAverage(close(period = aggPeriod)[displace], slowLength),
signalLength);
plot Diff = MACD - Signal;
}
input agg1 = AggregationPeriod.TWO_MIN;
input agg2 = AggregationPeriod.FIVE_MIN;
input agg3 = AggregationPeriod.TEN_MIN;
def m1 = m("agg period" = agg1).Diff > 0;
def m2 = m("agg period" = agg2).Diff > 0;
def m3 = m("agg period" = agg3).Diff > 0;
plot line1 = if IsNaN(close) then Double.NaN else 1;
line1.AssignValueColor(if m1 == 1 then Color.GREEN else Color.RED);
line1.SetPaintingStrategy(PaintingStrategy.POINTS);
plot line2 = if IsNaN(close) then Double.NaN else 2;
line2.AssignValueColor(if m2 == 1 then Color.GREEN else Color.RED);
line2.SetPaintingStrategy(PaintingStrategy.POINTS);
plot line3 = if IsNaN(close) then Double.NaN else 3;
line3.AssignValueColor(if m3 == 1 then Color.GREEN else Color.RED);
line3.SetPaintingStrategy(PaintingStrategy.POINTS);
plot line4 = 4;
line4.SetDefaultColor(Color.WHITE);
def sum = compoundvalue(1,
if m1 + m2 + m3 == 3 then 1
else if m1 + m2 + m3 == 0 then 0
else sum[1], 0);
addchartBubble(1,low,sum);
plot line5 = if IsNaN(close) then Double.NaN else 5;
line5.AssignValueColor(if sum == 1 then Color.GREEN else Color.RED);
line5.SetPaintingStrategy(PaintingStrategy.POINTS);
plot line7 = if IsNaN(close) then Double.NaN else 7;
line7.SetDefaultColor(Color.BLACK);
input showbubbles = yes;
input bubblemover = 7;
def b = bubblemover;
def b1 = b + 1;
def mover = showbubbles and IsNaN(close[b]) and !IsNaN(close[b1]);
AddChartBubble(mover, line1[b1], agg1 / 60000 + "m", line1.TakeValueColor());
AddChartBubble(mover, line2[b1], agg2 / 60000 + "m", line2.TakeValueColor());
AddChartBubble(mover, line3[b1], agg3 / 60000 + "m", line3.TakeValueColor());
AddChartBubble(mover, line5[b1], "All", line5.TakeValueColor());
To see only the last datapoint, you want to say:I'm building my first indicator, just a simplified way to view MACD trend from multiple timeframes plotted via multiple lines on a lower graph using points (green for bullish and red for bearish).
The problem I'm having is that when viewing a 1 min chart, the 1 min data points work as expected, however for the 10 min aggregation there are up to 9 additional data points being painted into the future. How can I get it to paint a single data point for the 10 min aggregation based on where the MACD was at that specific minute?
plot x = datapoint[1] and !datapoint ;
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
Thread starter | Similar threads | Forum | Replies | Date |
---|---|---|---|---|
Multiple Non-Linear Regression [ChartPrime] for ThinkOrSwim | Custom | 0 | ||
S | Multiple divergences For ThinkOrSwim | Custom | 8 | |
ML: Multiple Logistic Regression for ThinkOrSwim | Custom | 5 | ||
V | Multiple-Day Anchored VWAP For ThinkOrSwim | Custom | 10 | |
Multiple Frequency Volatility Correlation for ThinkOrSwim | Custom | 0 |
Start a new thread and receive assistance from our community.
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.
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.