Repaints (MTF) Moving Average Dashboard For ThinkOrSwim

Repaints
Hi @SleepyZ ! Do you have a code like this:
https://usethinkscript.com/threads/...cd-dashboard-for-thinkorswim.7530/#post-74562
with 9ExponentialMovingAverage and 20 ExponentialMovingAverage or other EMA instead of MACD? Thanks in advance

For example if the 9EMA is above 20 EMA the bubble is green.

An 'Averages' Method was added to the linked script.

There are agg1 - agg6 periods possible. If you do not feel the need for all six, you can choose the same aggregation period selection for multiple ones of the agg1 - agg6. See the image below for an example.

Screenshot-2023-01-02-124304.png
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 Averages,"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;

#Averages
input length1 = 9;
input length2 = 20;
input avgtype = averageType.EXPONENTIAL;
input price   = fundamentalType.CLOSE;
def ma1_1 = movingaverage(avgtype, fundamental(price, period = agg1), length1);
def ma2_1 = movingaverage(avgtype, fundamental(price, period = agg1), length2);
def ma1_2 = movingaverage(avgtype, fundamental(price, period = agg2), length1);
def ma2_2 = movingaverage(avgtype, fundamental(price, period = agg2), length2);
def ma1_3 = movingaverage(avgtype, fundamental(price, period = agg3), length1);
def ma2_3 = movingaverage(avgtype, fundamental(price, period = agg3), length2);
def ma1_4 = movingaverage(avgtype, fundamental(price, period = agg4), length1);
def ma2_4 = movingaverage(avgtype, fundamental(price, period = agg4), length2);
def ma1_5 = movingaverage(avgtype, fundamental(price, period = agg5), length1);
def ma2_5 = movingaverage(avgtype, fundamental(price, period = agg5), length2);
def ma1_6 = movingaverage(avgtype, fundamental(price, period = agg6), length1);
def ma2_6 = movingaverage(avgtype, fundamental(price, period = agg6), length2);

#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."Averages" {
Agg1per = ma1_1 > ma2_1;
Agg2per = ma1_2 > ma2_2;
Agg3per = ma1_3 > ma2_3;
agg4per = ma1_4 > ma2_4;
agg5per = ma1_5 > ma2_5;
agg6per = ma1_6 > ma2_6;;
}else 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."Averages"
then "Averages"
else 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);
 
EDIT: Nevermind, got it sorted.

I put this Multi Timeframe Heiken Ashi indicator together today if anyone would like to take a look at it on a 5 minute chart. I've got a couple problems.
1. I've got it almost there, but I've been digging around for hours now to try to get the background coloring figured out. I would like the green background to trigger on the first time that all timeframes are all aligned as green and then stay that way until they switch until all align as red.
2. I would like a notification that displays a message whenever the lowest timeframe being used in the study does not match the timeframe of the chart. I found some code on that but could not get it to work.
Thanks in advance.

MoPvtSm.png
 
Last edited by a moderator:
@theLEMband You may found this code I did awhile ago useful also. It has multiple periods, multiple methods, and clouds amongst some of the features.

Capture.jpg
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 "HASmooth", "Open_Close", "Close_Close[1]", "HAOpen_HAClose", "Trend", "SuperTrend"};
input useupper_lower = {default upper, lower};
input showdotplot    = yes;
input agg1           = AggregationPeriod.MIN;
input agg2           = AggregationPeriod.TWO_MIN;
input agg3           = AggregationPeriod.THREE_MIN;
input agg4           = AggregationPeriod.five_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 );

#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;
def HH4      = (Highest(high(period = agg4) , trend_lookback) + Lowest(low(period = agg4), trend_lookback)) / 2;
def Trend4   = close(period = agg4) > HH4;


# SuperTrend - "Strategy" by Mobius
# Chat Room Request
# V03.10.2015
input AtrMult        = 0.7;
input nATR           = 4;
input AvgType        = AverageType.HULL;
input price          = FundamentalType.HL2;

#SuperTrend1
def ATR1 = MovingAverage(AvgType, TrueRange(high(period = agg1), close(period = agg1), low(period = agg1)), nATR);
def UP1 = Fundamental(price, period = agg1) + (AtrMult * ATR1);
def DN1 = Fundamental(price, period = agg1) + (-AtrMult * ATR1);
def ST1 = if close(period = agg1) < ST1[1]
          then UP1
          else DN1;
def T1  = if close(period = agg1) > ST1
          then 1
          else 0;

#SuperTrend2

def ATR2 = MovingAverage(AvgType, TrueRange(high(period = agg2), close(period = agg2), low(period = agg2)), nATR);
def UP2 = Fundamental(price, period = agg2) + (AtrMult * ATR2);
def DN2 = Fundamental(price, period = agg2) + (-AtrMult * ATR2);
def ST2 = if close(period = agg2) < ST2[1]
          then UP2
          else DN2;
def T2  = if close(period = agg2) > ST2 then 1 else 0;

#SuperTrend3
def ATR3 = MovingAverage(AvgType, TrueRange(high(period = agg3), close(period = agg3), low(period = agg3)), nATR);
def UP3 = Fundamental(price, period = agg3) + (AtrMult * ATR3);
def DN3 = Fundamental(price, period = agg3) + (-AtrMult * ATR3);
def ST3 = if close(period = agg3) < ST3[1]
          then UP3
          else DN3;
def T3  = if close(period = agg3) > ST3
          then 1
          else 0;

#SuperTrend4
def ATR4 = MovingAverage(AvgType, TrueRange(high(period = agg4), close(period = agg4), low(period = agg4)), nATR);
def UP4 = Fundamental(price, period = agg4) + (AtrMult * ATR4);
def DN4 = Fundamental(price, period = agg4) + (-AtrMult * ATR4);
def ST4 = if close(period=agg4) < ST4[1]
          then UP4
          else DN4;
def T4  = if close(period = agg4) > ST4
          then 1
          else 0;

# HAsmoothed:
input avgha = averageType.simple;
input lenha = 10;
def o1 = MovingAverage(avgha, HAopen1, lenha);
def c1 = MovingAverage(avgha, HAclose1, lenha);
def o2 = MovingAverage(avgha, HAopen2, lenha);
def c2 = MovingAverage(avgha, HAclose2, lenha);
def o3 = MovingAverage(avgha, HAopen3, lenha);
def c3 = MovingAverage(avgha, HAclose3, lenha);
def o4 = MovingAverage(avgha, HAopen4, lenha);
def c4 = MovingAverage(avgha, HAclose4, lenha);

#Method applied to each aggregation

def Agg1per;
def Agg2per;
def Agg3per;
def Agg4per;
plot Agg1lower;
plot Agg2lower;
plot Agg3lower;
plot Agg4lower;

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];
}else if method == method."HAOpen_HAClose" {
Agg1per= HAclose1 > HAopen1;
Agg2per= HAclose2 > HAopen2;
Agg3per= HAclose3 > HAopen3;
Agg4per= HAclose4 > HAopen4;
}else if method == method."HASmooth" {
Agg1per= c1 > o1;
Agg2per= c2 > o2;
Agg3per= c3 > o3;
Agg4per= c4 > o4;
}else if method == method."Trend" {
Agg1per= Trend1;
Agg2per= Trend2;
Agg3per= Trend3;
Agg4per= Trend4;
}else if method == method."SuperTrend" {
Agg1per= T1;
Agg2per= T2;
Agg3per= T3;
Agg4per= T4;
}else {
Agg1per= close(period = agg1) > open(period = agg1);
Agg2per= close(period = agg2) > open(period = agg2);
Agg3per= close(period = agg3) > open(period = agg3);
Agg4per= close(period = agg4) > open(period = agg4);
}
          
#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
            then Color.GREEN
            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
            then Color.GREEN
            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
            then Color.GREEN
            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
            then Color.GREEN
            else Color.RED);

# Label identifying method and color green/red if all green/red otherwise white
def aggsum = Agg1per + Agg2per + Agg3per + Agg4per;
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."HASmooth"
                  then "HASmooth" 
                  else if method == method."Trend"
                  then "Trend"
                  else if method == method."SuperTrend"
                  then "ST"
                  else "C_O" ,
            if aggsum >= 3
            then Color.GREEN
            else if aggsum <= 1 
            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;
} 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;
}

agg1lower.SetPaintingStrategy(PaintingStrategy.POINTS);
agg1lower.AssignValueColor(if Agg1per == 1
                           then Color.GREEN
                           else Color.RED);
agg2lower.SetPaintingStrategy(PaintingStrategy.POINTS);
agg2lower.AssignValueColor(if Agg2per == 1
                           then Color.GREEN
                           else Color.RED);
agg3lower.SetPaintingStrategy(PaintingStrategy.POINTS);
agg3lower.AssignValueColor(if Agg3per == 1
                           then Color.GREEN
                           else Color.RED);
agg4lower.SetPaintingStrategy(PaintingStrategy.POINTS);
agg4lower.AssignValueColor(if Agg4per == 1
                           then Color.GREEN
                           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 <= 1 then if useupper_lower == useupper_lower.upper then -8.25 else  6.5 else Double.NaN;
sumagg.SetPaintingStrategy(PaintingStrategy.POINTS);
sumagg.AssignValueColor(if aggsum >= 4
                           then Color.GREEN
                           else if aggsum <= 0 
                           then Color.RED   
                           else Color.WHITE);

input showcloud = yes;
    def cloudcolor = if aggsum == 4 then 1 else if cloudcolor[1] == 1 and aggsum !=0 then 1 else 0;
    def ccolor = cloudcolor;
    AddCloud(if showcloud and ccolor == 1 then Double.POSITIVE_INFINITY else Double.NaN, Double.NEGATIVE_INFINITY, Color.LIGHT_GREEN, Color.LIGHT_GREEN);
    AddCloud(if showcloud and ccolor == 0 then Double.POSITIVE_INFINITY else Double.NaN, Double.NEGATIVE_INFINITY, Color.LIGHT_RED, color2 = Color.LIGHT_RED);

#Squeeze Added
input showsqueeze = yes;
def bbupper = reference BollingerBands(length = 20, "num dev dn" = -2.0, "num dev up" = 2.0).UpperBand;
def kcupper = KeltnerChannels(length = 20, factor = 1.5).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]<=1
               then color.red
               else color.white);
input usealerts = no;
Alert(usealerts and between(aggsum[1],0,2) and aggsum>=3 and !squeeze, "Candles - All Green", Alert.Bar, Sound.Ding);
Alert(usealerts and between(aggsum[1],1,3) and aggsum<=1 and !squeeze, "Candles - All Red  ", Alert.Bar, Sound.Ding);
 
could you possibly share this indicator?
I am working on cleaning up the code to make it smoother. It really bogs down my computer (cursor lags, quotes lag, etc.) which is a high-end workstation. If I can get it working smoothly, I will post it on usethinkscript.

@theLEMband You may found this code I did awhile ago useful also. It has multiple periods, multiple methods, and clouds amongst some of the features.
Thank you very much!
 
could you possibly share this indicator?
It still slows the computer, but it is better than my first attempt. I am sharing per your request, but I don't think this is all that useful due to the fact that it will continually repaint until the higher timeframe is complete.
See image in first post.

Ruby:
##Heiken Ashi Lower
##ver 210817.0 by theLEMband
## NOTE: THIS REPAINTS
declare lower;

input aggt1 = AggregationPeriod.FIVE_MIN;
def haCloset1 = ohlc4(period = aggt1);
def haOpent1 = if haOpent1[1] == 0 then haCloset1[1] else (haOpent1[1] + haCloset1[1]) / 2;
plot trendt1 = if close(period = aggt1) then 1 else Double.NaN;
trendt1.AssignValueColor(if haCloset1 > haOpent1 then Color.GREEN else if haCloset1 < haOpent1 then Color.RED else Color.WHITE);
trendt1.SetPaintingStrategy(PaintingStrategy.POINTS);
trendt1.SetLineWeight(2);

input aggt2 = AggregationPeriod.FIFTEEN_MIN;
def haCloset2 = ohlc4(period = aggt2);
def haOpent2 = if haOpent2[1] == 0 then haCloset2[1] else (haOpent2[1] + haCloset2[1]) / 2;
plot trendt2 = if close(period = aggt2) then 2 else Double.NaN;
trendt2.AssignValueColor(if haCloset2 > haOpent2 then Color.GREEN else if haCloset2 < haOpent2 then Color.RED else Color.WHITE);
trendt2.SetPaintingStrategy(PaintingStrategy.POINTS);
trendt2.SetLineWeight(2);

input aggt3 = AggregationPeriod.THIRTY_MIN;
def haCloset3 = ohlc4(period = aggt3);
def haOpent3 = if haOpent3[1] == 0 then haCloset3[1] else (haOpent3[1] + haCloset3[1]) / 2;
plot trendt3 = if close(period = aggt3) then 3 else Double.NaN;
trendt3.AssignValueColor(if haCloset3 > haOpent3 then Color.GREEN else if haCloset3 < haOpent3 then Color.RED else Color.WHITE);
trendt3.SetPaintingStrategy(PaintingStrategy.POINTS);
trendt3.SetLineWeight(2);

input aggt4 = AggregationPeriod.HOUR;
def haCloset4 = ohlc4(period = aggt4);
def haOpent4 = if haOpent4[1] == 0 then haCloset4[1] else (haOpent4[1] + haCloset4[1]) / 2;
plot trendt4 = if close(period = aggt4) then 4 else Double.NaN;
trendt4.AssignValueColor(if haCloset4 > haOpent4 then Color.GREEN else if haCloset4 < haOpent4 then Color.RED else Color.WHITE);
trendt4.SetPaintingStrategy(PaintingStrategy.POINTS);
trendt4.SetLineWeight(2);

input aggt5 = AggregationPeriod.TWO_HOURS;
def haCloset5 = ohlc4(period = aggt5);
def haOpent5 = if haOpent5[1] == 0 then haCloset5[1] else (haOpent5[1] + haCloset5[1]) / 2;
plot trendt5 = if close(period = aggt5) then 5 else Double.NaN;
trendt5.AssignValueColor(if haCloset5 > haOpent5 then Color.GREEN else if haCloset5 < haOpent5 then Color.RED else Color.WHITE);
trendt5.SetPaintingStrategy(PaintingStrategy.POINTS);
trendt5.SetLineWeight(2);

input aggt6 = AggregationPeriod.FOUR_HOURS;
def haCloset6 = ohlc4(period = aggt6);
def haOpent6 = if haOpent6[1] == 0 then haCloset6[1] else (haOpent6[1] + haCloset6[1]) / 2;
def haHight6 = Max(high, Max(haCloset6, haOpent6));
def haLowt6 = Min(low, Min(haCloset6, haOpent6));
plot trendt6 = if close(period = aggt6) then 6 else Double.NaN;
trendt6.AssignValueColor(if haCloset6 > haOpent6 then Color.GREEN else if haCloset6 < haOpent6 then Color.RED else Color.WHITE);
trendt6.SetPaintingStrategy(PaintingStrategy.POINTS);
trendt6.SetLineWeight(2);

input aggt7 = AggregationPeriod.DAY;
def haCloset7 = ohlc4(period = aggt7);
def haOpent7 = if haOpent7[1] == 0 then haCloset7[1] else (haOpent7[1] + haCloset7[1]) / 2;
plot trendt7 = if close(period = aggt7) then 7 else Double.NaN;
trendt7.AssignValueColor(if haCloset7 > haOpent7 then Color.GREEN else if haCloset7 < haOpent7 then Color.RED else Color.WHITE);
trendt7.SetPaintingStrategy(PaintingStrategy.POINTS);
trendt7.SetLineWeight(2);

def test1 = if haCloset1 > haOpent1 then 1 else if haCloset1 < haOpent1 then -1 else 0;
def test2 = if haCloset2 > haOpent2 then 1 else if haCloset2 < haOpent2 then -1 else 0;
def test3 = if haCloset3 > haOpent3 then 1 else if haCloset3 < haOpent3 then -1 else 0;
def test4 = if haCloset4 > haOpent4 then 1 else if haCloset4 < haOpent4 then -1 else 0;
def test5 = if haCloset5 > haOpent5 then 1 else if haCloset5 < haOpent5 then -1 else 0;
def test6 = if haCloset6 > haOpent6 then 1 else if haCloset6 < haOpent6 then -1 else 0;
def test7 = if haCloset7 > haOpent7 then 1 else if haCloset7 < haOpent7 then -1 else 0;

def total = test1 + test2 + test3 + test4 + test5 + test6 + test7;


def NewLong = if total == 7 then 1 else 0;
def StillLong = if haCloset7 > haOpent7 and total != -7 then 1 else 0;
def Greenup = if NewLong or StillLong then 1 else 0;
def NewShort = if total == -7 then 1 else 0;
def StillShort = if  haCloset7 < haOpent7 and total != 7 then 1 else 0;
def Redup = if NewShort or StillShort then 1 else 0;

def cond1 = if Greenup == 1 then 7 else 0;
def cond2 = if Redup == 1 then 7 else 0;
AddCloud(cond1, cond2, Color.GREEN, Color.RED);

##Testing/Debugging
#plot abstot = AbsValue(total);
 
It still slows the computer, but it is better than my first attempt. I am sharing per your request, but I don't think this is all that useful due to the fact that it will continually repaint until the higher timeframe is complete.
See image in first post.

Ruby:
##Heiken Ashi Lower
##ver 210817.0 by theLEMband
## NOTE: THIS REPAINTS
declare lower;

input aggt1 = AggregationPeriod.FIVE_MIN;
def haCloset1 = ohlc4(period = aggt1);
def haOpent1 = if haOpent1[1] == 0 then haCloset1[1] else (haOpent1[1] + haCloset1[1]) / 2;
plot trendt1 = if close(period = aggt1) then 1 else Double.NaN;
trendt1.AssignValueColor(if haCloset1 > haOpent1 then Color.GREEN else if haCloset1 < haOpent1 then Color.RED else Color.WHITE);
trendt1.SetPaintingStrategy(PaintingStrategy.POINTS);
trendt1.SetLineWeight(2);

input aggt2 = AggregationPeriod.FIFTEEN_MIN;
def haCloset2 = ohlc4(period = aggt2);
def haOpent2 = if haOpent2[1] == 0 then haCloset2[1] else (haOpent2[1] + haCloset2[1]) / 2;
plot trendt2 = if close(period = aggt2) then 2 else Double.NaN;
trendt2.AssignValueColor(if haCloset2 > haOpent2 then Color.GREEN else if haCloset2 < haOpent2 then Color.RED else Color.WHITE);
trendt2.SetPaintingStrategy(PaintingStrategy.POINTS);
trendt2.SetLineWeight(2);

input aggt3 = AggregationPeriod.THIRTY_MIN;
def haCloset3 = ohlc4(period = aggt3);
def haOpent3 = if haOpent3[1] == 0 then haCloset3[1] else (haOpent3[1] + haCloset3[1]) / 2;
plot trendt3 = if close(period = aggt3) then 3 else Double.NaN;
trendt3.AssignValueColor(if haCloset3 > haOpent3 then Color.GREEN else if haCloset3 < haOpent3 then Color.RED else Color.WHITE);
trendt3.SetPaintingStrategy(PaintingStrategy.POINTS);
trendt3.SetLineWeight(2);

input aggt4 = AggregationPeriod.HOUR;
def haCloset4 = ohlc4(period = aggt4);
def haOpent4 = if haOpent4[1] == 0 then haCloset4[1] else (haOpent4[1] + haCloset4[1]) / 2;
plot trendt4 = if close(period = aggt4) then 4 else Double.NaN;
trendt4.AssignValueColor(if haCloset4 > haOpent4 then Color.GREEN else if haCloset4 < haOpent4 then Color.RED else Color.WHITE);
trendt4.SetPaintingStrategy(PaintingStrategy.POINTS);
trendt4.SetLineWeight(2);

input aggt5 = AggregationPeriod.TWO_HOURS;
def haCloset5 = ohlc4(period = aggt5);
def haOpent5 = if haOpent5[1] == 0 then haCloset5[1] else (haOpent5[1] + haCloset5[1]) / 2;
plot trendt5 = if close(period = aggt5) then 5 else Double.NaN;
trendt5.AssignValueColor(if haCloset5 > haOpent5 then Color.GREEN else if haCloset5 < haOpent5 then Color.RED else Color.WHITE);
trendt5.SetPaintingStrategy(PaintingStrategy.POINTS);
trendt5.SetLineWeight(2);

input aggt6 = AggregationPeriod.FOUR_HOURS;
def haCloset6 = ohlc4(period = aggt6);
def haOpent6 = if haOpent6[1] == 0 then haCloset6[1] else (haOpent6[1] + haCloset6[1]) / 2;
def haHight6 = Max(high, Max(haCloset6, haOpent6));
def haLowt6 = Min(low, Min(haCloset6, haOpent6));
plot trendt6 = if close(period = aggt6) then 6 else Double.NaN;
trendt6.AssignValueColor(if haCloset6 > haOpent6 then Color.GREEN else if haCloset6 < haOpent6 then Color.RED else Color.WHITE);
trendt6.SetPaintingStrategy(PaintingStrategy.POINTS);
trendt6.SetLineWeight(2);

input aggt7 = AggregationPeriod.DAY;
def haCloset7 = ohlc4(period = aggt7);
def haOpent7 = if haOpent7[1] == 0 then haCloset7[1] else (haOpent7[1] + haCloset7[1]) / 2;
plot trendt7 = if close(period = aggt7) then 7 else Double.NaN;
trendt7.AssignValueColor(if haCloset7 > haOpent7 then Color.GREEN else if haCloset7 < haOpent7 then Color.RED else Color.WHITE);
trendt7.SetPaintingStrategy(PaintingStrategy.POINTS);
trendt7.SetLineWeight(2);

def test1 = if haCloset1 > haOpent1 then 1 else if haCloset1 < haOpent1 then -1 else 0;
def test2 = if haCloset2 > haOpent2 then 1 else if haCloset2 < haOpent2 then -1 else 0;
def test3 = if haCloset3 > haOpent3 then 1 else if haCloset3 < haOpent3 then -1 else 0;
def test4 = if haCloset4 > haOpent4 then 1 else if haCloset4 < haOpent4 then -1 else 0;
def test5 = if haCloset5 > haOpent5 then 1 else if haCloset5 < haOpent5 then -1 else 0;
def test6 = if haCloset6 > haOpent6 then 1 else if haCloset6 < haOpent6 then -1 else 0;
def test7 = if haCloset7 > haOpent7 then 1 else if haCloset7 < haOpent7 then -1 else 0;

def total = test1 + test2 + test3 + test4 + test5 + test6 + test7;


def NewLong = if total == 7 then 1 else 0;
def StillLong = if haCloset7 > haOpent7 and total != -7 then 1 else 0;
def Greenup = if NewLong or StillLong then 1 else 0;
def NewShort = if total == -7 then 1 else 0;
def StillShort = if  haCloset7 < haOpent7 and total != 7 then 1 else 0;
def Redup = if NewShort or StillShort then 1 else 0;

def cond1 = if Greenup == 1 then 7 else 0;
def cond2 = if Redup == 1 then 7 else 0;
AddCloud(cond1, cond2, Color.GREEN, Color.RED);

##Testing/Debugging
#plot abstot = AbsValue(total);
Thank you for trying and I applaud you for your effort. The theory of this indicator sounds like it could... (A)simply and reduce the excessive amount of indicators on the charts and (B) Make easier decisions on trades and stop the "paralysis of analysis" of having too many indicators.
 
Hey @SleepyZ, I just stumbled upon this indicator and have been testing it on my chart. Can you explain the "S or NS" bubble that appears in the right expansion field. It appears to change color with the Trend label, but I'm unclear as to what the S or NS designation refers to as well as the number displayed. Thanks in advance!
 
Hey @SleepyZ, I just stumbled upon this indicator and have been testing it on my chart. Can you explain the "S or NS" bubble that appears in the right expansion field. It appears to change color with the Trend label, but I'm unclear as to what the S or NS designation refers to as well as the number displayed. Thanks in advance!

The "S" stands for currently in a "Squeeze" and "NS" stands for currently "Not in a Squeeze". The number describes how many bars are involved in each.
 
The "S" stands for currently in a "Squeeze" and "NS" stands for currently "Not in a Squeeze". The number describes how many bars are involved in each.
This is awesome! I hope this isnt a dumb question, but I turned off the dot plot, and just kept the labels. Id like to put them in the upper portion of the chart, I thought the input : "Use upper or lower" would give me what I needed but doesnt seem to change anything. I know I can just drag the study to the upper portion of the studies window, but it messes with the Y axis.

Thank you so much for your hard work, you guys are the best.
 
This is awesome! I hope this isnt a dumb question, but I turned off the dot plot, and just kept the labels. Id like to put them in the upper portion of the chart, I thought the input : "Use upper or lower" would give me what I needed but doesnt seem to change anything. I know I can just drag the study to the upper portion of the studies window, but it messes with the Y axis.

Thank you so much for your hard work, you guys are the best.
Go into the study itself and at the top where it says "declare lower;" simply change lower to upper and it should position the labels where you'd like them on the upper chart.
 
Go into the study itself and at the top where it says "declare lower;" simply change lower to upper and it should position the labels where you'd like them on the upper chart.
My man! Thank you. That did the trick, man I was over-thinking it with the script. Great to know
 
The "S" stands for currently in a "Squeeze" and "NS" stands for currently "Not in a Squeeze". The number describes how many bars are involved in each.
Hi SleepyZ, can you please help to show how to addchartbubble to the price candle where the two moving average crosses?
 
Hi SleepyZ, can you please help to show how to addchartbubble to the price candle where the two moving average crosses?

Here is an example

Code:
#Example EMA Cross
input len1 = 5;
input len2 = 8;
input bubbles = yes;

plot ema1 = ExpAverage(close, len1);
plot ema2 = ExpAverage(close, len2);

def  cond  = if Crosses(ema1, ema2) then 1 else 0;
def cross_ = if cond == 1 then close else Double.NaN;

AddChartBubble(bubbles and IsNaN(cross_[1]) and cross_, if ema1 > ema2 then low else high, asdollars(ema1), if ema1 > ema2 then Color.GREEN else Color.RED, if ema1 > ema2 then no else yes);
 

Attachments

  • Screenshot 2023-06-01 071530.png
    Screenshot 2023-06-01 071530.png
    108.6 KB · Views: 201
I changed the script to show on the upper, (declare upper) but I believe its intended to be a lower study. You can set the MA's to whatever length you want, and itll show them as labels if they are above or below. For instance i like the 9 and 21, so itll show multiple time frames (whichever ones you want) and if the 9MA is over the 15MA on the 15 min chart, then the 15 minute chart label will be green, or if 9 is below, itll be red.

Hope you find it useful!

MTF_MA
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 Averages,"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;

#Averages
input length1 = 9;
input length2 = 20;
input avgtype = averageType.EXPONENTIAL;
input price   = fundamentalType.CLOSE;
def ma1_1 = movingaverage(avgtype, fundamental(price, period = agg1), length1);
def ma2_1 = movingaverage(avgtype, fundamental(price, period = agg1), length2);
def ma1_2 = movingaverage(avgtype, fundamental(price, period = agg2), length1);
def ma2_2 = movingaverage(avgtype, fundamental(price, period = agg2), length2);
def ma1_3 = movingaverage(avgtype, fundamental(price, period = agg3), length1);
def ma2_3 = movingaverage(avgtype, fundamental(price, period = agg3), length2);
def ma1_4 = movingaverage(avgtype, fundamental(price, period = agg4), length1);
def ma2_4 = movingaverage(avgtype, fundamental(price, period = agg4), length2);
def ma1_5 = movingaverage(avgtype, fundamental(price, period = agg5), length1);
def ma2_5 = movingaverage(avgtype, fundamental(price, period = agg5), length2);
def ma1_6 = movingaverage(avgtype, fundamental(price, period = agg6), length1);
def ma2_6 = movingaverage(avgtype, fundamental(price, period = agg6), length2);

#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."Averages" {
Agg1per = ma1_1 > ma2_1;
Agg2per = ma1_2 > ma2_2;
Agg3per = ma1_3 > ma2_3;
agg4per = ma1_4 > ma2_4;
agg5per = ma1_5 > ma2_5;
agg6per = ma1_6 > ma2_6;;
}else 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."Averages"
then "Averages"
else 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);
 
Last edited by a moderator:
I changed the script to show on the upper, (declare upper) but I believe its intended to be a lower study. You can set the MA's to whatever length you want, and itll show them as labels if they are above or below. For instance i like the 9 and 21, so itll show multiple time frames (whichever ones you want) and if the 9MA is over the 15MA on the 15 min chart, then the 15 minute chart label will be green, or if 9 is below, itll be red.

Hope you find it useful!
Downloaded the MTF_MA script, set use upper lower to upper, but not seeing anything on the chart.

UPDATE:
Thanks MerryDay, I was only able to see it on a one minute chart.
 
Last edited by a moderator:
You didn't provide enough information to say where you went astray.
Newer ToS users, run into problems with indicators not showing up on charts when they are attempting to use MTF scripts on a timeframe higher than the secondary aggregation that is called in the script.

ToS platform allows higher timeframe plots to be applied to lower timeframes, but it is not possible to put lower aggregations on a higher timeframe.

To get you started, here is a chart with the indicator already applied.
shared chart link: http://tos.mx/DOjRlwy Click here for --> Easiest way to load shared links
pvWelO4.png

PS: you might want to consider pulling this study down to a lower chart.
I commented out any plots so I only get the labels, as well
 
EDIT: Nevermind, got it sorted.

I put this Multi Timeframe Heiken Ashi indicator together today if anyone would like to take a look at it on a 5 minute chart. I've got a couple problems.
1. I've got it almost there, but I've been digging around for hours now to try to get the background coloring figured out. I would like the green background to trigger on the first time that all timeframes are all aligned as green and then stay that way until they switch until all align as red.
2. I would like a notification that displays a message whenever the lowest timeframe being used in the study does not match the timeframe of the chart. I found some code on that but could not get it to work.
Thanks in advance.

View attachment 11440
Is that SPY vol indicator available?
 

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