Help with three candle code

SJP07

Member
I'm looking to build a code that captures:

A) Bullish move:
• Three candles
  • First candle is red
  • Second is green and at least twice the size of the first candle
  • Third candle low that is at least a penny greater than the high of the first candle

This code should plot a horizontal line at the high of the first candle that extends all the way to the left of the chart until it's crossed.

B) Bearish move
• Three candles
  • First candle is green
  • Second candle is red and at least twice the size of the first green candle.
  • Third candle high is at least a penny less than the low of the first candle.

This code should plot a horizontal line at the low of the first candle that extends all the way to the left of the chart until it's crossed.


Thanks in advance!!!!!
 
Solution
Still trying to figure out how to get this to only show for the current trading day (pre-market included). Any help?

I included the label code at the bottom of this script. Whatever is currently the make up of the lines for Day are what appears in the labels as far as I can see.

Capture.jpg
Ruby:
###############WEEK###############
def open_week;
def high_week;
def low_week;
def close_week;
def Volume_week;

if GetAggregationPeriod() <= AggregationPeriod.WEEK {
    open_week = open(period = AggregationPeriod.WEEK);
    high_week = high(period = AggregationPeriod.WEEK);
    low_week = low(period = AggregationPeriod.WEEK);
    close_week = close(period = AggregationPeriod.WEEK);
    Volume_week = volume(period =...
I'm looking to build a code that captures:

A) Bullish move:
• Three candles
  • First candle is red
  • Second is green and at least twice the size of the first candle
  • Third candle low that is at least a penny greater than the high of the first candle

This code should plot a horizontal line at the high of the first candle that extends all the way to the left of the chart until it's crossed.

B) Bearish move
• Three candles
  • First candle is green
  • Second candle is red and at least twice the size of the first green candle.
  • Third candle high is at least a penny less than the low of the first candle.

This code should plot a horizontal line at the low of the first candle that extends all the way to the left of the chart until it's crossed.

why do you want lines extended to the left?
 

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

I'm looking to build a code that captures:

A) Bullish move:
• Three candles
  • First candle is red
  • Second is green and at least twice the size of the first candle
  • Third candle low that is at least a penny greater than the high of the first candle

This code should plot a horizontal line at the high of the first candle that extends all the way to the left of the chart until it's crossed.

B) Bearish move
• Three candles
  • First candle is green
  • Second candle is red and at least twice the size of the first green candle.
  • Third candle high is at least a penny less than the low of the first candle.

This code should plot a horizontal line at the low of the first candle that extends all the way to the left of the chart until it's crossed.


Thanks in advance!!!!!

See if this gets you started. You requested the horizontal line to plot to the left, but I assumed you meant to the right. As a result, I did not understand how you are using the significance of the cross.

Ruby:
  #A) Bullish move:
#• Three candles
#First candle is red
#Second is green and at least twice the size of the first candle
#Third candle low that is at least a penny greater than the high of the first candle

#This code should plot a horizontal line at the high of the first candle that extends all the way to the left of the chart until it's crossed.

def cond1 = close[2] < open[2];
def cond2 = close[1] > open[1] and (high[1] - low[1]) > (high[2] - low[2]) * 2;
def cond3 = low > high[2] + .01;
def cond4 = if isnan(close)
            then cond4[1]
            else if cond1 && cond2 && cond3
            then high[2]
            else cond4[1];
plot bull = cond4;
bull.setpaintingStrategy(paintingStrategy.HORIZONTAL);

def cond1a = close[2] > open[2];
def cond2a = close[1] < open[1] and (high[1] - low[1]) > (high[2] - low[2]) * 2;
def cond3a = high < low[2] - .01;
def cond4a = if isnan(close)
            then cond4[1]
            else if cond1a && cond2a && cond3a
            then low[2]
            else cond4a[1];
plot bear = cond4a;
bear.setpaintingStrategy(paintingStrategy.HORIZONTAL);
 
See if this gets you started. You requested the horizontal line to plot to the left, but I assumed you meant to the right. As a result, I did not understand how you are using the significance of the cross.

Yes, this is exactly what I'm looking for. Sorry I did mean extend to the right. The script you wrote looks complete. Is there anything that I need to add?
 
See if this gets you started. You requested the horizontal line to plot to the left, but I assumed you meant to the right. As a result, I did not understand how you are using the significance of the cross.
I added an MTF code and a label, ow do I also add the price of the line itself onto the label?


input aggregationPeriod = AggregationPeriod.Thirty_Min;
def open = open(period = aggregationPeriod);
def high = high(period = aggregationPeriod);
def low = low(period = aggregationPeriod);
def close = close(period = aggregationPeriod);
def Volume = volume(period = aggregationPeriod);


#A) Bullish move:
#• Three candles
#First candle is red
#Second is green and at least twice the size of the first candle
#Third candle low that is at least a penny greater than the high of the first candle

#This code should plot a horizontal line at the high of the first candle that extends all the way to the left of the chart until it's crossed.

def cond1 = close[2] < open[2];
def cond2 = close[1] > open[1] and (high[1] - low[1]) > (high[2] - low[2]) * 2;
def cond3 = low > high[2] + .01;
def cond4 = if isnan(close)
then cond4[1]
else if cond1 && cond2 && cond3
then high[2]
else cond4[1];
plot bull = cond4;
bull.setpaintingStrategy(paintingStrategy.HORIZONTAL);

def cond1a = close[2] > open[2];
def cond2a = close[1] < open[1] and (high[1] - low[1]) > (high[2] - low[2]) * 2;
def cond3a = high < low[2] - .01;
def cond4a = if isnan(close)
then cond4[1]
else if cond1a && cond2a && cond3a
then low[2]
else cond4a[1];

plot bear = cond4a;
bear.setpaintingStrategy(paintingStrategy.HORIZONTAL);

AddChartBubble(bull <> bull[1], bull, "30Min", Color.Orange);
AddChartBubble(bear <> bear[1], bear, "30Min", Color.Orange);
 
I added an MTF code and a label, ow do I also add the price of the line itself onto the label?


input aggregationPeriod = AggregationPeriod.Thirty_Min;
def open = open(period = aggregationPeriod);
def high = high(period = aggregationPeriod);
def low = low(period = aggregationPeriod);
def close = close(period = aggregationPeriod);
def Volume = volume(period = aggregationPeriod);


#A) Bullish move:
#• Three candles
#First candle is red
#Second is green and at least twice the size of the first candle
#Third candle low that is at least a penny greater than the high of the first candle

#This code should plot a horizontal line at the high of the first candle that extends all the way to the left of the chart until it's crossed.

def cond1 = close[2] < open[2];
def cond2 = close[1] > open[1] and (high[1] - low[1]) > (high[2] - low[2]) * 2;
def cond3 = low > high[2] + .01;
def cond4 = if isnan(close)
then cond4[1]
else if cond1 && cond2 && cond3
then high[2]
else cond4[1];
plot bull = cond4;
bull.setpaintingStrategy(paintingStrategy.HORIZONTAL);

def cond1a = close[2] > open[2];
def cond2a = close[1] < open[1] and (high[1] - low[1]) > (high[2] - low[2]) * 2;
def cond3a = high < low[2] - .01;
def cond4a = if isnan(close)
then cond4[1]
else if cond1a && cond2a && cond3a
then low[2]
else cond4a[1];

plot bear = cond4a;
bear.setpaintingStrategy(paintingStrategy.HORIZONTAL);

AddChartBubble(bull <> bull[1], bull, "30Min", Color.Orange);
AddChartBubble(bear <> bear[1], bear, "30Min", Color.Orange);

This will auto add the aggregationperiod value and price stacked in bubble. If you want the price next to the aggregationperiod then remove the \n

Ruby:
AddChartBubble(bull <> bull[1], bull, (aggregationPeriod / 60000) + "Min \n" + AsText(bull), Color.ORANGE, no);
AddChartBubble(bear <> bear[1], bear, (aggregationPeriod / 60000) + "Min \n" + AsText(bear), Color.ORANGE);
 
See if this gets you started. You requested the horizontal line to plot to the left, but I assumed you meant to the right. As a result, I did not understand how you are using the significance of the cross.
Been looking for this!
1.Is it possible to take out the 1 penny and just make it any amount? meaning if there is any gap between the first candles high and the third candles low (Bullish) or vice versa 1st candles low third candles High
2. Can you make the first bar indiscriminate either bull bear or doji just as long as long as there's a gap.
3. Can the line be changed to a cloud that closes when it comes in contact with price?

appreciated!
 
This will auto add the aggregationperiod value and price stacked in bubble. If you want the price next to the aggregationperiod then remove the \n
Thanks! It's not quite what I was looking for, but it gave me a good start. How do I get the bubbles to appear on the right side of the chart. Here's what I came up with...

AddChartBubble(Hour_bull <> Hour_bull[1], Hour_bull, Concat("Hour= $", Hour_bull), Color.Orange);
AddChartBubble(Hour_bear <> Hour_bear[1], Hour_bear, Concat("Hour = $", Hour_bear), Color.Orange);
 
Here' the full code I came up with. For some reason it doesn't populate on any chart larger than a 15min time frame. Can anyone help with that?

###############WEEK###############
input aggregationperiod_week = AggregationPeriod.WEEK;
def open_week = open(period = aggregationPeriod.WEEK);
def high_week = high(period = aggregationPeriod.WEEK);
def low_week = low(period = aggregationPeriod.WEEK);
def close_week = close(period = aggregationPeriod.WEEK);
def Volume_week = volume(period = aggregationPeriod.WEEK);

###############DAY###############
input aggregationperiod_day = AggregationPeriod.Day;
def open_day = open(period = aggregationPeriod.Day);
def high_day = high(period = aggregationPeriod.Day);
def low_day = low(period = aggregationPeriod.Day);
def close_day = close(period = aggregationPeriod.Day);
def Volume_day = volume(period = aggregationPeriod.Day);

###############4HR###############
input aggregationperiod_four_hours = AggregationPeriod.four_hours;
def open_four_hours = open(period = aggregationPeriod.four_hours);
def high_four_hours = high(period = aggregationPeriod.four_hours);
def low_four_hours = low(period = aggregationPeriod.four_hours);
def close_four_hours = close(period = aggregationPeriod.four_hours);
def Volume_four_hours = volume(period = aggregationPeriod.four_hours);

###############2HR###############
input aggregationperiod_two_hours = AggregationPeriod.two_hours;
def open_two_hours = open(period = aggregationPeriod.two_hours);
def high_two_hours = high(period = aggregationPeriod.two_hours);
def low_two_hours = low(period = aggregationPeriod.two_hours);
def close_two_hours = close(period = aggregationPeriod.two_hours);
def Volume_two_hours = volume(period = aggregationPeriod.two_hours);

###############1HR###############
input aggregationperiod_hour = AggregationPeriod.hour;
def open_hour = open(period = aggregationPeriod.hour);
def high_hour = high(period = aggregationPeriod.hour);
def low_hour = low(period = aggregationPeriod.hour);
def close_hour = close(period = aggregationPeriod.hour);
def Volume_hour = volume(period = aggregationPeriod.hour);

###############30Min###############
input aggregationperiod_thirty_min = AggregationPeriod.thirty_min;
def open_thirty_min = open(period = aggregationPeriod.thirty_min);
def high_thirty_min = high(period = aggregationPeriod.thirty_min);
def low_thirty_min = low(period = aggregationPeriod.thirty_min);
def close_thirty_min = close(period = aggregationPeriod.thirty_min);
def Volume_thirty_min = volume(period = aggregationPeriod.thirty_min);

###############15Min###############
input aggregationperiod_fifteen_min = AggregationPeriod.fifteen_min;
def open_fifteen_min = open(period = aggregationPeriod.fifteen_min);
def high_fifteen_min = high(period = aggregationPeriod.fifteen_min);
def low_fifteen_min = low(period = aggregationPeriod.fifteen_min);
def close_fifteen_min = close(period = aggregationPeriod.fifteen_min);
def Volume_fifteen_min = volume(period = aggregationPeriod.fifteen_min);

###############10Min###############
input aggregationperiod_ten_min = AggregationPeriod.ten_min;
def open_ten_min = open(period = AggregationPeriod.ten_min);
def high_ten_min = high(period = AggregationPeriod.ten_min);
def low_ten_min = low(period = AggregationPeriod.ten_min);
def close_ten_min = close(period = AggregationPeriod.ten_min);
def Volume_ten_min = volume(period = AggregationPeriod.ten_min);

########################WEEK CODE###########################

def cond1W = close_week[2] < open_week[2];
def cond2W = close_week[1] > open_week[1] and (high_week[1] - low_week[1]) > (high_week[2] - low_week[2]) * 2;
def cond3W = low_week > high_week[2] + .01;
def cond4W = if IsNaN(close_week)
then cond4W[1]
else if cond1W && cond2W && cond3W
then high_week[2]
else cond4W[1];
plot Week_bull = cond4W;
Week_bull.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Week_bull.SetDefaultColor(Color.Light_green);

def cond1Wa = close_week[2] > open_week[2];
def cond2Wa = close_week[1] < open_week[1] and (high_week[1] - low_week[1]) > (high_week[2] - low_week[2]) * 2;
def cond3Wa = high_week < low_week[2] - .01;
def cond4Wa = if IsNaN(close_week)
then cond4W[1]
else if cond1Wa && cond2Wa && cond3Wa
then low_week[2]
else cond4Wa[1];

plot Week_bear = cond4Wa;
Week_bear.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Week_bear.SetDefaultColor(Color.Pink);

AddChartBubble(week_bull <> week_bull[1], week_bull, Concat("W= $", week_bull), Color.Orange);

AddChartBubble(week_bear <> week_bear[1], week_bear, Concat("W = $", week_bear), Color.Orange);

########################DAY CODE###########################
def cond1D = close_Day[2] < open_Day[2];
def cond2D = close_Day[1] > open_Day[1] and (high_Day[1] - low_Day[1]) > (high_Day[2] - low_Day[2]) * 2;
def cond3D = low_Day > high_Day[2] + .01;
def cond4D = if IsNaN(close_Day)
then cond4D[1]
else if cond1D && cond2D && cond3D
then high_Day[2]
else cond4D[1];
plot Day_bull = cond4D;
Day_bull.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Day_bull.SetDefaultColor(Color.Light_green);

def cond1Da = close_Day[2] > open_Day[2];
def cond2Da = close_Day[1] < open_Day[1] and (high_Day[1] - low_Day[1]) > (high_Day[2] - low_Day[2]) * 2;
def cond3Da = high_Day < low_Day[2] - .01;
def cond4Da = if IsNaN(close_Day)
then cond4D[1]
else if cond1Da && cond2Da && cond3Da
then low_Day[2]
else cond4Da[1];

plot Day_bear = cond4Da;
Day_bear.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Day_bear.SetDefaultColor(Color.Pink);


AddChartBubble(Day_bull <> Day_bull[1], Day_bull, Concat("D= $", Day_bull), Color.Orange);
AddChartBubble(Day_bear <> Day_bear[1], Day_bear, Concat("D = $", Day_bear), Color.Orange);

#######################FOUR HOUR CODE###########################
def cond1_4H = close_Four_hours[2] < open_Four_hours[2];
def cond2_4H = close_Four_hours[1] > open_Four_hours[1] and (high_Four_hours[1] - low_Four_hours[1]) > (high_Four_hours[2] - low_Four_hours[2]) * 2;
def cond3_4H = low_Four_hours > high_Four_hours[2] + .01;
def cond4_4H = if IsNaN(close_Four_hours)
then cond4_4H[1]
else if cond1_4H && cond2_4H && cond3_4H
then high_Four_hours[2]
else cond4_4H[1];
plot Four_hours_bull = cond4_4H;
Four_hours_bull.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Four_hours_bull.SetDefaultColor(Color.Light_green);

def cond1_4Ha = close_Four_hours[2] > open_Four_hours[2];
def cond2_4Ha = close_Four_hours[1] < open_Four_hours[1] and (high_Four_hours[1] - low_Four_hours[1]) > (high_Four_hours[2] - low_Four_hours[2]) * 2;
def cond3_4Ha = high_Four_hours < low_Four_hours[2] - .01;
def cond4_4Ha = if IsNaN(close_Four_hours)
then cond4_4H[1]
else if cond1_4Ha && cond2_4Ha && cond3_4Ha
then low_Four_hours[2]
else cond4_4Ha[1];

plot Four_hours_bear = cond4_4Ha;
Four_hours_bear.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Four_hours_bear.SetDefaultColor(Color.Pink);


AddChartBubble(Four_hours_bull <> Four_hours_bull[1], Four_hours_bull, Concat("4H= $", Four_hours_bull), Color.Orange);
AddChartBubble(Four_hours_bear <> Four_hours_bear[1], Four_hours_bear, Concat("4H = $", Four_hours_bear), Color.Orange);

#######################TWO HOUR CODE###########################
def cond1_2_2H = close_Two_Hours[2] < open_Two_Hours[2];
def cond2_2H = close_Two_Hours[1] > open_Two_Hours[1] and (high_Two_Hours[1] - low_Two_Hours[1]) > (high_Two_Hours[2] - low_Two_Hours[2]) * 2;
def cond3_2H = low_Two_Hours > high_Two_Hours[2] + .01;
def cond4_2H = if IsNaN(close_Two_Hours)
then cond4_2H[1]
else if cond1_2_2H && cond2_2H && cond3_2H
then high_Two_Hours[2]
else cond4_2H[1];
plot Two_Hours_bull = cond4_2H;
Two_Hours_bull.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Two_Hours_bull.SetDefaultColor(Color.Light_green);

def cond1_2_2Ha = close_Two_Hours[2] > open_Two_Hours[2];
def cond2_2Ha = close_Two_Hours[1] < open_Two_Hours[1] and (high_Two_Hours[1] - low_Two_Hours[1]) > (high_Two_Hours[2] - low_Two_Hours[2]) * 2;
def cond3_2Ha = high_Two_Hours < low_Two_Hours[2] - .01;
def cond4_2Ha = if IsNaN(close_Two_Hours)
then cond4_2Ha[1]
else if cond1_2_2Ha && cond2_2Ha && cond3_2Ha
then low_Two_Hours[2]
else cond4_2Ha[1];

plot Two_Hours_bear = cond4_2Ha;
Two_Hours_bear.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Two_Hours_bear.SetDefaultColor(Color.Pink);

AddChartBubble(Two_Hours_bull <> Two_Hours_bull[1], Two_Hours_bull, Concat("2H= $", Two_Hours_bull), Color.Orange);
AddChartBubble(Two_Hours_bear <> Two_Hours_bear[1], Two_Hours_bear, Concat("2H = $", Two_Hours_bear), Color.Orange);


#######################HOUR CODE###########################

def cond1H = close_Hour[2] < open_Hour[2];
def cond2H = close_Hour[1] > open_Hour[1] and (high_Hour[1] - low_Hour[1]) > (high_Hour[2] - low_Hour[2]) * 2;
def cond3H = low_Hour > high_Hour[2] + .01;
def cond4H = if IsNaN(close_Hour)
then cond4H[1]
else if cond1H && cond2H && cond3H
then high_Hour[2]
else cond4H[1];
plot Hour_bull = cond4H;
Hour_bull.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Hour_bull.SetDefaultColor(Color.Light_green);

def cond1Ha = close_Hour[2] > open_Hour[2];
def cond2Ha = close_Hour[1] < open_Hour[1] and (high_Hour[1] - low_Hour[1]) > (high_Hour[2] - low_Hour[2]) * 2;
def cond3Ha = high_Hour < low_Hour[2] - .01;
def cond4Ha = if IsNaN(close_Hour)
then cond4Ha[1]
else if cond1Ha && cond2Ha && cond3Ha
then low_Hour[2]
else cond4Ha[1];

plot Hour_bear = cond4Ha;
Hour_bear.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Hour_bear.SetDefaultColor(Color.Pink);

AddChartBubble(Hour_bull <> Hour_bull[1], Hour_bull, Concat("H= $", Hour_bull), Color.Orange);
AddChartBubble(Hour_bear <> Hour_bear[1], Hour_bear, Concat("H = $", Hour_bear), Color.Orange);

#######################30 MIN CODE###########################
def cond1_30M = close_Thirty_min[2] < open_Thirty_min[2];
def cond2_30M = close_Thirty_min[1] > open_Thirty_min[1] and (high_Thirty_min[1] - low_Thirty_min[1]) > (high_Thirty_min[2] - low_Thirty_min[2]) * 2;
def cond3_30M = low_Thirty_min > high_Thirty_min[2] + .01;
def cond4_30M = if IsNaN(close_Thirty_min)
then cond4_30M[1]
else if cond1_30M && cond2_30M && cond3_30M
then high_Thirty_min[2]
else cond4_30M[1];
plot Thirty_min_bull = cond4_30M;
Thirty_min_bull.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
#Thirty_min_bull.SetDefaultColor(Color.Light_green);

def cond1_30Ma = close_Thirty_min[2] > open_Thirty_min[2];
def cond2_30Ma = close_Thirty_min[1] < open_Thirty_min[1] and (high_Thirty_min[1] - low_Thirty_min[1]) > (high_Thirty_min[2] - low_Thirty_min[2]) * 2;
def cond3_30Ma = high_Thirty_min < low_Thirty_min[2] - .01;
def cond4_30Ma = if IsNaN(close_Thirty_min)
then cond4_30M[1]
else if cond1_30Ma && cond2_30Ma && cond3_30Ma
then low_Thirty_min[2]
else cond4_30Ma[1];

plot Thirty_min_bear = cond4_30Ma;
Thirty_min_bear.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
#Thirty_min_bear.SetDefaultColor(Color.Pink);

AddChartBubble(Thirty_min_bull <> Thirty_min_bull[1], Thirty_min_bull, Concat("30M= $", Thirty_min_bull), Color.Orange);
AddChartBubble(Thirty_min_bear <> Thirty_min_bear[1], Thirty_min_bear, Concat("30M = $", Thirty_min_bear), Color.Orange);

#######################15 MIN CODE###########################

def cond1_15M = close_Fifteen_min[2] < open_Fifteen_min[2];
def cond2_15M = close_Fifteen_min[1] > open_Fifteen_min[1] and (high_Fifteen_min[1] - low_Fifteen_min[1]) > (high_Fifteen_min[2] - low_Fifteen_min[2]) * 2;
def cond3_15M = low_Fifteen_min > high_Fifteen_min[2] + .01;
def cond4_15M = if IsNaN(close_Fifteen_min)
then cond4_15M[1]
else if cond1_15M && cond2_15M && cond3_15M
then high_Fifteen_min[2]
else cond4_15M[1];
plot Fifteen_min_bull = cond4_15M;
Fifteen_min_bull.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
#Fifteen_min_bull.SetDefaultColor(Color.Light_green);

def cond1_15Ma = close_Fifteen_min[2] > open_Fifteen_min[2];
def cond2_15Ma = close_Fifteen_min[1] < open_Fifteen_min[1] and (high_Fifteen_min[1] - low_Fifteen_min[1]) > (high_Fifteen_min[2] - low_Fifteen_min[2]) * 2;
def cond3_15Ma = high_Fifteen_min < low_Fifteen_min[2] - .01;
def cond4_15Ma = if IsNaN(close_Fifteen_min)
then cond4_15M[1]
else if cond1_15Ma && cond2_15Ma && cond3_15Ma
then low_Fifteen_min[2]
else cond4_15Ma[1];

plot Fifteen_min_bear = cond4_15Ma;
Fifteen_min_bear.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
#Fifteen_min_bear.SetDefaultColor(Color.Pink);

AddChartBubble(Fifteen_min_bull <> Fifteen_min_bull[1], Fifteen_min_bull, Concat("15M= $", Fifteen_min_bull), Color.Orange);
AddChartBubble(Fifteen_min_bear <> Fifteen_min_bear[1], Fifteen_min_bear, Concat("15M = $", Fifteen_min_bear), Color.Orange);

Why isn't the day MTF populating on the daily time frame chart?
 
Last edited by a moderator:
So should I rearrange the code so that the larger aggregation period is last?

A common error when using MTF indicators is trying to use a time frame that is lower than the chart you are posting it on. On the TOS platform, you can display data from a higher timeframe onto a lower timeframe but not the other way around.
https://tlc.thinkorswim.com/center/...hapter-11---Referencing-Secondary-Aggregation

The standard answer is that from ToS Support is:
Plotting errors will occur when the secondary aggregation period is less than the primary aggregation period defined by chart settings.

You can never have a script that has secondary aggregation period is less than the primary aggregation.
You will have issues.
 
Last edited:
A common error when using MTF indicators is trying to use a time frame that is lower than the chart you are posting it on. On the TOS platform, you can display data from a higher timeframe onto a lower timeframe but not the other way around.
https://tlc.thinkorswim.com/center/...hapter-11---Referencing-Secondary-Aggregation

The standard answer is that from ToS Support is:


You can never have a script that has secondary aggregation period is less than the primary aggregation.
You will have issues.

I have revised your script to allow it to show on any chart aggregation that has secondary aggregation periods that are less than the primary chart aggregation. Any of your aggregations that are less the chart aggregation will not be shown, but the script will still work for those that can be shown

Here is how it was done for the 15m timeframe to allow it to not error the code on a higher than 15m timeframe. This type of if/then/else scripting is the only one that seemed to work to prevent the error.
Ruby:
###############15Min###############

def open_fifteen_min;
def high_fifteen_min;
def low_fifteen_min;
def close_fifteen_min;
def Volume_fifteen_min;
if GetAggregationPeriod() <= AggregationPeriod.FIFTEEN_MIN {
    open_fifteen_min = open(period = AggregationPeriod.FIFTEEN_MIN);
    high_fifteen_min = high(period = AggregationPeriod.FIFTEEN_MIN);
    low_fifteen_min = low(period = AggregationPeriod.FIFTEEN_MIN);
    close_fifteen_min = close(period = AggregationPeriod.FIFTEEN_MIN);
    Volume_fifteen_min = volume(period = AggregationPeriod.FIFTEEN_MIN);
} else {
    open_fifteen_min = Double.NaN;
    high_fifteen_min = Double.NaN;
    low_fifteen_min = Double.NaN;
    close_fifteen_min = Double.NaN;
    Volume_fifteen_min = Double.NaN;
}
Here is the full code
Ruby:
###############WEEK###############
def open_week;
def high_week;
def low_week;
def close_week;
def Volume_week;

if GetAggregationPeriod() <= AggregationPeriod.WEEK {
    open_week = open(period = AggregationPeriod.WEEK);
    high_week = high(period = AggregationPeriod.WEEK);
    low_week = low(period = AggregationPeriod.WEEK);
    close_week = close(period = AggregationPeriod.WEEK);
    Volume_week = volume(period = AggregationPeriod.WEEK);
} else {
    open_week = Double.NaN;
    high_week = Double.NaN;
    low_week = Double.NaN;
    close_week = Double.NaN;
    Volume_week = Double.NaN;
}

###############DAY###############

def open_day;
def high_day;
def low_day;
def close_day;
def Volume_day;

if GetAggregationPeriod() <= AggregationPeriod.DAY {
    open_day = open(period = AggregationPeriod.DAY);
    high_day = high(period = AggregationPeriod.DAY);
    low_day = low(period = AggregationPeriod.DAY);
    close_day = close(period = AggregationPeriod.DAY);
    Volume_day = volume(period = AggregationPeriod.DAY);
} else {
    open_day = Double.NaN;
    high_day = Double.NaN;
    low_day = Double.NaN;
    close_day = Double.NaN;
    Volume_day = Double.NaN;
}


###############4HR###############

def open_four_hours;
def high_four_hours;
def low_four_hours;
def close_four_hours;
def Volume_four_hours;

if GetAggregationPeriod() <= AggregationPeriod.FOUR_HOURS {
    open_four_hours = open(period = AggregationPeriod.FOUR_HOURS);
    high_four_hours = high(period = AggregationPeriod.FOUR_HOURS);
    low_four_hours = low(period = AggregationPeriod.FOUR_HOURS);
    close_four_hours = close(period = AggregationPeriod.FOUR_HOURS);
    Volume_four_hours = volume(period = AggregationPeriod.FOUR_HOURS);
} else {
    open_four_hours = Double.NaN;
    high_four_hours = Double.NaN;
    low_four_hours = Double.NaN;
    close_four_hours = Double.NaN;
    Volume_four_hours = Double.NaN;
}

###############2HR###############

def open_two_hours;
def high_two_hours;
def low_two_hours;
def close_two_hours;
def Volume_two_hours;

if GetAggregationPeriod() <= AggregationPeriod.TWO_HOURS {
    open_two_hours = open(period = AggregationPeriod.TWO_HOURS);
    high_two_hours = high(period = AggregationPeriod.TWO_HOURS);
    low_two_hours = low(period = AggregationPeriod.TWO_HOURS);
    close_two_hours = close(period = AggregationPeriod.TWO_HOURS);
    Volume_two_hours = volume(period = AggregationPeriod.TWO_HOURS);
} else {
    open_two_hours = Double.NaN;
    high_two_hours = Double.NaN;
    low_two_hours = Double.NaN;
    close_two_hours = Double.NaN;
    Volume_two_hours = Double.NaN;
}
###############1HR###############

def open_hour;
def high_hour;
def low_hour;
def close_hour;
def Volume_hour;

if GetAggregationPeriod() <= AggregationPeriod.HOUR {
    open_hour = open(period = AggregationPeriod.HOUR);
    high_hour = high(period = AggregationPeriod.HOUR);
    low_hour = low(period = AggregationPeriod.HOUR);
    close_hour = close(period = AggregationPeriod.HOUR);
    Volume_hour = volume(period = AggregationPeriod.HOUR);
} else {
    open_hour = Double.NaN;
    high_hour = Double.NaN;
    low_hour = Double.NaN;
    close_hour = Double.NaN;
    Volume_hour = Double.NaN;
}
###############30Min###############

def open_thirty_min;
def high_thirty_min;
def low_thirty_min;
def close_thirty_min;
def Volume_thirty_min;

if GetAggregationPeriod() <= AggregationPeriod.THIRTY_MIN {
    open_thirty_min = open(period = AggregationPeriod.THIRTY_MIN);
    high_thirty_min = high(period = AggregationPeriod.THIRTY_MIN);
    low_thirty_min = low(period = AggregationPeriod.THIRTY_MIN);
    close_thirty_min = close(period = AggregationPeriod.THIRTY_MIN);
    Volume_thirty_min = volume(period = AggregationPeriod.THIRTY_MIN);
} else {
    open_thirty_min = Double.NaN;
    high_thirty_min = Double.NaN;
    low_thirty_min = Double.NaN;
    close_thirty_min = Double.NaN;
    Volume_thirty_min = Double.NaN;
}

###############15Min###############

def open_fifteen_min;
def high_fifteen_min;
def low_fifteen_min;
def close_fifteen_min;
def Volume_fifteen_min;
if GetAggregationPeriod() <= AggregationPeriod.FIFTEEN_MIN {
    open_fifteen_min = open(period = AggregationPeriod.FIFTEEN_MIN);
    high_fifteen_min = high(period = AggregationPeriod.FIFTEEN_MIN);
    low_fifteen_min = low(period = AggregationPeriod.FIFTEEN_MIN);
    close_fifteen_min = close(period = AggregationPeriod.FIFTEEN_MIN);
    Volume_fifteen_min = volume(period = AggregationPeriod.FIFTEEN_MIN);
} else {
    open_fifteen_min = Double.NaN;
    high_fifteen_min = Double.NaN;
    low_fifteen_min = Double.NaN;
    close_fifteen_min = Double.NaN;
    Volume_fifteen_min = Double.NaN;
}

########################WEEK CODE###########################

def cond1W = close_week[2] < open_week[2];
def cond2W = close_week[1] > open_week[1] and (high_week[1] - low_week[1]) > (high_week[2] - low_week[2]) * 2;
def cond3W = low_week > high_week[2] + .01;
def cond4W = if IsNaN(close_week)
then cond4W[1]
else if cond1W && cond2W && cond3W
then high_week[2]
else cond4W[1];
plot Week_bull = cond4W;
Week_bull.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Week_bull.SetDefaultColor(Color.LIGHT_GREEN);

def cond1Wa = close_week[2] > open_week[2];
def cond2Wa = close_week[1] < open_week[1] and (high_week[1] - low_week[1]) > (high_week[2] - low_week[2]) * 2;
def cond3Wa = high_week < low_week[2] - .01;
def cond4Wa = if IsNaN(close_week)
then cond4W[1]
else if cond1Wa && cond2Wa && cond3Wa
then low_week[2]
else cond4Wa[1];

plot Week_bear = cond4Wa;
Week_bear.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Week_bear.SetDefaultColor(Color.PINK);

AddChartBubble(Week_bull <> Week_bull[1], Week_bull, Concat("W= $", Week_bull), Color.ORANGE);

AddChartBubble(Week_bear <> Week_bear[1], Week_bear, Concat("W = $", Week_bear), Color.ORANGE);

########################DAY CODE###########################
def cond1D = close_day[2] < open_day[2];
def cond2D = close_day[1] > open_day[1] and (high_day[1] - low_day[1]) > (high_day[2] - low_day[2]) * 2;
def cond3D = low_day > high_day[2] + .01;
def cond4D = if IsNaN(close_day)
then cond4D[1]
else if cond1D && cond2D && cond3D
then high_day[2]
else cond4D[1];
plot Day_bull = cond4D;
Day_bull.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Day_bull.SetDefaultColor(Color.LIGHT_GREEN);

def cond1Da = close_day[2] > open_day[2];
def cond2Da = close_day[1] < open_day[1] and (high_day[1] - low_day[1]) > (high_day[2] - low_day[2]) * 2;
def cond3Da = high_day < low_day[2] - .01;
def cond4Da = if IsNaN(close_day)
then cond4D[1]
else if cond1Da && cond2Da && cond3Da
then low_day[2]
else cond4Da[1];

plot Day_bear = cond4Da;
Day_bear.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Day_bear.SetDefaultColor(Color.PINK);


AddChartBubble(Day_bull <> Day_bull[1], Day_bull, Concat("D= $", Day_bull), Color.ORANGE);
AddChartBubble(Day_bear <> Day_bear[1], Day_bear, Concat("D = $", Day_bear), Color.ORANGE);

#######################FOUR HOUR CODE###########################
def cond1_4H = close_four_hours[2] < open_four_hours[2];
def cond2_4H = close_four_hours[1] > open_four_hours[1] and (high_four_hours[1] - low_four_hours[1]) > (high_four_hours[2] - low_four_hours[2]) * 2;
def cond3_4H = low_four_hours > high_four_hours[2] + .01;
def cond4_4H = if IsNaN(close_four_hours)
then cond4_4H[1]
else if cond1_4H && cond2_4H && cond3_4H
then high_four_hours[2]
else cond4_4H[1];
plot Four_hours_bull = cond4_4H;
Four_hours_bull.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Four_hours_bull.SetDefaultColor(Color.LIGHT_GREEN);

def cond1_4Ha = close_four_hours[2] > open_four_hours[2];
def cond2_4Ha = close_four_hours[1] < open_four_hours[1] and (high_four_hours[1] - low_four_hours[1]) > (high_four_hours[2] - low_four_hours[2]) * 2;
def cond3_4Ha = high_four_hours < low_four_hours[2] - .01;
def cond4_4Ha = if IsNaN(close_four_hours)
then cond4_4H[1]
else if cond1_4Ha && cond2_4Ha && cond3_4Ha
then low_four_hours[2]
else cond4_4Ha[1];

plot Four_hours_bear = cond4_4Ha;
Four_hours_bear.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Four_hours_bear.SetDefaultColor(Color.PINK);


AddChartBubble(Four_hours_bull <> Four_hours_bull[1], Four_hours_bull, Concat("4H= $", Four_hours_bull), Color.ORANGE);
AddChartBubble(Four_hours_bear <> Four_hours_bear[1], Four_hours_bear, Concat("4H = $", Four_hours_bear), Color.ORANGE);

#######################TWO HOUR CODE###########################
def cond1_2_2H = close_two_hours[2] < open_two_hours[2];
def cond2_2H = close_two_hours[1] > open_two_hours[1] and (high_two_hours[1] - low_two_hours[1]) > (high_two_hours[2] - low_two_hours[2]) * 2;
def cond3_2H = low_two_hours > high_two_hours[2] + .01;
def cond4_2H = if IsNaN(close_two_hours)
then cond4_2H[1]
else if cond1_2_2H && cond2_2H && cond3_2H
then high_two_hours[2]
else cond4_2H[1];
plot Two_Hours_bull = cond4_2H;
Two_Hours_bull.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Two_Hours_bull.SetDefaultColor(Color.LIGHT_GREEN);

def cond1_2_2Ha = close_two_hours[2] > open_two_hours[2];
def cond2_2Ha = close_two_hours[1] < open_two_hours[1] and (high_two_hours[1] - low_two_hours[1]) > (high_two_hours[2] - low_two_hours[2]) * 2;
def cond3_2Ha = high_two_hours < low_two_hours[2] - .01;
def cond4_2Ha = if IsNaN(close_two_hours)
then cond4_2Ha[1]
else if cond1_2_2Ha && cond2_2Ha && cond3_2Ha
then low_two_hours[2]
else cond4_2Ha[1];

plot Two_Hours_bear = cond4_2Ha;
Two_Hours_bear.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Two_Hours_bear.SetDefaultColor(Color.PINK);

AddChartBubble(Two_Hours_bull <> Two_Hours_bull[1], Two_Hours_bull, Concat("2H= $", Two_Hours_bull), Color.ORANGE);
AddChartBubble(Two_Hours_bear <> Two_Hours_bear[1], Two_Hours_bear, Concat("2H = $", Two_Hours_bear), Color.ORANGE);


#######################HOUR CODE###########################

def cond1H = close_hour[2] < open_hour[2];
def cond2H = close_hour[1] > open_hour[1] and (high_hour[1] - low_hour[1]) > (high_hour[2] - low_hour[2]) * 2;
def cond3H = low_hour > high_hour[2] + .01;
def cond4H = if IsNaN(close_hour)
then cond4H[1]
else if cond1H && cond2H && cond3H
then high_hour[2]
else cond4H[1];
plot Hour_bull = cond4H;
Hour_bull.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Hour_bull.SetDefaultColor(Color.LIGHT_GREEN);

def cond1Ha = close_hour[2] > open_hour[2];
def cond2Ha = close_hour[1] < open_hour[1] and (high_hour[1] - low_hour[1]) > (high_hour[2] - low_hour[2]) * 2;
def cond3Ha = high_hour < low_hour[2] - .01;
def cond4Ha = if IsNaN(close_hour)
then cond4Ha[1]
else if cond1Ha && cond2Ha && cond3Ha
then low_hour[2]
else cond4Ha[1];

plot Hour_bear = cond4Ha;
Hour_bear.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Hour_bear.SetDefaultColor(Color.PINK);

AddChartBubble(Hour_bull <> Hour_bull[1], Hour_bull, Concat("H= $", Hour_bull), Color.ORANGE);
AddChartBubble(Hour_bear <> Hour_bear[1], Hour_bear, Concat("H = $", Hour_bear), Color.ORANGE);

#######################30 MIN CODE###########################
def cond1_30M = close_thirty_min[2] < open_thirty_min[2];
def cond2_30M = close_thirty_min[1] > open_thirty_min[1] and (high_thirty_min[1] - low_thirty_min[1]) > (high_thirty_min[2] - low_thirty_min[2]) * 2;
def cond3_30M = low_thirty_min > high_thirty_min[2] + .01;
def cond4_30M = if IsNaN(close_thirty_min)
then cond4_30M[1]
else if cond1_30M && cond2_30M && cond3_30M
then high_thirty_min[2]
else cond4_30M[1];
plot Thirty_min_bull = cond4_30M;
Thirty_min_bull.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
#Thirty_min_bull.SetDefaultColor(Color.Light_green);

def cond1_30Ma = close_thirty_min[2] > open_thirty_min[2];
def cond2_30Ma = close_thirty_min[1] < open_thirty_min[1] and (high_thirty_min[1] - low_thirty_min[1]) > (high_thirty_min[2] - low_thirty_min[2]) * 2;
def cond3_30Ma = high_thirty_min < low_thirty_min[2] - .01;
def cond4_30Ma = if IsNaN(close_thirty_min)
then cond4_30M[1]
else if cond1_30Ma && cond2_30Ma && cond3_30Ma
then low_thirty_min[2]
else cond4_30Ma[1];

plot Thirty_min_bear = cond4_30Ma;
Thirty_min_bear.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
#Thirty_min_bear.SetDefaultColor(Color.Pink);

AddChartBubble(Thirty_min_bull <> Thirty_min_bull[1], Thirty_min_bull, Concat("30M= $", Thirty_min_bull), Color.ORANGE);
AddChartBubble(Thirty_min_bear <> Thirty_min_bear[1], Thirty_min_bear, Concat("30M = $", Thirty_min_bear), Color.ORANGE);

#######################15 MIN CODE###########################

def cond1_15M = close_fifteen_min[2] < open_fifteen_min[2];
def cond2_15M = close_fifteen_min[1] > open_fifteen_min[1] and (high_fifteen_min[1] - low_fifteen_min[1]) > (high_fifteen_min[2] - low_fifteen_min[2]) * 2;
def cond3_15M = low_fifteen_min > high_fifteen_min[2] + .01;
def cond4_15M = if IsNaN(close_fifteen_min)
then cond4_15M[1]
else if cond1_15M && cond2_15M && cond3_15M
then high_fifteen_min[2]
else cond4_15M[1];
plot Fifteen_min_bull = cond4_15M;
Fifteen_min_bull.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
#Fifteen_min_bull.SetDefaultColor(Color.Light_green);

def cond1_15Ma = close_fifteen_min[2] > open_fifteen_min[2];
def cond2_15Ma = close_fifteen_min[1] < open_fifteen_min[1] and (high_fifteen_min[1] - low_fifteen_min[1]) > (high_fifteen_min[2] - low_fifteen_min[2]) * 2;
def cond3_15Ma = high_fifteen_min < low_fifteen_min[2] - .01;
def cond4_15Ma = if IsNaN(close_fifteen_min)
then cond4_15M[1]
else if cond1_15Ma && cond2_15Ma && cond3_15Ma
then low_fifteen_min[2]
else cond4_15Ma[1];

plot Fifteen_min_bear = cond4_15Ma;
Fifteen_min_bear.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
#Fifteen_min_bear.SetDefaultColor(Color.Pink);

AddChartBubble(Fifteen_min_bull <> Fifteen_min_bull[1], Fifteen_min_bull, Concat("15M= $", Fifteen_min_bull), Color.ORANGE);
AddChartBubble(Fifteen_min_bear <> Fifteen_min_bear[1], Fifteen_min_bear, Concat("15M = $", Fifteen_min_bear), Color.ORANGE);
 
Last edited:
I have revised your script to allow it to show on any chart aggregation that has secondary aggregation periods that are less than the primary chart aggregation. Any of your aggregations that are less the chart aggregation will not be shown, but the script will still work for those that can be shown

Here is how it was done for the 15m timeframe to allow it to not error the code on a higher than 15m timeframe. This type of if/then/else scripting is the only one that seemed to work to prevent the error.

Here is the full code
I'm not sure how to apply this here, but how could I get the bubbles to line up and move to the right like in this code...

https://usethinkscript.com/threads/moving-labels-away-from-current-time.12434/#post-106777
 
I'm not sure how to apply this here, but how could I get the bubbles to line up and move to the right like in this code...

https://usethinkscript.com/threads/moving-labels-away-from-current-time.12434/#post-106777

This will move the bubbles to the right using instead of
Code:
AddChartBubble(Fifteen_min_bull <> Fifteen_min_bull[1], Fifteen_min_bull, Concat("15M= $", Fifteen_min_bull), Color.ORANGE);
AddChartBubble(Fifteen_min_bear <> Fifteen_min_bear[1], Fifteen_min_bear, Concat("15M = $", Fifteen_min_bear), Color.ORANGE);
using this
Code:
AddChartBubble(Fifteen_min_bull <> Fifteen_min_bull[-1], Fifteen_min_bull, Concat("15M= $", Fifteen_min_bull), Color.ORANGE);
AddChartBubble(Fifteen_min_bear <> Fifteen_min_bear[-1], Fifteen_min_bear, Concat("15M = $", Fifteen_min_bear), Color.ORANGE);

This revision to the above code then allows you to move the bubbles sideways at input bubblemover

Ruby:
AddChartBubble(Fifteen_min_bull[[B]b] [/B]<> Fifteen_min_bull[[B]b - 1][/B], Fifteen_min_bull[[B]b],[/B] Concat("15M= $", Fifteen_min_bull[[B]b])[/B], Color.ORANGE); 
AddChartBubble(Fifteen_min_bear[B][b] [/B]<> Fifteen_min_bear[B][b - 1],[/B] Fifteen_min_bear[B][b],[/B] Concat("15M = $", Fifteen_min_bear[[B]b][/B]), Color.ORANGE);

Here is the full revised movable bubble code

Ruby:
###############WEEK###############
def open_week;
def high_week;
def low_week;
def close_week;
def Volume_week;

if GetAggregationPeriod() <= AggregationPeriod.WEEK {
    open_week = open(period = AggregationPeriod.WEEK);
    high_week = high(period = AggregationPeriod.WEEK);
    low_week = low(period = AggregationPeriod.WEEK);
    close_week = close(period = AggregationPeriod.WEEK);
    Volume_week = volume(period = AggregationPeriod.WEEK);
} else {
    open_week = Double.NaN;
    high_week = Double.NaN;
    low_week = Double.NaN;
    close_week = Double.NaN;
    Volume_week = Double.NaN;
}

###############DAY###############

def open_day;
def high_day;
def low_day;
def close_day;
def Volume_day;

if GetAggregationPeriod() <= AggregationPeriod.DAY {
    open_day = open(period = AggregationPeriod.DAY);
    high_day = high(period = AggregationPeriod.DAY);
    low_day = low(period = AggregationPeriod.DAY);
    close_day = close(period = AggregationPeriod.DAY);
    Volume_day = volume(period = AggregationPeriod.DAY);
} else {
    open_day = Double.NaN;
    high_day = Double.NaN;
    low_day = Double.NaN;
    close_day = Double.NaN;
    Volume_day = Double.NaN;
}


###############4HR###############

def open_four_hours;
def high_four_hours;
def low_four_hours;
def close_four_hours;
def Volume_four_hours;

if GetAggregationPeriod() <= AggregationPeriod.FOUR_HOURS {
    open_four_hours = open(period = AggregationPeriod.FOUR_HOURS);
    high_four_hours = high(period = AggregationPeriod.FOUR_HOURS);
    low_four_hours = low(period = AggregationPeriod.FOUR_HOURS);
    close_four_hours = close(period = AggregationPeriod.FOUR_HOURS);
    Volume_four_hours = volume(period = AggregationPeriod.FOUR_HOURS);
} else {
    open_four_hours = Double.NaN;
    high_four_hours = Double.NaN;
    low_four_hours = Double.NaN;
    close_four_hours = Double.NaN;
    Volume_four_hours = Double.NaN;
}

###############2HR###############

def open_two_hours;
def high_two_hours;
def low_two_hours;
def close_two_hours;
def Volume_two_hours;

if GetAggregationPeriod() <= AggregationPeriod.TWO_HOURS {
    open_two_hours = open(period = AggregationPeriod.TWO_HOURS);
    high_two_hours = high(period = AggregationPeriod.TWO_HOURS);
    low_two_hours = low(period = AggregationPeriod.TWO_HOURS);
    close_two_hours = close(period = AggregationPeriod.TWO_HOURS);
    Volume_two_hours = volume(period = AggregationPeriod.TWO_HOURS);
} else {
    open_two_hours = Double.NaN;
    high_two_hours = Double.NaN;
    low_two_hours = Double.NaN;
    close_two_hours = Double.NaN;
    Volume_two_hours = Double.NaN;
}
###############1HR###############

def open_hour;
def high_hour;
def low_hour;
def close_hour;
def Volume_hour;

if GetAggregationPeriod() <= AggregationPeriod.HOUR {
    open_hour = open(period = AggregationPeriod.HOUR);
    high_hour = high(period = AggregationPeriod.HOUR);
    low_hour = low(period = AggregationPeriod.HOUR);
    close_hour = close(period = AggregationPeriod.HOUR);
    Volume_hour = volume(period = AggregationPeriod.HOUR);
} else {
    open_hour = Double.NaN;
    high_hour = Double.NaN;
    low_hour = Double.NaN;
    close_hour = Double.NaN;
    Volume_hour = Double.NaN;
}
###############30Min###############

def open_thirty_min;
def high_thirty_min;
def low_thirty_min;
def close_thirty_min;
def Volume_thirty_min;

if GetAggregationPeriod() <= AggregationPeriod.THIRTY_MIN {
    open_thirty_min = open(period = AggregationPeriod.THIRTY_MIN);
    high_thirty_min = high(period = AggregationPeriod.THIRTY_MIN);
    low_thirty_min = low(period = AggregationPeriod.THIRTY_MIN);
    close_thirty_min = close(period = AggregationPeriod.THIRTY_MIN);
    Volume_thirty_min = volume(period = AggregationPeriod.THIRTY_MIN);
} else {
    open_thirty_min = Double.NaN;
    high_thirty_min = Double.NaN;
    low_thirty_min = Double.NaN;
    close_thirty_min = Double.NaN;
    Volume_thirty_min = Double.NaN;
}

###############15Min###############

def open_fifteen_min;
def high_fifteen_min;
def low_fifteen_min;
def close_fifteen_min;
def Volume_fifteen_min;
if GetAggregationPeriod() <= AggregationPeriod.FIFTEEN_MIN {
    open_fifteen_min = open(period = AggregationPeriod.FIFTEEN_MIN);
    high_fifteen_min = high(period = AggregationPeriod.FIFTEEN_MIN);
    low_fifteen_min = low(period = AggregationPeriod.FIFTEEN_MIN);
    close_fifteen_min = close(period = AggregationPeriod.FIFTEEN_MIN);
    Volume_fifteen_min = volume(period = AggregationPeriod.FIFTEEN_MIN);
} else {
    open_fifteen_min = Double.NaN;
    high_fifteen_min = Double.NaN;
    low_fifteen_min = Double.NaN;
    close_fifteen_min = Double.NaN;
    Volume_fifteen_min = Double.NaN;
}

input bubblemover = 4;
def b = bubblemover;


########################WEEK CODE###########################

def cond1W = close_week[2] < open_week[2];
def cond2W = close_week[1] > open_week[1] and (high_week[1] - low_week[1]) > (high_week[2] - low_week[2]) * 2;
def cond3W = low_week > high_week[2] + .01;
def cond4W = if IsNaN(close_week)
then cond4W[1]
else if cond1W && cond2W && cond3W
then high_week[2]
else cond4W[1];
plot Week_bull = cond4W;
Week_bull.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Week_bull.SetDefaultColor(Color.LIGHT_GREEN);

def cond1Wa = close_week[2] > open_week[2];
def cond2Wa = close_week[1] < open_week[1] and (high_week[1] - low_week[1]) > (high_week[2] - low_week[2]) * 2;
def cond3Wa = high_week < low_week[2] - .01;
def cond4Wa = if IsNaN(close_week)
then cond4W[1]
else if cond1Wa && cond2Wa && cond3Wa
then low_week[2]
else cond4Wa[1];

plot Week_bear = cond4Wa;
Week_bear.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Week_bear.SetDefaultColor(Color.PINK);

AddChartBubble(Week_bull[b] <> Week_bull[b - 1], Week_bull[b], Concat("W= $", Week_bull[b]), Color.ORANGE);

AddChartBubble(Week_bear[b] <> Week_bear[b - 1], Week_bear[b], Concat("W = $", Week_bear[b]), Color.ORANGE);

########################DAY CODE###########################
def cond1D = close_day[2] < open_day[2];
def cond2D = close_day[1] > open_day[1] and (high_day[1] - low_day[1]) > (high_day[2] - low_day[2]) * 2;
def cond3D = low_day > high_day[2] + .01;
def cond4D = if IsNaN(close_day)
then cond4D[1]
else if cond1D && cond2D && cond3D
then high_day[2]
else cond4D[1];
plot Day_bull = cond4D;
Day_bull.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Day_bull.SetDefaultColor(Color.LIGHT_GREEN);

def cond1Da = close_day[2] > open_day[2];
def cond2Da = close_day[1] < open_day[1] and (high_day[1] - low_day[1]) > (high_day[2] - low_day[2]) * 2;
def cond3Da = high_day < low_day[2] - .01;
def cond4Da = if IsNaN(close_day)
then cond4D[1]
else if cond1Da && cond2Da && cond3Da
then low_day[2]
else cond4Da[1];

plot Day_bear = cond4Da;
Day_bear.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Day_bear.SetDefaultColor(Color.PINK);


AddChartBubble(Day_bull[b] <> Day_bull[b - 1], Day_bull[b], Concat("D= $", Day_bull[b]), Color.ORANGE);
AddChartBubble(Day_bear[b] <> Day_bear[b - 1], Day_bear[b], Concat("D = $", Day_bear[b]), Color.ORANGE);

#######################FOUR HOUR CODE###########################
def cond1_4H = close_four_hours[2] < open_four_hours[2];
def cond2_4H = close_four_hours[1] > open_four_hours[1] and (high_four_hours[1] - low_four_hours[1]) > (high_four_hours[2] - low_four_hours[2]) * 2;
def cond3_4H = low_four_hours > high_four_hours[2] + .01;
def cond4_4H = if IsNaN(close_four_hours)
then cond4_4H[1]
else if cond1_4H && cond2_4H && cond3_4H
then high_four_hours[2]
else cond4_4H[1];
plot Four_hours_bull = cond4_4H;
Four_hours_bull.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Four_hours_bull.SetDefaultColor(Color.LIGHT_GREEN);

def cond1_4Ha = close_four_hours[2] > open_four_hours[2];
def cond2_4Ha = close_four_hours[1] < open_four_hours[1] and (high_four_hours[1] - low_four_hours[1]) > (high_four_hours[2] - low_four_hours[2]) * 2;
def cond3_4Ha = high_four_hours < low_four_hours[2] - .01;
def cond4_4Ha = if IsNaN(close_four_hours)
then cond4_4H[1]
else if cond1_4Ha && cond2_4Ha && cond3_4Ha
then low_four_hours[2]
else cond4_4Ha[1];

plot Four_hours_bear = cond4_4Ha;
Four_hours_bear.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Four_hours_bear.SetDefaultColor(Color.PINK);


AddChartBubble(Four_hours_bull[b] <> Four_hours_bull[b - 1], Four_hours_bull[b], Concat("4H= $", Four_hours_bull[b]), Color.ORANGE);
AddChartBubble(Four_hours_bear[b] <> Four_hours_bear[b - 1], Four_hours_bear[b], Concat("4H = $", Four_hours_bear[b]), Color.ORANGE);

#######################TWO HOUR CODE###########################
def cond1_2_2H = close_two_hours[2] < open_two_hours[2];
def cond2_2H = close_two_hours[1] > open_two_hours[1] and (high_two_hours[1] - low_two_hours[1]) > (high_two_hours[2] - low_two_hours[2]) * 2;
def cond3_2H = low_two_hours > high_two_hours[2] + .01;
def cond4_2H = if IsNaN(close_two_hours)
then cond4_2H[1]
else if cond1_2_2H && cond2_2H && cond3_2H
then high_two_hours[2]
else cond4_2H[1];
plot Two_Hours_bull = cond4_2H;
Two_Hours_bull.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Two_Hours_bull.SetDefaultColor(Color.LIGHT_GREEN);

def cond1_2_2Ha = close_two_hours[2] > open_two_hours[2];
def cond2_2Ha = close_two_hours[1] < open_two_hours[1] and (high_two_hours[1] - low_two_hours[1]) > (high_two_hours[2] - low_two_hours[2]) * 2;
def cond3_2Ha = high_two_hours < low_two_hours[2] - .01;
def cond4_2Ha = if IsNaN(close_two_hours)
then cond4_2Ha[1]
else if cond1_2_2Ha && cond2_2Ha && cond3_2Ha
then low_two_hours[2]
else cond4_2Ha[1];

plot Two_Hours_bear = cond4_2Ha;
Two_Hours_bear.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Two_Hours_bear.SetDefaultColor(Color.PINK);

AddChartBubble(Two_Hours_bull[b] <> Two_Hours_bull[b - 1], Two_Hours_bull[b], Concat("2H= $", Two_Hours_bull[b]), Color.ORANGE);
AddChartBubble(Two_Hours_bear[b] <> Two_Hours_bear[b - 1], Two_Hours_bear[b], Concat("2H = $", Two_Hours_bear[b]), Color.ORANGE);


#######################HOUR CODE###########################

def cond1H = close_hour[2] < open_hour[2];
def cond2H = close_hour[1] > open_hour[1] and (high_hour[1] - low_hour[1]) > (high_hour[2] - low_hour[2]) * 2;
def cond3H = low_hour > high_hour[2] + .01;
def cond4H = if IsNaN(close_hour)
then cond4H[1]
else if cond1H && cond2H && cond3H
then high_hour[2]
else cond4H[1];
plot Hour_bull = cond4H;
Hour_bull.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Hour_bull.SetDefaultColor(Color.LIGHT_GREEN);

def cond1Ha = close_hour[2] > open_hour[2];
def cond2Ha = close_hour[1] < open_hour[1] and (high_hour[1] - low_hour[1]) > (high_hour[2] - low_hour[2]) * 2;
def cond3Ha = high_hour < low_hour[2] - .01;
def cond4Ha = if IsNaN(close_hour)
then cond4Ha[1]
else if cond1Ha && cond2Ha && cond3Ha
then low_hour[2]
else cond4Ha[1];

plot Hour_bear = cond4Ha;
Hour_bear.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Hour_bear.SetDefaultColor(Color.PINK);

AddChartBubble(Hour_bull[b] <> Hour_bull[b - 1], Hour_bull[b], Concat("H= $", Hour_bull[b]), Color.ORANGE);
AddChartBubble(Hour_bear[b] <> Hour_bear[b - 1], Hour_bear[b], Concat("H = $", Hour_bear[b]), Color.ORANGE);

#######################30 MIN CODE###########################
def cond1_30M = close_thirty_min[2] < open_thirty_min[2];
def cond2_30M = close_thirty_min[1] > open_thirty_min[1] and (high_thirty_min[1] - low_thirty_min[1]) > (high_thirty_min[2] - low_thirty_min[2]) * 2;
def cond3_30M = low_thirty_min > high_thirty_min[2] + .01;
def cond4_30M = if IsNaN(close_thirty_min)
then cond4_30M[1]
else if cond1_30M && cond2_30M && cond3_30M
then high_thirty_min[2]
else cond4_30M[1];
plot Thirty_min_bull = cond4_30M;
Thirty_min_bull.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
#Thirty_min_bull.SetDefaultColor(Color.Light_green);

def cond1_30Ma = close_thirty_min[2] > open_thirty_min[2];
def cond2_30Ma = close_thirty_min[1] < open_thirty_min[1] and (high_thirty_min[1] - low_thirty_min[1]) > (high_thirty_min[2] - low_thirty_min[2]) * 2;
def cond3_30Ma = high_thirty_min < low_thirty_min[2] - .01;
def cond4_30Ma = if IsNaN(close_thirty_min)
then cond4_30M[1]
else if cond1_30Ma && cond2_30Ma && cond3_30Ma
then low_thirty_min[2]
else cond4_30Ma[1];

plot Thirty_min_bear = cond4_30Ma;
Thirty_min_bear.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
#Thirty_min_bear.SetDefaultColor(Color.Pink);

AddChartBubble(Thirty_min_bull[b] <> Thirty_min_bull[b - 1], Thirty_min_bull[b], Concat("30M= $", Thirty_min_bull[b]), Color.ORANGE);
AddChartBubble(Thirty_min_bear[b] <> Thirty_min_bear[b - 1], Thirty_min_bear[b], Concat("30M = $", Thirty_min_bear[b]), Color.ORANGE);

#######################15 MIN CODE###########################

def cond1_15M = close_fifteen_min[2] < open_fifteen_min[2];
def cond2_15M = close_fifteen_min[1] > open_fifteen_min[1] and (high_fifteen_min[1] - low_fifteen_min[1]) > (high_fifteen_min[2] - low_fifteen_min[2]) * 2;
def cond3_15M = low_fifteen_min > high_fifteen_min[2] + .01;
def cond4_15M = if IsNaN(close_fifteen_min)
then cond4_15M[1]
else if cond1_15M && cond2_15M && cond3_15M
then high_fifteen_min[2]
else cond4_15M[1];
plot Fifteen_min_bull = cond4_15M;
Fifteen_min_bull.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
#Fifteen_min_bull.SetDefaultColor(Color.Light_green);

def cond1_15Ma = close_fifteen_min[2] > open_fifteen_min[2];
def cond2_15Ma = close_fifteen_min[1] < open_fifteen_min[1] and (high_fifteen_min[1] - low_fifteen_min[1]) > (high_fifteen_min[2] - low_fifteen_min[2]) * 2;
def cond3_15Ma = high_fifteen_min < low_fifteen_min[2] - .01;
def cond4_15Ma = if IsNaN(close_fifteen_min)
then cond4_15M[1]
else if cond1_15Ma && cond2_15Ma && cond3_15Ma
then low_fifteen_min[2]
else cond4_15Ma[1];

plot Fifteen_min_bear = cond4_15Ma;
Fifteen_min_bear.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
#Fifteen_min_bear.SetDefaultColor(Color.Pink);

AddChartBubble(Fifteen_min_bull[b] <> Fifteen_min_bull[b - 1], Fifteen_min_bull[b], Concat("15M= $", Fifteen_min_bull[b]), Color.ORANGE);
AddChartBubble(Fifteen_min_bear[b] <> Fifteen_min_bear[b - 1], Fifteen_min_bear[b], Concat("15M = $", Fifteen_min_bear[b]), Color.ORANGE);
 
I'm not sure how to apply this here, but how could I get the bubbles to line up and move to the right like in this code...

https://usethinkscript.com/threads/moving-labels-away-from-current-time.12434/#post-106777

Here is another example than post #14. It is only the last plot of each bull/bear shown in the expanision

Capture.jpg
Ruby:
###############WEEK###############
def open_week;
def high_week;
def low_week;
def close_week;
def Volume_week;

if GetAggregationPeriod() <= AggregationPeriod.WEEK {
    open_week = open(period = AggregationPeriod.WEEK);
    high_week = high(period = AggregationPeriod.WEEK);
    low_week = low(period = AggregationPeriod.WEEK);
    close_week = close(period = AggregationPeriod.WEEK);
    Volume_week = volume(period = AggregationPeriod.WEEK);
} else {
    open_week = Double.NaN;
    high_week = Double.NaN;
    low_week = Double.NaN;
    close_week = Double.NaN;
    Volume_week = Double.NaN;
}

###############DAY###############

def open_day;
def high_day;
def low_day;
def close_day;
def Volume_day;

if GetAggregationPeriod() <= AggregationPeriod.DAY {
    open_day = open(period = AggregationPeriod.DAY);
    high_day = high(period = AggregationPeriod.DAY);
    low_day = low(period = AggregationPeriod.DAY);
    close_day = close(period = AggregationPeriod.DAY);
    Volume_day = volume(period = AggregationPeriod.DAY);
} else {
    open_day = Double.NaN;
    high_day = Double.NaN;
    low_day = Double.NaN;
    close_day = Double.NaN;
    Volume_day = Double.NaN;
}


###############4HR###############

def open_four_hours;
def high_four_hours;
def low_four_hours;
def close_four_hours;
def Volume_four_hours;

if GetAggregationPeriod() <= AggregationPeriod.FOUR_HOURS {
    open_four_hours = open(period = AggregationPeriod.FOUR_HOURS);
    high_four_hours = high(period = AggregationPeriod.FOUR_HOURS);
    low_four_hours = low(period = AggregationPeriod.FOUR_HOURS);
    close_four_hours = close(period = AggregationPeriod.FOUR_HOURS);
    Volume_four_hours = volume(period = AggregationPeriod.FOUR_HOURS);
} else {
    open_four_hours = Double.NaN;
    high_four_hours = Double.NaN;
    low_four_hours = Double.NaN;
    close_four_hours = Double.NaN;
    Volume_four_hours = Double.NaN;
}

###############2HR###############

def open_two_hours;
def high_two_hours;
def low_two_hours;
def close_two_hours;
def Volume_two_hours;

if GetAggregationPeriod() <= AggregationPeriod.TWO_HOURS {
    open_two_hours = open(period = AggregationPeriod.TWO_HOURS);
    high_two_hours = high(period = AggregationPeriod.TWO_HOURS);
    low_two_hours = low(period = AggregationPeriod.TWO_HOURS);
    close_two_hours = close(period = AggregationPeriod.TWO_HOURS);
    Volume_two_hours = volume(period = AggregationPeriod.TWO_HOURS);
} else {
    open_two_hours = Double.NaN;
    high_two_hours = Double.NaN;
    low_two_hours = Double.NaN;
    close_two_hours = Double.NaN;
    Volume_two_hours = Double.NaN;
}
###############1HR###############

def open_hour;
def high_hour;
def low_hour;
def close_hour;
def Volume_hour;

if GetAggregationPeriod() <= AggregationPeriod.HOUR {
    open_hour = open(period = AggregationPeriod.HOUR);
    high_hour = high(period = AggregationPeriod.HOUR);
    low_hour = low(period = AggregationPeriod.HOUR);
    close_hour = close(period = AggregationPeriod.HOUR);
    Volume_hour = volume(period = AggregationPeriod.HOUR);
} else {
    open_hour = Double.NaN;
    high_hour = Double.NaN;
    low_hour = Double.NaN;
    close_hour = Double.NaN;
    Volume_hour = Double.NaN;
}
###############30Min###############

def open_thirty_min;
def high_thirty_min;
def low_thirty_min;
def close_thirty_min;
def Volume_thirty_min;

if GetAggregationPeriod() <= AggregationPeriod.THIRTY_MIN {
    open_thirty_min = open(period = AggregationPeriod.THIRTY_MIN);
    high_thirty_min = high(period = AggregationPeriod.THIRTY_MIN);
    low_thirty_min = low(period = AggregationPeriod.THIRTY_MIN);
    close_thirty_min = close(period = AggregationPeriod.THIRTY_MIN);
    Volume_thirty_min = volume(period = AggregationPeriod.THIRTY_MIN);
} else {
    open_thirty_min = Double.NaN;
    high_thirty_min = Double.NaN;
    low_thirty_min = Double.NaN;
    close_thirty_min = Double.NaN;
    Volume_thirty_min = Double.NaN;
}

###############15Min###############

def open_fifteen_min;
def high_fifteen_min;
def low_fifteen_min;
def close_fifteen_min;
def Volume_fifteen_min;
if GetAggregationPeriod() <= AggregationPeriod.FIFTEEN_MIN {
    open_fifteen_min = open(period = AggregationPeriod.FIFTEEN_MIN);
    high_fifteen_min = high(period = AggregationPeriod.FIFTEEN_MIN);
    low_fifteen_min = low(period = AggregationPeriod.FIFTEEN_MIN);
    close_fifteen_min = close(period = AggregationPeriod.FIFTEEN_MIN);
    Volume_fifteen_min = volume(period = AggregationPeriod.FIFTEEN_MIN);
} else {
    open_fifteen_min = Double.NaN;
    high_fifteen_min = Double.NaN;
    low_fifteen_min = Double.NaN;
    close_fifteen_min = Double.NaN;
    Volume_fifteen_min = Double.NaN;
}

input bubblemover = 10;
def b  = bubblemover;
def b1 = b + 1;


########################WEEK CODE###########################

def cond1W = close_week[2] < open_week[2];
def cond2W = close_week[1] > open_week[1] and (high_week[1] - low_week[1]) > (high_week[2] - low_week[2]) * 2;
def cond3W = low_week > high_week[2] + .01;
def cond4W = if IsNaN(close)
then cond4W[1]
else if IsNaN(close_week)
then cond4W[1]
else if cond1W && cond2W && cond3W
then high_week[2]
else cond4W[1];
plot Week_bull = if !IsNaN(close) then Double.NaN else cond4W;
Week_bull.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Week_bull.SetDefaultColor(Color.LIGHT_GREEN);

def cond1Wa = close_week[2] > open_week[2];
def cond2Wa = close_week[1] < open_week[1] and (high_week[1] - low_week[1]) > (high_week[2] - low_week[2]) * 2;
def cond3Wa = high_week < low_week[2] - .01;
def cond4Wa = if IsNaN(close)
then cond4Wa[1]
else if IsNaN(close_week)
then cond4W[1]
else if cond1Wa && cond2Wa && cond3Wa
then low_week[2]
else cond4Wa[1];

plot Week_bear = if !IsNaN(close) then Double.NaN else cond4Wa;
Week_bear.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Week_bear.SetDefaultColor(Color.PINK);

AddChartBubble(!IsNaN(Week_bull[b]) and IsNaN(Week_bull[b1]), Week_bull, Concat("W= $", Week_bull), Color.ORANGE);

AddChartBubble(!IsNaN(Week_bear[b]) and IsNaN(Week_bear[b1]), Week_bear[b], Concat("W = $", Week_bear[b]), Color.ORANGE);

########################DAY CODE###########################
def cond1D = close_day[2] < open_day[2];
def cond2D = close_day[1] > open_day[1] and (high_day[1] - low_day[1]) > (high_day[2] - low_day[2]) * 2;
def cond3D = low_day > high_day[2] + .01;
def cond4D = if IsNaN(close_day)
then cond4D[1]
else if cond1D && cond2D && cond3D
then high_day[2]
else cond4D[1];
plot Day_bull = if !IsNaN(close) then Double.NaN else cond4D;
Day_bull.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Day_bull.SetDefaultColor(Color.LIGHT_GREEN);

def cond1Da = close_day[2] > open_day[2];
def cond2Da = close_day[1] < open_day[1] and (high_day[1] - low_day[1]) > (high_day[2] - low_day[2]) * 2;
def cond3Da = high_day < low_day[2] - .01;
def cond4Da = if IsNaN(close_day)
then cond4Da[1]
else if cond1Da && cond2Da && cond3Da
then low_day[2]
else cond4Da[1];

plot Day_bear = if !IsNaN(close) then Double.NaN else cond4Da;
Day_bear.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Day_bear.SetDefaultColor(Color.PINK);


AddChartBubble(!IsNaN(Day_bull[b]) and IsNaN(Day_bull[b1]), Day_bull[b], Concat("D= $", Day_bull[b]), Color.ORANGE);
AddChartBubble(!IsNaN(Day_bear[b]) and IsNaN(Day_bear[b1]), Day_bear[b], Concat("D = $", Day_bear[b]), Color.ORANGE);

#######################FOUR HOUR CODE###########################
def cond1_4H = close_four_hours[2] < open_four_hours[2];
def cond2_4H = close_four_hours[1] > open_four_hours[1] and (high_four_hours[1] - low_four_hours[1]) > (high_four_hours[2] - low_four_hours[2]) * 2;
def cond3_4H = low_four_hours > high_four_hours[2] + .01;
def cond4_4H = if IsNaN(close)
then cond4_4H[1]
else if IsNaN(close_four_hours)
then cond4_4H[1]
else if cond1_4H && cond2_4H && cond3_4H
then high_four_hours[2]
else cond4_4H[1];
plot Four_hours_bull = if !IsNaN(close) then Double.NaN else cond4_4H;
Four_hours_bull.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Four_hours_bull.SetDefaultColor(Color.LIGHT_GREEN);

def cond1_4Ha = close_four_hours[2] > open_four_hours[2];
def cond2_4Ha = close_four_hours[1] < open_four_hours[1] and (high_four_hours[1] - low_four_hours[1]) > (high_four_hours[2] - low_four_hours[2]) * 2;
def cond3_4Ha = high_four_hours < low_four_hours[2] - .01;
def cond4_4Ha = if IsNaN(close)
then cond4_4Ha[1]
else if IsNaN(close_four_hours)
then cond4_4H[1]
else if cond1_4Ha && cond2_4Ha && cond3_4Ha
then low_four_hours[2]
else cond4_4Ha[1];

plot Four_hours_bear = if !IsNaN(close) then Double.NaN else cond4_4Ha;
Four_hours_bear.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Four_hours_bear.SetDefaultColor(Color.PINK);


AddChartBubble(!IsNaN(Four_hours_bull[b]) and IsNaN(Four_hours_bull[b1]) , Four_hours_bull[b], Concat("4H= $", Four_hours_bull[b]), Color.ORANGE);
AddChartBubble(!IsNaN(Four_hours_bear[b]) and IsNaN(Four_hours_bear[b1]), Four_hours_bear[b], Concat("4H = $", Four_hours_bear[b]), Color.ORANGE);

#######################TWO HOUR CODE###########################
def cond1_2_2H = close_two_hours[2] < open_two_hours[2];
def cond2_2H = close_two_hours[1] > open_two_hours[1] and (high_two_hours[1] - low_two_hours[1]) > (high_two_hours[2] - low_two_hours[2]) * 2;
def cond3_2H = low_two_hours > high_two_hours[2] + .01;
def cond4_2H = if IsNaN(close)
then cond4_2H[1]
else if IsNaN(close_two_hours)
then cond4_2H[1]
else if cond1_2_2H && cond2_2H && cond3_2H
then high_two_hours[2]
else cond4_2H[1];
plot Two_Hours_bull = if !IsNaN(close) then Double.NaN else cond4_2H;
Two_Hours_bull.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Two_Hours_bull.SetDefaultColor(Color.LIGHT_GREEN);

def cond1_2_2Ha = close_two_hours[2] > open_two_hours[2];
def cond2_2Ha = close_two_hours[1] < open_two_hours[1] and (high_two_hours[1] - low_two_hours[1]) > (high_two_hours[2] - low_two_hours[2]) * 2;
def cond3_2Ha = high_two_hours < low_two_hours[2] - .01;
def cond4_2Ha = if IsNaN(close)
then cond4_2Ha[1]
else if IsNaN(close_two_hours)
then cond4_2Ha[1]
else if cond1_2_2Ha && cond2_2Ha && cond3_2Ha
then low_two_hours[2]
else cond4_2Ha[1];

plot Two_Hours_bear = if !IsNaN(close) then Double.NaN else cond4_2Ha;
Two_Hours_bear.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Two_Hours_bear.SetDefaultColor(Color.PINK);

AddChartBubble(!IsNaN(Two_Hours_bull[b]) and IsNaN(Two_Hours_bull[b1]), Two_Hours_bull[b], Concat("2H= $", Two_Hours_bull[b]), Color.ORANGE);
AddChartBubble(!IsNaN(Two_Hours_bear[b]) and IsNaN(Two_Hours_bear[b1]), Two_Hours_bear[b], Concat("2H = $", Two_Hours_bear[b]), Color.ORANGE);


#######################HOUR CODE###########################

def cond1H = close_hour[2] < open_hour[2];
def cond2H = close_hour[1] > open_hour[1] and (high_hour[1] - low_hour[1]) > (high_hour[2] - low_hour[2]) * 2;
def cond3H = low_hour > high_hour[2] + .01;
def cond4H = if IsNaN(close)
then cond4H[1]
else if IsNaN(close_hour)
then cond4H[1]
else if cond1H && cond2H && cond3H
then high_hour[2]
else cond4H[1];
plot Hour_bull = if !IsNaN(close) then Double.NaN else cond4H;
Hour_bull.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Hour_bull.SetDefaultColor(Color.LIGHT_GREEN);

def cond1Ha = close_hour[2] > open_hour[2];
def cond2Ha = close_hour[1] < open_hour[1] and (high_hour[1] - low_hour[1]) > (high_hour[2] - low_hour[2]) * 2;
def cond3Ha = high_hour < low_hour[2] - .01;
def cond4Ha = if IsNaN(close)
then cond4Ha[1]
else if IsNaN(close_hour)
then cond4Ha[1]
else if cond1Ha && cond2Ha && cond3Ha
then low_hour[2]
else cond4Ha[1];

plot Hour_bear = if !IsNaN(close) then Double.NaN else cond4Ha;
Hour_bear.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Hour_bear.SetDefaultColor(Color.PINK);

AddChartBubble(!IsNaN(Hour_bull[b]) and IsNaN(Hour_bull[b1]), Hour_bull[b], Concat("H= $", Hour_bull[b]), Color.ORANGE);
AddChartBubble(!IsNaN(Hour_bear[b]) and IsNaN(Hour_bear[b1]), Hour_bear[b], Concat("H = $", Hour_bear[b]), Color.ORANGE);

#######################30 MIN CODE###########################
def cond1_30M = close_thirty_min[2] < open_thirty_min[2];
def cond2_30M = close_thirty_min[1] > open_thirty_min[1] and (high_thirty_min[1] - low_thirty_min[1]) > (high_thirty_min[2] - low_thirty_min[2]) * 2;
def cond3_30M = low_thirty_min > high_thirty_min[2] + .01;
def cond4_30M = if IsNaN(close)
then cond4_30M[1]
else if IsNaN(close_thirty_min)
then cond4_30M[1]
else if cond1_30M && cond2_30M && cond3_30M
then high_thirty_min[2]
else cond4_30M[1];
plot Thirty_min_bull = if !IsNaN(close) then Double.NaN else cond4_30M;
Thirty_min_bull.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
#Thirty_min_bull.SetDefaultColor(Color.Light_green);

def cond1_30Ma = close_thirty_min[2] > open_thirty_min[2];
def cond2_30Ma = close_thirty_min[1] < open_thirty_min[1] and (high_thirty_min[1] - low_thirty_min[1]) > (high_thirty_min[2] - low_thirty_min[2]) * 2;
def cond3_30Ma = high_thirty_min < low_thirty_min[2] - .01;
def cond4_30Ma = if IsNaN(close)
then cond4_30Ma[1]
else if IsNaN(close_thirty_min)
then cond4_30M[1]
else if cond1_30Ma && cond2_30Ma && cond3_30Ma
then low_thirty_min[2]
else cond4_30Ma[1];

plot Thirty_min_bear = if !IsNaN(close) then Double.NaN else cond4_30Ma;
Thirty_min_bear.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
#Thirty_min_bear.SetDefaultColor(Color.Pink);

AddChartBubble(!IsNaN(Thirty_min_bull[b]) and IsNaN(Thirty_min_bull[b1]), Thirty_min_bull[b], Concat("30M= $", Thirty_min_bull[b]), Color.ORANGE);
AddChartBubble(!IsNaN(Thirty_min_bear[b]) and IsNaN(Thirty_min_bear[b1]), Thirty_min_bear[b], Concat("30M = $", Thirty_min_bear[b]), Color.ORANGE);

#######################15 MIN CODE###########################

def cond1_15M = close_fifteen_min[2] < open_fifteen_min[2];
def cond2_15M = close_fifteen_min[1] > open_fifteen_min[1] and (high_fifteen_min[1] - low_fifteen_min[1]) > (high_fifteen_min[2] - low_fifteen_min[2]) * 2;
def cond3_15M = low_fifteen_min > high_fifteen_min[2] + .01;
def cond4_15M = if IsNaN(close)
then cond4_15M[1]
else if IsNaN(close_fifteen_min)
then cond4_15M[1]
else if cond1_15M && cond2_15M && cond3_15M
then high_fifteen_min[2]
else cond4_15M[1];
plot Fifteen_min_bull = if !IsNaN(close) then Double.NaN else cond4_15M;
Fifteen_min_bull.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
#Fifteen_min_bull.SetDefaultColor(Color.Light_green);

def cond1_15Ma = close_fifteen_min[2] > open_fifteen_min[2];
def cond2_15Ma = close_fifteen_min[1] < open_fifteen_min[1] and (high_fifteen_min[1] - low_fifteen_min[1]) > (high_fifteen_min[2] - low_fifteen_min[2]) * 2;
def cond3_15Ma = high_fifteen_min < low_fifteen_min[2] - .01;
def cond4_15Ma = if IsNaN(close)
then cond4_15Ma[1]
else if IsNaN(close_fifteen_min)
then cond4_15M[1]
else if cond1_15Ma && cond2_15Ma && cond3_15Ma
then low_fifteen_min[2]
else cond4_15Ma[1];

plot Fifteen_min_bear = if !IsNaN(close) then Double.NaN else cond4_15Ma;
Fifteen_min_bear.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
#Fifteen_min_bear.SetDefaultColor(Color.Pink);

AddChartBubble(!IsNaN(Fifteen_min_bull[b]) and IsNaN(Fifteen_min_bull[b1]), Fifteen_min_bull[b], Concat("15M= $", Fifteen_min_bull[b]), Color.ORANGE);
AddChartBubble(!IsNaN(Fifteen_min_bear[b]) and IsNaN(Fifteen_min_bear[b1]), Fifteen_min_bear[b], Concat("15M = $", Fifteen_min_bear[b]), Color.ORANGE);
 
Been looking for this!
1.Is it possible to take out the 1 penny and just make it any amount? meaning if there is any gap between the first candles high and the third candles low (Bullish) or vice versa 1st candles low third candles High
2. Can you make the first bar indiscriminate either bull bear or doji just as long as long as there's a gap.
3. Can the line be changed to a cloud that closes when it comes in contact with price?

appreciated!

Sorry, I started this and realized I wasn't sure how you used this code, but it looks like as support/resistance. So when you wanted to stop the plot of a line when contact is made, that would mean each of those plots would have to be identified with their own plots each time there was a change in condition, extended to go all the way to the right, and ended when contact is made. That would be a lot of coding.

I did something similar to profile pocs posted here https://usethinkscript.com/threads/extend-point-of-control-line-volume-profile.10893/post-106420. This was very resource intensive to run on TOS.
 
Sorry, I started this and realized I wasn't sure how you used this code, but it looks like as support/resistance. So when you wanted to stop the plot of a line when contact is made, that would mean each of those plots would have to be identified with their own plots each time there was a change in condition, extended to go all the way to the right, and ended when contact is made. That would be a lot of coding.

I did something similar to profile pocs posted here https://usethinkscript.com/threads/extend-point-of-control-line-volume-profile.10893/post-106420. This was very resource intensive to run on TOS.
No worries, you've been an incredible help as always. I wouldn't describe this as a support resistance code but more so an areas of interest based off of previous data. It helps me decided if/when I should be and where I should place my target and stop loss. As you can see in the screenshot attached there was a huge candle around 11am. From that time forward the market reversed each time it reaches the area.



I understand that it would be too much coding to extend the lines until cross on the MTF version of the code, but could it be done for the non-mtf version below? Thanks in advance!




Input ShowChartBubble = no;
Input ShowPriceBubble = no;
input ShowLabels = no;
input ShowArrows = no;
#input bubblemover = 4;
#def b = bubblemover;

#A) Bullish move:
#• Three candles
#First candle is red
#Second is green and at least twice the size of the first candle
#Third candle low that is at least a penny greater than the high of the first candle

#This code should plot a horizontal line at the high of the first candle that extends all the way to the left of the chart until it's crossed.

def cond1 = close[2] < open[2];
def cond2 = close[1] > open[1] and (high[1] - low[1]) > (high[2] - low[2]) * 2;
def cond3 = low > high[2] + .01;
def cond4 = if isnan(close)
then cond4[1]
else if cond1 && cond2 && cond3
then high[2]
else cond4[1];
plot bull = cond4;
bull.setpaintingStrategy(paintingStrategy.HORIZONTAL);
bull.SetDefaultColor(Color.Light_green);

def cond1a = close[2] > open[2];
def cond2a = close[1] < open[1] and (high[1] - low[1]) > (high[2] - low[2]) * 2;
def cond3a = high < low[2] - .01;
def cond4a = if isnan(close)
then cond4[1]
else if cond1a && cond2a && cond3a
then low[2]
else cond4a[1];

plot bear = cond4a;
bear.setpaintingStrategy(paintingStrategy.HORIZONTAL);
bear.SetDefaultColor(Color.light_red);
 
What did you do to the code to only have the most recent line show?

1) This isnan(close) portion of the following code is what extended the lines, which would likely be the last without the need for coding.
2) Also, there was a fix to the cond4 reference in the cond4a code, which is easy to occur when copying one part of the code to another.
3) So this code does the last line extension for both of the plots .

Code:
def cond4a = if isnan(close)
then cond4a[1]
else if cond1a && cond2a && cond3a
then low[2]
else cond4a[1];
Here are the last 3 bull/bear conditions extended to the right with bubbles. I am leaving it to you to do as many as you would like by using the logic in the code below to do the plots and bubbles using the script function c3()

Capture.jpg
Ruby:
script c3 {
input condplot = 0;
Input ShowChartBubble = no;
Input ShowPriceBubble = no;
input ShowLabels = no;
input ShowArrows = no;
#input bubblemover = 4;
#def b = bubblemover;

#A) Bullish move:
#• Three candles
#First candle is red
#Second is green and at least twice the size of the first candle
#Third candle low that is at least a penny greater than the high of the first candle

#This code should plot a horizontal line at the high of the first candle that extends all the way to the left of the chart until it's crossed.

#Bull
def cond1 = close[2] < open[2];
def cond2 = close[1] > open[1] and (high[1] - low[1]) > (high[2] - low[2]) * 2;
def cond3 = low > high[2] + .01;
def cond4 = if isnan(close)
then cond4[1]
else if cond1 && cond2 && cond3
then high[2]
else cond4[1];

def bullcond =  cond4;
def candles  = !IsNaN(close);
def capture  = bullcond != bullcond[1];
def dayCount = CompoundValue(1, if capture then dayCount[1] + 1 else dayCount[1], 0);
def thisDay  = (HighestAll(dayCount)- dayCount) ;

def bullext = if isnan(close) then bullext[1] else if thisday==condplot then cond4 else bullext[1];

plot bull = if thisday < condplot + 1 then  bullext else double.nan;
bull.setpaintingStrategy(paintingStrategy.HORIZONTAL);
bull.SetDefaultColor(Color.Light_green);

#Bear
def cond1a = close[2] > open[2];
def cond2a = close[1] < open[1] and (high[1] - low[1]) > (high[2] - low[2]) * 2;
def cond3a = high < low[2] - .01;
def cond4a = if isnan(close)
then cond4a[1]
else if cond1a && cond2a && cond3a
then low[2]
else cond4a[1];

def bearcond =  cond4a;
def candles1 = !IsNaN(close);
def capture1 = bearcond != bearcond[1];
def dayCount1= CompoundValue(1, if capture1 then dayCount1[1] + 1 else dayCount1[1], 0);
def thisDay1  = (HighestAll(dayCount1)- dayCount1) ;

def bearext = if isnan(close) then bearext[1] else if thisday1==condplot then cond4a else bearext[1];

plot bear = if thisday < condplot + 1 then  bearext else double.nan;
bear.setpaintingStrategy(paintingStrategy.HORIZONTAL);
bear.SetDefaultColor(Color.light_red);
}

#Bull Plots

plot bull0 = c3(0).bull;
bull0.setpaintingStrategy(paintingStrategy.HORIZONTAL);
bull0.SetDefaultColor(Color.Light_green);

plot bull1 = c3(1).bull;
bull1.setpaintingStrategy(paintingStrategy.HORIZONTAL);
bull1.SetDefaultColor(Color.Light_green);

plot bull2 = c3(2).bull;
bull2.setpaintingStrategy(paintingStrategy.HORIZONTAL);
bull2.SetDefaultColor(Color.Light_green);

#Bear Plots

plot bear0 = c3(0).bear;
bear0.setpaintingStrategy(paintingStrategy.HORIZONTAL);
bear0.SetDefaultColor(Color.light_red);

plot bear1 = c3(1).bear;
bear1.setpaintingStrategy(paintingStrategy.HORIZONTAL);
bear1.SetDefaultColor(Color.light_red);

plot bear2 = c3(2).bear;
bear2.setpaintingStrategy(paintingStrategy.HORIZONTAL);
bear2.SetDefaultColor(Color.light_red);

input bubblemover = 3;
def b=bubblemover;
def b1=b+1;

#Bull Bubbles

addchartBubble(!isnan(close[b1]) and isnan(close[b]) and bull0[b],bull0[b1], 0, bull0.takevalueColor());
addchartBubble(!isnan(close[b1]) and isnan(close[b]) and bull1[b],bull1[b1], 1, bull1.takevalueColor());
addchartBubble(!isnan(close[b1]) and isnan(close[b]) and bull2[b],bull2[b1], 2, bull2.takevalueColor());

#Bear Bubbles
addchartBubble(!isnan(close[b1]) and isnan(close[b]) and bear0[b],bear0[b1], 0, bear0.takevalueColor());
addchartBubble(!isnan(close[b1]) and isnan(close[b]) and bear1[b],bear1[b1], 1, bear1.takevalueColor());
addchartBubble(!isnan(close[b1]) and isnan(close[b]) and bear2[b],bear2[b1], 2, bear2.takevalueColor());
 
Thanks again for all the help coding. I do have another [hopefully simple] request. I'm looking for a label to show only if the bear or bull condition is true for the current trading day. Ideally, I'd like the label to also show the price when the condition is met. Thanks in advance...

AddLabel(Showlabels, "Bulls: " + Concat (cond4, 0), color.uptick);
AddLabel(Showlabels, "Bears: " + Concat (cond4a, 0), color.downtick);
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
173 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