#MTF_MovingAverage_LowerStudy_Dots
#Caution: Anytime a higher timeframe row changes color between the white dots, the entire row between the white dots will change to the new color. This will include dots that have previously plotted another color during that span between the white dots. This could give you a misleading impression when viewing the lower timeframe chart.
declare lower;
input showchartbubbles = yes;
input show_white_dots = yes;
input timeFrame1 = AggregationPeriod.FIVE_MIN;
input timeFrame2 = AggregationPeriod.FIFTEEN_MIN;
input timeFrame3 = AggregationPeriod.THIRTY_MIN;
input maLength1 = 5;
input maType1 = AverageType.EXPONENTIAL;
input maLength2 = 20;
input maType2 = AverageType.EXPONENTIAL;
def ma1 = MovingAverage(maType1, close(period = timeFrame1), maLength1);
def ma2 = MovingAverage(maType2, close(period = timeFrame1), maLength2);
def ma3 = MovingAverage(maType1, close(period = timeFrame2), maLength1);
def ma4 = MovingAverage(maType2, close(period = timeFrame2), maLength2);
def ma5 = MovingAverage(maType1, close(period = timeFrame3), maLength1);
def ma6 = MovingAverage(maType2, close(period = timeFrame3), maLength2);
#White Dots plotted, marking the last Higher Timeframe bar on the Lower Timeframe
input begin = 0930;
def minutes1 = timeFrame1 / 60000;
def minutes2 = timeFrame2 / 60000;
def minutes3 = timeFrame3 / 60000;
def barSeq = if SecondsTillTime(begin) == 0 and
SecondsFromTime(begin) == 0
then 0
else barSeq[1] + 1;
def bar = barSeq;
def bar1 = if (bar) % (minutes1 / (GetAggregationPeriod() / 60000)) == 0 then bar1[1] + 1 else bar1[1];
def bar1ext = if !IsNaN(close) and IsNaN(close[-1]) then bar1 else Double.NaN;
def bar2 = if (bar) % (minutes2 / (GetAggregationPeriod() / 60000)) == 0 then bar2[1] + 1 else bar2[1];
def bar2ext = if !IsNaN(close) and IsNaN(close[-1]) then bar2 else Double.NaN;
def bar3 = if (bar) % (minutes3 / (GetAggregationPeriod() / 60000)) == 0 then bar3[1] + 1 else bar3[1];
def bar3ext = if !IsNaN(close) and IsNaN(close[-1]) then bar3 else Double.NaN;
plot dot1 = if show_white_dots and between(bar1, highestall(bar1ext), highestall(bar1ext)+1) and (bar) % (minutes1 / (GetAggregationPeriod() / 60000)) == 0 then .9 else Double.NaN;
dot1.SetPaintingStrategy(PaintingStrategy.POINTS);
dot1.SetDefaultColor(Color.WHITE);
plot dot2 = if show_white_dots and between(bar2, highestall(bar2ext), highestall(bar2ext)+1) and (bar) % (minutes2 / (GetAggregationPeriod() / 60000)) == 0 then 1.9 else Double.NaN;
dot2.SetPaintingStrategy(PaintingStrategy.POINTS);
dot2.SetDefaultColor(Color.WHITE);
plot dot3 = if show_white_dots and between(bar3, highestall(bar3ext), highestall(bar3ext)+1) and (bar) % (minutes3 / (GetAggregationPeriod() / 60000)) == 0 then 2.9 else Double.NaN;
dot3.SetPaintingStrategy(PaintingStrategy.POINTS);
dot3.SetDefaultColor(Color.WHITE);
#Red/Green Dots plotted comparing the the Two Higher Moving Averages to each other
#Row 1
plot row1 = if !IsNaN(close) then 1 else Double.NaN;
row1.SetPaintingStrategy(PaintingStrategy.POINTS);
row1.AssignValueColor(if ma1 > ma2 then Color.GREEN else Color.RED);
row1.SetLineWeight(3);
#Row 2
plot row2 = if !IsNaN(close) then 2 else Double.NaN;
row2.SetPaintingStrategy(PaintingStrategy.POINTS);
row2.AssignValueColor(if ma3 > ma4 then Color.GREEN else Color.RED);
row2.SetLineWeight(3);
#Row 3
plot row3 = if !IsNaN(close) then 3 else Double.NaN;
row3.SetPaintingStrategy(PaintingStrategy.POINTS);
row3.AssignValueColor(if ma5 > ma6 then Color.GREEN else Color.RED);
row3.SetLineWeight(3);
#Chart Bubbles indicating the timeframe of each row
input b = 5; #Increase to move bubble to the right and Decrease to move bubble to the left
def bm = b + 1;
plot lowerline = 0;#Plotted to orient the Dots within the Lower Chart Panel
lowerline.SetDefaultColor(Color.GRAY);
plot upperline = 4;#Plotted to orient the Dots within the Lower Chart Panel
upperline.SetDefaultColor(Color.GRAY);
AddChartBubble(showchartbubbles and IsNaN(close[b]) and !IsNaN(close[bm]), row1[bm], timeFrame1 / 60000, if ma1[bm] > ma2[bm] then Color.GREEN else Color.RED);
AddChartBubble(showchartbubbles and IsNaN(close[b]) and !IsNaN(close[bm]), row2[bm], timeFrame2 / 60000, if ma3[bm] > ma4[bm] then Color.GREEN else Color.RED);
AddChartBubble(showchartbubbles and IsNaN(close[b]) and !IsNaN(close[bm]), row3[bm], timeFrame3 / 60000, if ma5[bm] > ma6[bm] then Color.GREEN else Color.RED);