songvicobac
New member
Does anyone know how to display let say yesterday close ,draw a line and bubble say yesterday high on the right edge?
Thanks
Thanks
# Plot yesterday's high / low with chart bubbles
input aggregationPeriod = AggregationPeriod.DAY;
def open = open(period = aggregationPeriod);
def high = high(period = aggregationPeriod);
def low = low(period = aggregationPeriod);
plot h1 = high(period = aggregationPeriod)[1];
plot l1 = low(period = aggregationPeriod)[1];
input showBubble = yes;
def SR = showBubble and !IsNaN(close) and IsNaN(close [-1] ) && HighestAll(BarNumber());
AddChartBubble(SR, h1, "PrevHi", Color.Dark_Orange);
AddChartBubble(SR, l1, "PrevLo", Color.Dark_Orange);
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
def limit = !IsNaN(close) and IsNaN(close [-1] ) && HighestAll(BarNumber());
AddChartBubble(limit, pLevel1, "L1: " +pLevel1, color.DARK_ORANGE);
# plots a bubble, x bars after last bar,
# at a price level equal to the last bar close
input bars_in_future = 3;
def bif = bars_in_future;
def x = !IsNaN(close[bif]) and IsNaN(close[bif - 1]);
def vert = close[bif];
input show_bubble = yes;
AddChartBubble(show_bubble and x, vert,
"Draw a bubble\n" +
bif + " bars\n" +
"after the last bar,\n" +
"at a price equal to the\n" +
"last bar close\n" + vert
, Color.WHITE, yes);
#
This is exactly i am looking for Bubble after last bar, thanks a ton @halcyonguynot sure what you are trying to do, your words say 2 different things, and the code is different from both.
the limit formula is identifying the last bar.
do you want bubbles to be displayed to the right of the last bar? ( off to the right)
here is a code to place a bubble x bars after the last bar
Ruby:# plots a bubble x bars after last bar input bars_in_future = 3; def bif = bars_in_future; def cls = close; def x = isNaN(cls[bif]) and !isNaN(cls[bif+1]); def vert = cls[bif+1]; input show = yes; AddChartBubble(show and x, vert, vert, color.white, yes);
Hi halcyonguy, question. I am doing something similar in that I'm trying to addchartbubble for pivot high and pivot low for multiple timeframe on a single chart (ie, pivots for 30, 60, 4-HR, D will show on the 30 minute chart). Is your code looking at the last pivot high and using that as the starting point for the bars_in_the_future? When I insert your code, it works good for the more recent pivot H/L bubbles but if, for example, the 4Hr pivot H was a few days ago, the bubble is way back a few days ago. Is there any way to force the chart bubbles to always display near the right side of the chart? I'll paste a screenshot of how it looks.not sure what you are trying to do, your words say 2 different things, and the code is different from both.
the limit formula is identifying the last bar.
do you want bubbles to be displayed to the right of the last bar? ( off to the right)
here is a code to place a bubble x bars after the last bar
Ruby:# plots a bubble x bars after last bar input bars_in_future = 3; def bif = bars_in_future; def cls = close; def x = isNaN(cls[bif]) and !isNaN(cls[bif+1]); def vert = cls[bif+1]; input show = yes; AddChartBubble(show and x, vert, vert, color.white, yes);
def ThirtyMinAgg = AggregationPeriod.thirty_MIN;
def High_30 = high(period = ThirtyMinAgg);
def Low_30 = low(period = ThirtyMinAgg);
def Open_30 = open(period = ThirtyMinAgg);
def Close_30 = close(period = ThirtyMinAgg);
def labelyes = open > 0;
def LookbackPeriod_30 = 8;
def FirstBar_30 = BarNumber();
def Highest_30 = fold i_30 = 1
to LookbackPeriod_30 + 1
with p_30 = 1
while p_30
do High_30 > GetValue(High_30, -i_30);
def A_30 = if (FirstBar_30 > LookbackPeriod_30
and High_30 == Highest(High_30, LookbackPeriod_30)
and Highest_30)
then High_30
else Double.NaN;
def Lowest_30 = fold j_30 = 1
to LookbackPeriod_30 + 1
with q_30 = 1
while q_30
do Low_30 < GetValue(Low_30, -j_30);
def B_30 = if (FirstBar_30 > LookbackPeriod_30
and Low_30 == Lowest(Low_30, LookbackPeriod_30)
and Lowest_30)
then Low_30
else Double.NaN;
#--------------------------------------------------------------
def _highInPeriod_30 = Highest(High_30, LookbackPeriod_30);
def _lowInPeriod_30 = Lowest(Low_30, LookbackPeriod_30);
#--------------------------------------------------------------
def marketLow_30 = if _lowInPeriod_30 < _lowInPeriod_30[-LookbackPeriod_30] then _lowInPeriod_30 else _lowInPeriod_30[-LookbackPeriod_30];
def _markedLow_30 = Low_30 == marketLow_30;
rec _lastMarkedLow_30 = CompoundValue(1, if IsNaN(_markedLow_30) then _lastMarkedLow_30[1] else if _markedLow_30 then Low_30 else _lastMarkedLow_30[1], Low_30);
#--------------------------------------------------------------
def marketHigh_30 = if _highInPeriod_30 > _highInPeriod_30[-LookbackPeriod_30] then _highInPeriod_30 else _highInPeriod_30[-LookbackPeriod_30];
def _markedHigh_30 = High_30 == marketHigh_30;
rec _lastMarkedHigh_30 = CompoundValue(1, if IsNaN(_markedHigh_30) then _lastMarkedHigh_30[1] else if _markedHigh_30 then High_30 else _lastMarkedHigh_30[1], High_30);
#--------------------------------------------------------------
plot Resistance_30 = _lastMarkedHigh_30;
plot Support_30 = _lastMarkedLow_30;
plot price_30 = if(resistance_30 > 0, resistance_30, double.nan);
#plot isbtw = close > Resistance_30* NearPctLow_30 and close < Resistance_30* NearPctHigh_30 or close > Support_30 * NearPctLow_30 and close < Support_30 * NearPctHigh_30 ;
def lower_close_30 = (SMA crosses below Support_30[1]);
def higher_close_30 = (SMA crosses above Resistance_30[1]);
#---------------------------------------
def ph_30 = Round(A_30, 2);
def pl_30 = Round(B_30, 2);
#--------------------------------------------------------------
Resistance_30.SetPaintingStrategy(PaintingStrategy.DASHES);
Resistance_30.SetDefaultColor(Color.GREEN);
# plots a bubble x bars after last bar
input bars_in_future_30 = 15;
def bif_30 = bars_in_future_30;
def PivHigh_30 = GetValue(ph_30,0);
def x_30 = IsNaN(Ph_30[bif_30]) and !IsNaN(Ph_30[bif_30 + 1]);
def vertH_30 = Ph_30[bif_30 + 1];
input show = yes;
AddChartBubble(show and x_30, vertH_30, "30", Color.white, yes);
#--------------------------------------------------------------
Support_30.SetPaintingStrategy(PaintingStrategy.DASHES);
Support_30.SetDefaultColor(Color.RED);
# plots a bubble x bars after last bar
def PivLow_30 = getvalue(pl_30,0);
def y_30 = IsNaN(Pl_30[bif_30]) and !IsNaN(Pl_30[bif_30 + 1]);
def vertL_30 = Pl_30[bif_30 + 1];
AddChartBubble(show and y_30, vertL_30, "30", Color.white, yes);
################################
def OneHrAgg = AggregationPeriod.HOUR;
def High_Hr = high(period = OneHrAgg);
def Low_Hr = low(period = OneHrAgg);
def Open_Hr = open(period = OneHrAgg);
def Close_Hr = close(period = OneHrAgg);
def LookbackPeriod_HR = 8;
def FirstBar_HR = BarNumber();
def Highest_HR = fold i_HR = 1
to LookbackPeriod_HR + 1
with p_HR = 1
while p_HR
do High_Hr > GetValue(High_Hr, -i_HR);
def A_HR = if (FirstBar_HR > LookbackPeriod_HR
and High_Hr == Highest(High_Hr, LookbackPeriod_HR)
and Highest_HR)
then High_Hr
else Double.NaN;
def Lowest_HR = fold j_HR = 1
to LookbackPeriod_HR + 1
with q_HR = 1
while q_HR
do Low_Hr < GetValue(Low_Hr, -j_HR);
def B_HR = if (FirstBar_HR > LookbackPeriod_HR
and Low_Hr == Lowest(Low_Hr, LookbackPeriod_HR)
and Lowest_HR)
then Low_Hr
else Double.NaN;
#--------------------------------------------------------------
def _highInPeriod_HR = Highest(High_Hr, LookbackPeriod_HR);
def _lowInPeriod_HR = Lowest(Low_Hr, LookbackPeriod_Hr);
#--------------------------------------------------------------
def marketLow_HR = if _lowInPeriod_HR < _lowInPeriod_HR[-LookbackPeriod_HR] then _lowInPeriod_HR else _lowInPeriod_HR[-LookbackPeriod_HR];
def _markedLow_HR = Low_Hr == marketLow_HR;
rec _lastMarkedLow_HR = CompoundValue(1, if IsNaN(_markedLow_HR) then _lastMarkedLow_HR[1] else if _markedLow_HR then Low_Hr else _lastMarkedLow_HR[1], Low_Hr);
#--------------------------------------------------------------
def marketHigh_HR = if _highInPeriod_HR > _highInPeriod_HR[-LookbackPeriod_HR] then _highInPeriod_HR else _highInPeriod_HR[-LookbackPeriod_HR];
def _markedHigh_HR = High_Hr == marketHigh_HR;
rec _lastMarkedHigh_HR = CompoundValue(1, if IsNaN(_markedHigh_HR) then _lastMarkedHigh_HR[1] else if _markedHigh_HR then High_Hr else _lastMarkedHigh_HR[1], High_Hr);
#--------------------------------------------------------------
plot Resistance_HR = _lastMarkedHigh_HR;
plot Support_HR = _lastMarkedLow_HR;
#plot isbtw = close > Resistance_HR* NearPctLow_HR and close < Resistance_HR* NearPctHigh_HR or close > Support_HR * NearPctLow_HR and close < Support_HR * NearPctHigh_HR ;
def lower_close_HR = (SMA crosses below Support_HR[1]);
def higher_close_HR = (SMA crosses above Resistance_HR[1]);
#---------------------------------------
def ph_HR = Round(A_HR, 2);
def pl_HR = Round(B_HR, 2);
#--------------------------------------------------------------
Resistance_HR.SetPaintingStrategy(PaintingStrategy.DASHES);
Resistance_HR.SetDefaultColor(Color.GREEN);
# plots a bubble x bars after last bar
input bars_in_future_HR = 11;
def bif_HR = bars_in_future_HR;
def PivHigh_Hr = GetValue(ph_HR,0);
def x_HR = IsNaN(Ph_Hr[bif_HR]) and !IsNaN(Ph_Hr[bif_HR + 1]);
def vertH_HR = Ph_Hr[bif_HR + 1];
AddChartBubble(show and x_HR, vertH_Hr, "HR", Color.WHITE, yes);
#--------------------------------------------------------------
Support_HR.SetPaintingStrategy(PaintingStrategy.DASHES);
Support_HR.SetDefaultColor(Color.RED);
# plots a bubble x bars after last bar
def PivLow_Hr = getvalue(pl_HR,0);
def y_HR = IsNaN(Pl_Hr[bif_HR]) and !IsNaN(Pl_Hr[bif_HR + 1]);
def vertL_HR = Pl_Hr[bif_HR + 1];
AddChartBubble(show and y_HR, vertL_HR, "HR", Color.WHITE, yes);
################################
def FourHrAgg = AggregationPeriod.FOUR_HOURS;
def High_4HR = high(period = FourHrAgg);
def Low_4HR = low(period = FourHrAgg);
def Open_4HR = open(period = FourHrAgg);
def Close_4HR = close(period = FourHrAgg);
def LookbackPeriod_4HR = 8;
def FirstBar_4HR = BarNumber();
def Highest_4HR = fold i_4HR = 1
to LookbackPeriod_4HR + 1
with p_4HR = 1
while p_4HR
do High_4HR > GetValue(High_4HR, -i_4HR);
def A_4HR = if (FirstBar_4HR > LookbackPeriod_4HR
and High_4HR == Highest(High_4HR, LookbackPeriod_4HR)
and Highest_4HR)
then High_4HR
else Double.NaN;
def Lowest_4HR = fold j_4HR = 1
to LookbackPeriod_4HR + 1
with q_4HR = 1
while q_4HR
do Low_4HR < GetValue(Low_4HR, -j_4HR);
def B_4HR = if (FirstBar_4HR > LookbackPeriod_4HR
and Low_4HR == Lowest(Low_4HR, LookbackPeriod_4HR)
and Lowest_4HR)
then Low_4HR
else Double.NaN;
#--------------------------------------------------------------
def _highInPeriod_4HR = Highest(High_4HR, LookbackPeriod_4HR);
def _lowInPeriod_4HR = Lowest(Low_4HR, LookbackPeriod_4HR);
#--------------------------------------------------------------
def marketLow_4HR = if _lowInPeriod_4HR < _lowInPeriod_4HR[-LookbackPeriod_4HR] then _lowInPeriod_4HR else _lowInPeriod_4HR[-LookbackPeriod_4HR];
def _markedLow_4HR = Low_4HR == marketLow_4HR;
rec _lastMarkedLow_4HR = CompoundValue(1, if IsNaN(_markedLow_4HR) then _lastMarkedLow_4HR[1] else if _markedLow_4HR then Low_4HR else _lastMarkedLow_4HR[1], Low_4HR);
#--------------------------------------------------------------
def marketHigh_4HR = if _highInPeriod_4HR > _highInPeriod_4HR[-LookbackPeriod_4HR] then _highInPeriod_4HR else _highInPeriod_4HR[-LookbackPeriod_4HR];
def _markedHigh_4HR = High_4HR == marketHigh_4HR;
rec _lastMarkedHigh_4HR = CompoundValue(1, if IsNaN(_markedHigh_4HR) then _lastMarkedHigh_4HR[1] else if _markedHigh_4HR then High_4HR else _lastMarkedHigh_4HR[1], High_4HR);
#--------------------------------------------------------------
plot Resistance_4HR = _lastMarkedHigh_4HR;
plot Support_4HR = _lastMarkedLow_4HR;
#plot price_4HR = if(resistance_4HR > 0, resistance_4HR, double.nan);
#plot isbtw = close > Resistance_4HR* NearPctLow_4HR and close < Resistance_4HR* NearPctHigh_4HR or close > Support_4HR * NearPctLow_4HR and close < Support_4HR * NearPctHigh_4HR ;
def lower_close_4HR = (SMA crosses below Support_4HR[1]);
def higher_close_4HR = (SMA crosses above Resistance_4HR[1]);
#---------------------------------------
def ph_4HR = Round(A_4HR, 2);
def pl_4HR = Round(B_4HR, 2);
#--------------------------------------------------------------
Resistance_4HR.SetPaintingStrategy(PaintingStrategy.DASHES);
Resistance_4HR.SetDefaultColor(Color.GREEN);
# plots a bubble x bars after last bar
input bars_in_future_4HR = 7;
def bif_4HR = bars_in_future_4HR;
def PivHigh_4HR = GetValue(ph_4HR,0);
def x_4HR = IsNaN(Ph_4HR[bif_4HR]) and !IsNaN(Ph_4HR[bif_4HR + 1]);
def vertH_4HR = Ph_4HR[bif_4HR + 1];
AddChartBubble(show and x_4HR, vertH_4HR, "4", Color.WHITE, yes);
#--------------------------------------------------------------
Support_4HR.SetPaintingStrategy(PaintingStrategy.DASHES);
Support_4HR.SetDefaultColor(Color.RED);
# plots a bubble x bars after last bar
def PivLow_4HR = getvalue(pl_4HR,0);
def y_4HR = IsNaN(Pl_4HR[bif_4HR]) and !IsNaN(Pl_4HR[bif_4HR + 1]);
def vertL_4HR = Pl_4HR[bif_4HR + 1];
AddChartBubble(show and y_4HR, vertL_4HR, "4", Color.WHITE, yes);
################################
def DayAgg = AggregationPeriod.Day;
def High_D = high(period = DayAgg);
def Low_D = low(period = DayAgg);
def Open_D = open(period = DayAgg);
def Close_D = close(period = DayAgg);
def LookbackPeriod_D = 8;
def FirstBar_D = BarNumber();
def Highest_D = fold i_D = 1
to LookbackPeriod_D + 1
with p_D = 1
while p_D
do High_D > GetValue(High_D, -i_D);
def A_D = if (FirstBar_D > LookbackPeriod_D
and High_D == Highest(High_D, LookbackPeriod_D)
and Highest_D)
then High_D
else Double.NaN;
def Lowest_D = fold j_D = 1
to LookbackPeriod_D + 1
with q_D = 1
while q_D
do Low_D < GetValue(Low_D, -j_D);
def B_D = if (FirstBar_D > LookbackPeriod_D
and Low_D == Lowest(Low_D, LookbackPeriod_D)
and Lowest_D)
then Low_D
else Double.NaN;
#--------------------------------------------------------------
def _highInPeriod_D = Highest(High_D, LookbackPeriod_D);
def _lowInPeriod_D = Lowest(Low_D, LookbackPeriod_D);
#--------------------------------------------------------------
def marketLow_D = if _lowInPeriod_D < _lowInPeriod_D[-LookbackPeriod_D] then _lowInPeriod_D else _lowInPeriod_D[-LookbackPeriod_D];
def _markedLow_D = Low_D == marketLow_D;
rec _lastMarkedLow_D = CompoundValue(1, if IsNaN(_markedLow_D) then _lastMarkedLow_D[1] else if _markedLow_D then Low_D else _lastMarkedLow_D[1], Low_D);
#--------------------------------------------------------------
def marketHigh_D = if _highInPeriod_D > _highInPeriod_D[-LookbackPeriod_D] then _highInPeriod_D else _highInPeriod_D[-LookbackPeriod_D];
def _markedHigh_D = High_D == marketHigh_D;
rec _lastMarkedHigh_D = CompoundValue(1, if IsNaN(_markedHigh_D) then _lastMarkedHigh_D[1] else if _markedHigh_D then High_D else _lastMarkedHigh_D[1], High_D);
#--------------------------------------------------------------
plot Resistance_D = _lastMarkedHigh_D;
plot Support_D = _lastMarkedLow_D;
#plot isbtw = close > Resistance_D* NearPctLow_D and close < Resistance_D* NearPctHigh_D or close > Support_D * NearPctLow_D and close < Support_D * NearPctHigh_D ;
def lower_close_D = (SMA crosses below Support_D[1]);
def higher_close_D = (SMA crosses above Resistance_D[1]);
#---------------------------------------
def ph_D = Round(A_D, 2);
def pl_D = Round(B_D, 2);
#--------------------------------------------------------------
Resistance_D.SetPaintingStrategy(PaintingStrategy.DASHES);
Resistance_D.SetDefaultColor(Color.GREEN);
# plots a bubble x bars after last bar
input bars_in_future_D = 5;
def bif_D = bars_in_future_D;
def PivHigh_D = GetValue(ph_D,0);
def x_D = IsNaN(Ph_D[bif_D]) and !IsNaN(Ph_D[bif_D + 1]);
def vertH_D = Ph_D[bif_D + 1];
AddChartBubble(show and x_D, vertH_D, "HR", Color.WHITE, yes);
#--------------------------------------------------------------
Support_D.SetPaintingStrategy(PaintingStrategy.DASHES);
Support_D.SetDefaultColor(Color.RED);
# plots a bubble x bars after last bar
def PivLow_D = getvalue(pl_D,0);
def y_D = IsNaN(Pl_D[bif_D]) and !IsNaN(Pl_D[bif_D + 1]);
def vertL_D = Pl_D[bif_D + 1];
AddChartBubble(show and y_D, vertL_D, "HR", Color.WHITE, yes);
Hi halcyonguy, question. I am doing something similar in that I'm trying to addchartbubble for pivot high and pivot low for multiple timeframe on a single chart (ie, pivots for 30, 60, 4-HR, D will show on the 30 minute chart). Is your code looking at the last pivot high and using that as the starting point for the bars_in_the_future? When I insert your code, it works good for the more recent pivot H/L bubbles but if, for example, the 4Hr pivot H was a few days ago, the bubble is way back a few days ago. Is there any way to force the chart bubbles to always display near the right side of the chart? I'll paste a screenshot of how it looks.
Code:def sma = simpleMovingAvg(close,9); def xx = barnumber()==highestall(barnumber()); def ThirtyMinAgg = AggregationPeriod.THIRTY_MIN; def High_30 = high(period = ThirtyMinAgg); def Low_30 = low(period = ThirtyMinAgg); def Open_30 = open(period = ThirtyMinAgg); def Close_30 = close(period = ThirtyMinAgg); def labelyes = open > 0; def LookbackPeriod_30 = 8; def FirstBar_30 = BarNumber(); def Highest_30 = fold i_30 = 1 to LookbackPeriod_30 + 1 with p_30 = 1 while p_30 do High_30 > GetValue(High_30, -i_30); def A_30 = if (FirstBar_30 > LookbackPeriod_30 and High_30 == Highest(High_30, LookbackPeriod_30) and Highest_30) then High_30 else Double.NaN; def Lowest_30 = fold j_30 = 1 to LookbackPeriod_30 + 1 with q_30 = 1 while q_30 do Low_30 < GetValue(Low_30, -j_30); def B_30 = if (FirstBar_30 > LookbackPeriod_30 and Low_30 == Lowest(Low_30, LookbackPeriod_30) and Lowest_30) then Low_30 else Double.NaN; #-------------------------------------------------------------- def _highInPeriod_30 = Highest(High_30, LookbackPeriod_30); def _lowInPeriod_30 = Lowest(Low_30, LookbackPeriod_30); #-------------------------------------------------------------- def marketLow_30 = if _lowInPeriod_30 < _lowInPeriod_30[-LookbackPeriod_30] then _lowInPeriod_30 else _lowInPeriod_30[-LookbackPeriod_30]; def _markedLow_30 = Low_30 == marketLow_30; rec _lastMarkedLow_30 = CompoundValue(1, if IsNaN(_markedLow_30) then _lastMarkedLow_30[1] else if _markedLow_30 then Low_30 else _lastMarkedLow_30[1], Low_30); #-------------------------------------------------------------- def marketHigh_30 = if _highInPeriod_30 > _highInPeriod_30[-LookbackPeriod_30] then _highInPeriod_30 else _highInPeriod_30[-LookbackPeriod_30]; def _markedHigh_30 = High_30 == marketHigh_30; rec _lastMarkedHigh_30 = CompoundValue(1, if IsNaN(_markedHigh_30) then _lastMarkedHigh_30[1] else if _markedHigh_30 then High_30 else _lastMarkedHigh_30[1], High_30); #-------------------------------------------------------------- plot Resistance_30 = _lastMarkedHigh_30; plot Support_30 = _lastMarkedLow_30; plot price_30 = If(Resistance_30 > 0, Resistance_30, Double.NaN); #plot isbtw = close > Resistance_30* NearPctLow_30 and close < Resistance_30* NearPctHigh_30 or close > Support_30 * NearPctLow_30 and close < Support_30 * NearPctHigh_30 ; def lower_close_30 = (SMA crosses below Support_30[1]); def higher_close_30 = (SMA crosses above Resistance_30[1]); #--------------------------------------- def ph_30 = Round(A_30, 2); def pl_30 = Round(B_30, 2); #-------------------------------------------------------------- Resistance_30.SetPaintingStrategy(PaintingStrategy.DASHES); Resistance_30.SetDefaultColor(Color.GREEN); input show = yes; AddChartBubble(show and xx , Resistance_30, "30", Color.WHITE, yes); #-------------------------------------------------------------- Support_30.SetPaintingStrategy(PaintingStrategy.DASHES); Support_30.SetDefaultColor(Color.RED); AddChartBubble(show and xx, Support_30, "30", Color.WHITE, yes); ################################ def OneHrAgg = AggregationPeriod.HOUR; def High_Hr = high(period = OneHrAgg); def Low_Hr = low(period = OneHrAgg); def Open_Hr = open(period = OneHrAgg); def Close_Hr = close(period = OneHrAgg); def LookbackPeriod_HR = 8; def FirstBar_HR = BarNumber(); def Highest_HR = fold i_HR = 1 to LookbackPeriod_HR + 1 with p_HR = 1 while p_HR do High_Hr > GetValue(High_Hr, -i_HR); def A_HR = if (FirstBar_HR > LookbackPeriod_HR and High_Hr == Highest(High_Hr, LookbackPeriod_HR) and Highest_HR) then High_Hr else Double.NaN; def Lowest_HR = fold j_HR = 1 to LookbackPeriod_HR + 1 with q_HR = 1 while q_HR do Low_Hr < GetValue(Low_Hr, -j_HR); def B_HR = if (FirstBar_HR > LookbackPeriod_HR and Low_Hr == Lowest(Low_Hr, LookbackPeriod_HR) and Lowest_HR) then Low_Hr else Double.NaN; #-------------------------------------------------------------- def _highInPeriod_HR = Highest(High_Hr, LookbackPeriod_HR); def _lowInPeriod_HR = Lowest(Low_Hr, LookbackPeriod_HR); #-------------------------------------------------------------- def marketLow_HR = if _lowInPeriod_HR < _lowInPeriod_HR[-LookbackPeriod_HR] then _lowInPeriod_HR else _lowInPeriod_HR[-LookbackPeriod_HR]; def _markedLow_HR = Low_Hr == marketLow_HR; rec _lastMarkedLow_HR = CompoundValue(1, if IsNaN(_markedLow_HR) then _lastMarkedLow_HR[1] else if _markedLow_HR then Low_Hr else _lastMarkedLow_HR[1], Low_Hr); #-------------------------------------------------------------- def marketHigh_HR = if _highInPeriod_HR > _highInPeriod_HR[-LookbackPeriod_HR] then _highInPeriod_HR else _highInPeriod_HR[-LookbackPeriod_HR]; def _markedHigh_HR = High_Hr == marketHigh_HR; rec _lastMarkedHigh_HR = CompoundValue(1, if IsNaN(_markedHigh_HR) then _lastMarkedHigh_HR[1] else if _markedHigh_HR then High_Hr else _lastMarkedHigh_HR[1], High_Hr); #-------------------------------------------------------------- plot Resistance_HR = _lastMarkedHigh_HR; plot Support_HR = _lastMarkedLow_HR; #plot isbtw = close > Resistance_HR* NearPctLow_HR and close < Resistance_HR* NearPctHigh_HR or close > Support_HR * NearPctLow_HR and close < Support_HR * NearPctHigh_HR ; def lower_close_HR = (SMA crosses below Support_HR[1]); def higher_close_HR = (SMA crosses above Resistance_HR[1]); #--------------------------------------- def ph_HR = Round(A_HR, 2); def pl_HR = Round(B_HR, 2); #-------------------------------------------------------------- Resistance_HR.SetPaintingStrategy(PaintingStrategy.DASHES); Resistance_HR.SetDefaultColor(Color.GREEN); AddChartBubble(show and xx, Resistance_HR, "HR", Color.WHITE, yes); #-------------------------------------------------------------- Support_HR.SetPaintingStrategy(PaintingStrategy.DASHES); Support_HR.SetDefaultColor(Color.RED); AddChartBubble(show and xx, Support_HR, "HR", Color.WHITE, yes); ################################ def FourHrAgg = AggregationPeriod.FOUR_HOURS; def High_4HR = high(period = FourHrAgg); def Low_4HR = low(period = FourHrAgg); def Open_4HR = open(period = FourHrAgg); def Close_4HR = close(period = FourHrAgg); def LookbackPeriod_4HR = 8; def FirstBar_4HR = BarNumber(); def Highest_4HR = fold i_4HR = 1 to LookbackPeriod_4HR + 1 with p_4HR = 1 while p_4HR do High_4HR > GetValue(High_4HR, -i_4HR); def A_4HR = if (FirstBar_4HR > LookbackPeriod_4HR and High_4HR == Highest(High_4HR, LookbackPeriod_4HR) and Highest_4HR) then High_4HR else Double.NaN; def Lowest_4HR = fold j_4HR = 1 to LookbackPeriod_4HR + 1 with q_4HR = 1 while q_4HR do Low_4HR < GetValue(Low_4HR, -j_4HR); def B_4HR = if (FirstBar_4HR > LookbackPeriod_4HR and Low_4HR == Lowest(Low_4HR, LookbackPeriod_4HR) and Lowest_4HR) then Low_4HR else Double.NaN; #-------------------------------------------------------------- def _highInPeriod_4HR = Highest(High_4HR, LookbackPeriod_4HR); def _lowInPeriod_4HR = Lowest(Low_4HR, LookbackPeriod_4HR); #-------------------------------------------------------------- def marketLow_4HR = if _lowInPeriod_4HR < _lowInPeriod_4HR[-LookbackPeriod_4HR] then _lowInPeriod_4HR else _lowInPeriod_4HR[-LookbackPeriod_4HR]; def _markedLow_4HR = Low_4HR == marketLow_4HR; rec _lastMarkedLow_4HR = CompoundValue(1, if IsNaN(_markedLow_4HR) then _lastMarkedLow_4HR[1] else if _markedLow_4HR then Low_4HR else _lastMarkedLow_4HR[1], Low_4HR); #-------------------------------------------------------------- def marketHigh_4HR = if _highInPeriod_4HR > _highInPeriod_4HR[-LookbackPeriod_4HR] then _highInPeriod_4HR else _highInPeriod_4HR[-LookbackPeriod_4HR]; def _markedHigh_4HR = High_4HR == marketHigh_4HR; rec _lastMarkedHigh_4HR = CompoundValue(1, if IsNaN(_markedHigh_4HR) then _lastMarkedHigh_4HR[1] else if _markedHigh_4HR then High_4HR else _lastMarkedHigh_4HR[1], High_4HR); #-------------------------------------------------------------- plot Resistance_4HR = _lastMarkedHigh_4HR; plot Support_4HR = _lastMarkedLow_4HR; #plot price_4HR = if(resistance_4HR > 0, resistance_4HR, double.nan); #plot isbtw = close > Resistance_4HR* NearPctLow_4HR and close < Resistance_4HR* NearPctHigh_4HR or close > Support_4HR * NearPctLow_4HR and close < Support_4HR * NearPctHigh_4HR ; def lower_close_4HR = (SMA crosses below Support_4HR[1]); def higher_close_4HR = (SMA crosses above Resistance_4HR[1]); #--------------------------------------- def ph_4HR = Round(A_4HR, 2); def pl_4HR = Round(B_4HR, 2); #-------------------------------------------------------------- Resistance_4HR.SetPaintingStrategy(PaintingStrategy.DASHES); Resistance_4HR.SetDefaultColor(Color.GREEN); AddChartBubble(show and xx, Resistance_4HR, "4", Color.WHITE, yes); #-------------------------------------------------------------- Support_4HR.SetPaintingStrategy(PaintingStrategy.DASHES); Support_4HR.SetDefaultColor(Color.RED); AddChartBubble(show and xx, Support_4HR, "4", Color.WHITE, yes); ################################ def DayAgg = AggregationPeriod.DAY; def High_D = high(period = DayAgg); def Low_D = low(period = DayAgg); def Open_D = open(period = DayAgg); def Close_D = close(period = DayAgg); def LookbackPeriod_D = 8; def FirstBar_D = BarNumber(); def Highest_D = fold i_D = 1 to LookbackPeriod_D + 1 with p_D = 1 while p_D do High_D > GetValue(High_D, -i_D); def A_D = if (FirstBar_D > LookbackPeriod_D and High_D == Highest(High_D, LookbackPeriod_D) and Highest_D) then High_D else Double.NaN; def Lowest_D = fold j_D = 1 to LookbackPeriod_D + 1 with q_D = 1 while q_D do Low_D < GetValue(Low_D, -j_D); def B_D = if (FirstBar_D > LookbackPeriod_D and Low_D == Lowest(Low_D, LookbackPeriod_D) and Lowest_D) then Low_D else Double.NaN; #-------------------------------------------------------------- def _highInPeriod_D = Highest(High_D, LookbackPeriod_D); def _lowInPeriod_D = Lowest(Low_D, LookbackPeriod_D); #-------------------------------------------------------------- def marketLow_D = if _lowInPeriod_D < _lowInPeriod_D[-LookbackPeriod_D] then _lowInPeriod_D else _lowInPeriod_D[-LookbackPeriod_D]; def _markedLow_D = Low_D == marketLow_D; rec _lastMarkedLow_D = CompoundValue(1, if IsNaN(_markedLow_D) then _lastMarkedLow_D[1] else if _markedLow_D then Low_D else _lastMarkedLow_D[1], Low_D); #-------------------------------------------------------------- def marketHigh_D = if _highInPeriod_D > _highInPeriod_D[-LookbackPeriod_D] then _highInPeriod_D else _highInPeriod_D[-LookbackPeriod_D]; def _markedHigh_D = High_D == marketHigh_D; rec _lastMarkedHigh_D = CompoundValue(1, if IsNaN(_markedHigh_D) then _lastMarkedHigh_D[1] else if _markedHigh_D then High_D else _lastMarkedHigh_D[1], High_D); #-------------------------------------------------------------- plot Resistance_D = _lastMarkedHigh_D; plot Support_D = _lastMarkedLow_D; #plot isbtw = close > Resistance_D* NearPctLow_D and close < Resistance_D* NearPctHigh_D or close > Support_D * NearPctLow_D and close < Support_D * NearPctHigh_D ; def lower_close_D = (SMA crosses below Support_D[1]); def higher_close_D = (SMA crosses above Resistance_D[1]); #--------------------------------------- def ph_D = Round(A_D, 2); def pl_D = Round(B_D, 2); #-------------------------------------------------------------- Resistance_D.SetPaintingStrategy(PaintingStrategy.DASHES); Resistance_D.SetDefaultColor(Color.GREEN); AddChartBubble(show and xx, Resistance_D, "HR", Color.WHITE, yes); #-------------------------------------------------------------- Support_D.SetPaintingStrategy(PaintingStrategy.DASHES); Support_D.SetDefaultColor(Color.RED); AddChartBubble(show and xx, Support_D, "HR", Color.WHITE, yes);
absolutely fantastic. thank you so much for your help. Also, thank you so much for explaining why this works as it helps with my education. Thank you again!See if this works as you wanted. I added missing 'sma' definition and 'xx' to be barnumber()==highestall(barnumber()), which places bubbles to the far right of the chart. I removed the code you added to move the bubbles past the last bar, as it is not needed if this version is what you want.
One question. I noticed if I change my chart timeframe to anything above 30 minutes, the pivots and chart bubbles no longer display. Any idea why?See if this works as you wanted. I added missing 'sma' definition and 'xx' to be barnumber()==highestall(barnumber()), which places bubbles to the far right of the chart. I removed the code you added to move the bubbles past the last bar, as it is not needed if this version is what you want.
You cannot plot lower timeframe data on a higher chart timeframe.One question. I noticed if I change my chart timeframe to anything above 30 minutes, the pivots and chart bubbles no longer display. Any idea why?
Correct but if I go from a 30 minute chart to a 1 hour chart, I should still be able to see the 1 Hr, 4 Hr, and Daily plots, correct? That is the issue I seem to have. I go to a 1 HR chart and the plots are not displaying. Thoughts?You cannot plot lower timeframe data on a higher chart timeframe.
Correct but if I go from a 30 minute chart to a 1 hour chart, I should still be able to see the 1 Hr, 4 Hr, and Daily plots, correct? That is the issue I seem to have. I go to a 1 HR chart and the plots are not displaying. Thoughts?
Code:def sma = simpleMovingAvg(close,9); def xx = barnumber()==highestall(barnumber()); def ThirtyMinAgg = if getaggregationPeriod()<=AggregationPeriod.THIRTY_MIN then aggregationPeriod.THIRTY_MIN else getaggregationPeriod(); def High_30 = high(period = ThirtyMinAgg); def Low_30 = low(period = ThirtyMinAgg); def Open_30 = open(period = ThirtyMinAgg); def Close_30 = close(period = ThirtyMinAgg); def labelyes = open > 0; def LookbackPeriod_30 = 8; def FirstBar_30 = BarNumber(); def Highest_30 = fold i_30 = 1 to LookbackPeriod_30 + 1 with p_30 = 1 while p_30 do High_30 > GetValue(High_30, -i_30); def A_30 = if (FirstBar_30 > LookbackPeriod_30 and High_30 == Highest(High_30, LookbackPeriod_30) and Highest_30) then High_30 else Double.NaN; def Lowest_30 = fold j_30 = 1 to LookbackPeriod_30 + 1 with q_30 = 1 while q_30 do Low_30 < GetValue(Low_30, -j_30); def B_30 = if (FirstBar_30 > LookbackPeriod_30 and Low_30 == Lowest(Low_30, LookbackPeriod_30) and Lowest_30) then Low_30 else Double.NaN; #-------------------------------------------------------------- def _highInPeriod_30 = Highest(High_30, LookbackPeriod_30); def _lowInPeriod_30 = Lowest(Low_30, LookbackPeriod_30); #-------------------------------------------------------------- def marketLow_30 = if _lowInPeriod_30 < _lowInPeriod_30[-LookbackPeriod_30] then _lowInPeriod_30 else _lowInPeriod_30[-LookbackPeriod_30]; def _markedLow_30 = Low_30 == marketLow_30; rec _lastMarkedLow_30 = CompoundValue(1, if IsNaN(_markedLow_30) then _lastMarkedLow_30[1] else if _markedLow_30 then Low_30 else _lastMarkedLow_30[1], Low_30); #-------------------------------------------------------------- def marketHigh_30 = if _highInPeriod_30 > _highInPeriod_30[-LookbackPeriod_30] then _highInPeriod_30 else _highInPeriod_30[-LookbackPeriod_30]; def _markedHigh_30 = High_30 == marketHigh_30; rec _lastMarkedHigh_30 = CompoundValue(1, if IsNaN(_markedHigh_30) then _lastMarkedHigh_30[1] else if _markedHigh_30 then High_30 else _lastMarkedHigh_30[1], High_30); #-------------------------------------------------------------- plot Resistance_30 = _lastMarkedHigh_30; plot Support_30 = _lastMarkedLow_30; plot price_30 = If(Resistance_30 > 0, Resistance_30, Double.NaN); #plot isbtw = close > Resistance_30* NearPctLow_30 and close < Resistance_30* NearPctHigh_30 or close > Support_30 * NearPctLow_30 and close < Support_30 * NearPctHigh_30 ; def lower_close_30 = (SMA crosses below Support_30[1]); def higher_close_30 = (SMA crosses above Resistance_30[1]); #--------------------------------------- def ph_30 = Round(A_30, 2); def pl_30 = Round(B_30, 2); #-------------------------------------------------------------- Resistance_30.SetPaintingStrategy(PaintingStrategy.DASHES); Resistance_30.SetDefaultColor(Color.GREEN); input show = yes; AddChartBubble(show and xx , Resistance_30, "30", Color.WHITE, yes); #-------------------------------------------------------------- Support_30.SetPaintingStrategy(PaintingStrategy.DASHES); Support_30.SetDefaultColor(Color.RED); AddChartBubble(show and xx, Support_30, "30", Color.WHITE, yes); ################################ def OneHrAgg = if getaggregationPeriod()<=AggregationPeriod.HOUR then aggregationPeriod.HOUR else getaggregationPeriod(); def High_Hr = high(period = OneHrAgg); def Low_Hr = low(period = OneHrAgg); def Open_Hr = open(period = OneHrAgg); def Close_Hr = close(period = OneHrAgg); def LookbackPeriod_HR = 8; def FirstBar_HR = BarNumber(); def Highest_HR = fold i_HR = 1 to LookbackPeriod_HR + 1 with p_HR = 1 while p_HR do High_Hr > GetValue(High_Hr, -i_HR); def A_HR = if (FirstBar_HR > LookbackPeriod_HR and High_Hr == Highest(High_Hr, LookbackPeriod_HR) and Highest_HR) then High_Hr else Double.NaN; def Lowest_HR = fold j_HR = 1 to LookbackPeriod_HR + 1 with q_HR = 1 while q_HR do Low_Hr < GetValue(Low_Hr, -j_HR); def B_HR = if (FirstBar_HR > LookbackPeriod_HR and Low_Hr == Lowest(Low_Hr, LookbackPeriod_HR) and Lowest_HR) then Low_Hr else Double.NaN; #-------------------------------------------------------------- def _highInPeriod_HR = Highest(High_Hr, LookbackPeriod_HR); def _lowInPeriod_HR = Lowest(Low_Hr, LookbackPeriod_HR); #-------------------------------------------------------------- def marketLow_HR = if _lowInPeriod_HR < _lowInPeriod_HR[-LookbackPeriod_HR] then _lowInPeriod_HR else _lowInPeriod_HR[-LookbackPeriod_HR]; def _markedLow_HR = Low_Hr == marketLow_HR; rec _lastMarkedLow_HR = CompoundValue(1, if IsNaN(_markedLow_HR) then _lastMarkedLow_HR[1] else if _markedLow_HR then Low_Hr else _lastMarkedLow_HR[1], Low_Hr); #-------------------------------------------------------------- def marketHigh_HR = if _highInPeriod_HR > _highInPeriod_HR[-LookbackPeriod_HR] then _highInPeriod_HR else _highInPeriod_HR[-LookbackPeriod_HR]; def _markedHigh_HR = High_Hr == marketHigh_HR; rec _lastMarkedHigh_HR = CompoundValue(1, if IsNaN(_markedHigh_HR) then _lastMarkedHigh_HR[1] else if _markedHigh_HR then High_Hr else _lastMarkedHigh_HR[1], High_Hr); #-------------------------------------------------------------- plot Resistance_HR = _lastMarkedHigh_HR; plot Support_HR = _lastMarkedLow_HR; #plot isbtw = close > Resistance_HR* NearPctLow_HR and close < Resistance_HR* NearPctHigh_HR or close > Support_HR * NearPctLow_HR and close < Support_HR * NearPctHigh_HR ; def lower_close_HR = (SMA crosses below Support_HR[1]); def higher_close_HR = (SMA crosses above Resistance_HR[1]); #--------------------------------------- def ph_HR = Round(A_HR, 2); def pl_HR = Round(B_HR, 2); #-------------------------------------------------------------- Resistance_HR.SetPaintingStrategy(PaintingStrategy.DASHES); Resistance_HR.SetDefaultColor(Color.GREEN); AddChartBubble(show and xx, Resistance_HR, "HR", Color.WHITE, yes); #-------------------------------------------------------------- Support_HR.SetPaintingStrategy(PaintingStrategy.DASHES); Support_HR.SetDefaultColor(Color.RED); AddChartBubble(show and xx, Support_HR, "HR", Color.WHITE, yes); ################################ def FourHrAgg = if getaggregationPeriod()<=AggregationPeriod.FOUR_HOURS then aggregationPeriod.FOUR_HOURS else getaggregationPeriod(); def High_4HR = high(period = FourHrAgg); def Low_4HR = low(period = FourHrAgg); def Open_4HR = open(period = FourHrAgg); def Close_4HR = close(period = FourHrAgg); def LookbackPeriod_4HR = 8; def FirstBar_4HR = BarNumber(); def Highest_4HR = fold i_4HR = 1 to LookbackPeriod_4HR + 1 with p_4HR = 1 while p_4HR do High_4HR > GetValue(High_4HR, -i_4HR); def A_4HR = if (FirstBar_4HR > LookbackPeriod_4HR and High_4HR == Highest(High_4HR, LookbackPeriod_4HR) and Highest_4HR) then High_4HR else Double.NaN; def Lowest_4HR = fold j_4HR = 1 to LookbackPeriod_4HR + 1 with q_4HR = 1 while q_4HR do Low_4HR < GetValue(Low_4HR, -j_4HR); def B_4HR = if (FirstBar_4HR > LookbackPeriod_4HR and Low_4HR == Lowest(Low_4HR, LookbackPeriod_4HR) and Lowest_4HR) then Low_4HR else Double.NaN; #-------------------------------------------------------------- def _highInPeriod_4HR = Highest(High_4HR, LookbackPeriod_4HR); def _lowInPeriod_4HR = Lowest(Low_4HR, LookbackPeriod_4HR); #-------------------------------------------------------------- def marketLow_4HR = if _lowInPeriod_4HR < _lowInPeriod_4HR[-LookbackPeriod_4HR] then _lowInPeriod_4HR else _lowInPeriod_4HR[-LookbackPeriod_4HR]; def _markedLow_4HR = Low_4HR == marketLow_4HR; rec _lastMarkedLow_4HR = CompoundValue(1, if IsNaN(_markedLow_4HR) then _lastMarkedLow_4HR[1] else if _markedLow_4HR then Low_4HR else _lastMarkedLow_4HR[1], Low_4HR); #-------------------------------------------------------------- def marketHigh_4HR = if _highInPeriod_4HR > _highInPeriod_4HR[-LookbackPeriod_4HR] then _highInPeriod_4HR else _highInPeriod_4HR[-LookbackPeriod_4HR]; def _markedHigh_4HR = High_4HR == marketHigh_4HR; rec _lastMarkedHigh_4HR = CompoundValue(1, if IsNaN(_markedHigh_4HR) then _lastMarkedHigh_4HR[1] else if _markedHigh_4HR then High_4HR else _lastMarkedHigh_4HR[1], High_4HR); #-------------------------------------------------------------- plot Resistance_4HR = _lastMarkedHigh_4HR; plot Support_4HR = _lastMarkedLow_4HR; #plot price_4HR = if(resistance_4HR > 0, resistance_4HR, double.nan); #plot isbtw = close > Resistance_4HR* NearPctLow_4HR and close < Resistance_4HR* NearPctHigh_4HR or close > Support_4HR * NearPctLow_4HR and close < Support_4HR * NearPctHigh_4HR ; def lower_close_4HR = (SMA crosses below Support_4HR[1]); def higher_close_4HR = (SMA crosses above Resistance_4HR[1]); #--------------------------------------- def ph_4HR = Round(A_4HR, 2); def pl_4HR = Round(B_4HR, 2); #-------------------------------------------------------------- Resistance_4HR.SetPaintingStrategy(PaintingStrategy.DASHES); Resistance_4HR.SetDefaultColor(Color.GREEN); AddChartBubble(show and xx, Resistance_4HR, "4", Color.WHITE, yes); #-------------------------------------------------------------- Support_4HR.SetPaintingStrategy(PaintingStrategy.DASHES); Support_4HR.SetDefaultColor(Color.RED); AddChartBubble(show and xx, Support_4HR, "4", Color.WHITE, yes); ################################ def DayAgg = if getaggregationPeriod()<=AggregationPeriod.DAY then aggregationPeriod.DAY else getaggregationPeriod(); def High_D = high(period = DayAgg); def Low_D = low(period = DayAgg); def Open_D = open(period = DayAgg); def Close_D = close(period = DayAgg); def LookbackPeriod_D = 8; def FirstBar_D = BarNumber(); def Highest_D = fold i_D = 1 to LookbackPeriod_D + 1 with p_D = 1 while p_D do High_D > GetValue(High_D, -i_D); def A_D = if (FirstBar_D > LookbackPeriod_D and High_D == Highest(High_D, LookbackPeriod_D) and Highest_D) then High_D else Double.NaN; def Lowest_D = fold j_D = 1 to LookbackPeriod_D + 1 with q_D = 1 while q_D do Low_D < GetValue(Low_D, -j_D); def B_D = if (FirstBar_D > LookbackPeriod_D and Low_D == Lowest(Low_D, LookbackPeriod_D) and Lowest_D) then Low_D else Double.NaN; #-------------------------------------------------------------- def _highInPeriod_D = Highest(High_D, LookbackPeriod_D); def _lowInPeriod_D = Lowest(Low_D, LookbackPeriod_D); #-------------------------------------------------------------- def marketLow_D = if _lowInPeriod_D < _lowInPeriod_D[-LookbackPeriod_D] then _lowInPeriod_D else _lowInPeriod_D[-LookbackPeriod_D]; def _markedLow_D = Low_D == marketLow_D; rec _lastMarkedLow_D = CompoundValue(1, if IsNaN(_markedLow_D) then _lastMarkedLow_D[1] else if _markedLow_D then Low_D else _lastMarkedLow_D[1], Low_D); #-------------------------------------------------------------- def marketHigh_D = if _highInPeriod_D > _highInPeriod_D[-LookbackPeriod_D] then _highInPeriod_D else _highInPeriod_D[-LookbackPeriod_D]; def _markedHigh_D = High_D == marketHigh_D; rec _lastMarkedHigh_D = CompoundValue(1, if IsNaN(_markedHigh_D) then _lastMarkedHigh_D[1] else if _markedHigh_D then High_D else _lastMarkedHigh_D[1], High_D); #-------------------------------------------------------------- plot Resistance_D = _lastMarkedHigh_D; plot Support_D = _lastMarkedLow_D; #plot isbtw = close > Resistance_D* NearPctLow_D and close < Resistance_D* NearPctHigh_D or close > Support_D * NearPctLow_D and close < Support_D * NearPctHigh_D ; def lower_close_D = (SMA crosses below Support_D[1]); def higher_close_D = (SMA crosses above Resistance_D[1]); #--------------------------------------- def ph_D = Round(A_D, 2); def pl_D = Round(B_D, 2); #-------------------------------------------------------------- Resistance_D.SetPaintingStrategy(PaintingStrategy.DASHES); Resistance_D.SetDefaultColor(Color.GREEN); AddChartBubble(show and xx, Resistance_D, "HR", Color.WHITE, yes); #-------------------------------------------------------------- Support_D.SetPaintingStrategy(PaintingStrategy.DASHES); Support_D.SetDefaultColor(Color.RED); AddChartBubble(show and xx, Support_D, "HR", Color.WHITE, yes);
Looks like that took care of the plotting issue so thank you so much. I'm going to play around with the bubble code to see if I can fix the lower TF bubbles showing up on higher TF's. I'm also going to see if I can display the bubbles horizontally across the pivot line instead of vertically stacked. You are awesome!Since you still have the 30 minute aggregation defined in your script, TOS considers that an aggregationperiod error. See the 'i' icon at the top left of your chart.
However, I just tried some coding that might be a workaround this. You need to test it to see if it works as I have not at this time. It will display your script by using instead of a:
def ThirtyMinAgg = aggregationPeriod.THIRTY_MIN );
uses this instead:
def ThirtyMinAgg = if getaggregationPeriod()<=AggregationPeriod.THIRTY_MIN then aggregationPeriod.THIRTY_MIN else getaggregationPeriod();
Here is the revised code for you to test. It basically says if the current chart aggregation if less than or equal to your def agg, then use the def agg, otherwise use the current chart agg. It looks like the line plots may be okay, but the addchartbubbles may need code adjustment. Let me know if you need further assistance.
Looks like that took care of the plotting issue so thank you so much. I'm going to play around with the bubble code to see if I can fix the lower TF bubbles showing up on higher TF's. I'm also going to see if I can display the bubbles horizontally across the pivot line instead of vertically stacked. You are awesome!
Code:def sma = simpleMovingAvg(close,9); def xx = barnumber()==highestall(barnumber()); def ThirtyMinAgg = if getaggregationPeriod()<=AggregationPeriod.THIRTY_MIN then aggregationPeriod.THIRTY_MIN else getaggregationPeriod(); def High_30 = high(period = ThirtyMinAgg); def Low_30 = low(period = ThirtyMinAgg); def Open_30 = open(period = ThirtyMinAgg); def Close_30 = close(period = ThirtyMinAgg); def labelyes = open > 0; def LookbackPeriod_30 = 8; def FirstBar_30 = BarNumber(); def Highest_30 = fold i_30 = 1 to LookbackPeriod_30 + 1 with p_30 = 1 while p_30 do High_30 > GetValue(High_30, -i_30); def A_30 = if (FirstBar_30 > LookbackPeriod_30 and High_30 == Highest(High_30, LookbackPeriod_30) and Highest_30) then High_30 else Double.NaN; def Lowest_30 = fold j_30 = 1 to LookbackPeriod_30 + 1 with q_30 = 1 while q_30 do Low_30 < GetValue(Low_30, -j_30); def B_30 = if (FirstBar_30 > LookbackPeriod_30 and Low_30 == Lowest(Low_30, LookbackPeriod_30) and Lowest_30) then Low_30 else Double.NaN; #-------------------------------------------------------------- def _highInPeriod_30 = Highest(High_30, LookbackPeriod_30); def _lowInPeriod_30 = Lowest(Low_30, LookbackPeriod_30); #-------------------------------------------------------------- def marketLow_30 = if _lowInPeriod_30 < _lowInPeriod_30[-LookbackPeriod_30] then _lowInPeriod_30 else _lowInPeriod_30[-LookbackPeriod_30]; def _markedLow_30 = Low_30 == marketLow_30; rec _lastMarkedLow_30 = CompoundValue(1, if IsNaN(_markedLow_30) then _lastMarkedLow_30[1] else if _markedLow_30 then Low_30 else _lastMarkedLow_30[1], Low_30); #-------------------------------------------------------------- def marketHigh_30 = if _highInPeriod_30 > _highInPeriod_30[-LookbackPeriod_30] then _highInPeriod_30 else _highInPeriod_30[-LookbackPeriod_30]; def _markedHigh_30 = High_30 == marketHigh_30; rec _lastMarkedHigh_30 = CompoundValue(1, if IsNaN(_markedHigh_30) then _lastMarkedHigh_30[1] else if _markedHigh_30 then High_30 else _lastMarkedHigh_30[1], High_30); #-------------------------------------------------------------- plot Resistance_30 = _lastMarkedHigh_30; plot Support_30 = _lastMarkedLow_30; plot price_30 = If(Resistance_30 > 0, Resistance_30, Double.NaN); #plot isbtw = close > Resistance_30* NearPctLow_30 and close < Resistance_30* NearPctHigh_30 or close > Support_30 * NearPctLow_30 and close < Support_30 * NearPctHigh_30 ; def lower_close_30 = (SMA crosses below Support_30[1]); def higher_close_30 = (SMA crosses above Resistance_30[1]); #--------------------------------------- def ph_30 = Round(A_30, 2); def pl_30 = Round(B_30, 2); #-------------------------------------------------------------- Resistance_30.SetPaintingStrategy(PaintingStrategy.DASHES); Resistance_30.SetDefaultColor(Color.GREEN); input show = yes; AddChartBubble(show and xx and getaggregationPeriod()<=AggregationPeriod.THIRTY_MIN, Resistance_30, "30", Color.WHITE, yes); #-------------------------------------------------------------- Support_30.SetPaintingStrategy(PaintingStrategy.DASHES); Support_30.SetDefaultColor(Color.RED); AddChartBubble(show and xx and getaggregationPeriod()<=AggregationPeriod.THIRTY_MIN, Support_30, "30", Color.WHITE, yes); ################################ def OneHrAgg = if getaggregationPeriod()<=AggregationPeriod.HOUR then aggregationPeriod.HOUR else getaggregationPeriod(); def High_Hr = high(period = OneHrAgg); def Low_Hr = low(period = OneHrAgg); def Open_Hr = open(period = OneHrAgg); def Close_Hr = close(period = OneHrAgg); def LookbackPeriod_HR = 8; def FirstBar_HR = BarNumber(); def Highest_HR = fold i_HR = 1 to LookbackPeriod_HR + 1 with p_HR = 1 while p_HR do High_Hr > GetValue(High_Hr, -i_HR); def A_HR = if (FirstBar_HR > LookbackPeriod_HR and High_Hr == Highest(High_Hr, LookbackPeriod_HR) and Highest_HR) then High_Hr else Double.NaN; def Lowest_HR = fold j_HR = 1 to LookbackPeriod_HR + 1 with q_HR = 1 while q_HR do Low_Hr < GetValue(Low_Hr, -j_HR); def B_HR = if (FirstBar_HR > LookbackPeriod_HR and Low_Hr == Lowest(Low_Hr, LookbackPeriod_HR) and Lowest_HR) then Low_Hr else Double.NaN; #-------------------------------------------------------------- def _highInPeriod_HR = Highest(High_Hr, LookbackPeriod_HR); def _lowInPeriod_HR = Lowest(Low_Hr, LookbackPeriod_HR); #-------------------------------------------------------------- def marketLow_HR = if _lowInPeriod_HR < _lowInPeriod_HR[-LookbackPeriod_HR] then _lowInPeriod_HR else _lowInPeriod_HR[-LookbackPeriod_HR]; def _markedLow_HR = Low_Hr == marketLow_HR; rec _lastMarkedLow_HR = CompoundValue(1, if IsNaN(_markedLow_HR) then _lastMarkedLow_HR[1] else if _markedLow_HR then Low_Hr else _lastMarkedLow_HR[1], Low_Hr); #-------------------------------------------------------------- def marketHigh_HR = if _highInPeriod_HR > _highInPeriod_HR[-LookbackPeriod_HR] then _highInPeriod_HR else _highInPeriod_HR[-LookbackPeriod_HR]; def _markedHigh_HR = High_Hr == marketHigh_HR; rec _lastMarkedHigh_HR = CompoundValue(1, if IsNaN(_markedHigh_HR) then _lastMarkedHigh_HR[1] else if _markedHigh_HR then High_Hr else _lastMarkedHigh_HR[1], High_Hr); #-------------------------------------------------------------- plot Resistance_HR = _lastMarkedHigh_HR; plot Support_HR = _lastMarkedLow_HR; #plot isbtw = close > Resistance_HR* NearPctLow_HR and close < Resistance_HR* NearPctHigh_HR or close > Support_HR * NearPctLow_HR and close < Support_HR * NearPctHigh_HR ; def lower_close_HR = (SMA crosses below Support_HR[1]); def higher_close_HR = (SMA crosses above Resistance_HR[1]); #--------------------------------------- def ph_HR = Round(A_HR, 2); def pl_HR = Round(B_HR, 2); #-------------------------------------------------------------- Resistance_HR.SetPaintingStrategy(PaintingStrategy.DASHES); Resistance_HR.SetDefaultColor(Color.GREEN); AddChartBubble(show and xx and getaggregationPeriod()<=AggregationPeriod.hour, Resistance_HR, "HR", Color.WHITE, yes); #-------------------------------------------------------------- Support_HR.SetPaintingStrategy(PaintingStrategy.DASHES); Support_HR.SetDefaultColor(Color.RED); AddChartBubble(show and xx and getaggregationPeriod()<=AggregationPeriod.hour, Support_HR, "HR", Color.WHITE, yes); ################################ def FourHrAgg = if getaggregationPeriod()<=AggregationPeriod.FOUR_HOURS then aggregationPeriod.FOUR_HOURS else getaggregationPeriod(); def High_4HR = high(period = FourHrAgg); def Low_4HR = low(period = FourHrAgg); def Open_4HR = open(period = FourHrAgg); def Close_4HR = close(period = FourHrAgg); def LookbackPeriod_4HR = 8; def FirstBar_4HR = BarNumber(); def Highest_4HR = fold i_4HR = 1 to LookbackPeriod_4HR + 1 with p_4HR = 1 while p_4HR do High_4HR > GetValue(High_4HR, -i_4HR); def A_4HR = if (FirstBar_4HR > LookbackPeriod_4HR and High_4HR == Highest(High_4HR, LookbackPeriod_4HR) and Highest_4HR) then High_4HR else Double.NaN; def Lowest_4HR = fold j_4HR = 1 to LookbackPeriod_4HR + 1 with q_4HR = 1 while q_4HR do Low_4HR < GetValue(Low_4HR, -j_4HR); def B_4HR = if (FirstBar_4HR > LookbackPeriod_4HR and Low_4HR == Lowest(Low_4HR, LookbackPeriod_4HR) and Lowest_4HR) then Low_4HR else Double.NaN; #-------------------------------------------------------------- def _highInPeriod_4HR = Highest(High_4HR, LookbackPeriod_4HR); def _lowInPeriod_4HR = Lowest(Low_4HR, LookbackPeriod_4HR); #-------------------------------------------------------------- def marketLow_4HR = if _lowInPeriod_4HR < _lowInPeriod_4HR[-LookbackPeriod_4HR] then _lowInPeriod_4HR else _lowInPeriod_4HR[-LookbackPeriod_4HR]; def _markedLow_4HR = Low_4HR == marketLow_4HR; rec _lastMarkedLow_4HR = CompoundValue(1, if IsNaN(_markedLow_4HR) then _lastMarkedLow_4HR[1] else if _markedLow_4HR then Low_4HR else _lastMarkedLow_4HR[1], Low_4HR); #-------------------------------------------------------------- def marketHigh_4HR = if _highInPeriod_4HR > _highInPeriod_4HR[-LookbackPeriod_4HR] then _highInPeriod_4HR else _highInPeriod_4HR[-LookbackPeriod_4HR]; def _markedHigh_4HR = High_4HR == marketHigh_4HR; rec _lastMarkedHigh_4HR = CompoundValue(1, if IsNaN(_markedHigh_4HR) then _lastMarkedHigh_4HR[1] else if _markedHigh_4HR then High_4HR else _lastMarkedHigh_4HR[1], High_4HR); #-------------------------------------------------------------- plot Resistance_4HR = _lastMarkedHigh_4HR; plot Support_4HR = _lastMarkedLow_4HR; #plot price_4HR = if(resistance_4HR > 0, resistance_4HR, double.nan); #plot isbtw = close > Resistance_4HR* NearPctLow_4HR and close < Resistance_4HR* NearPctHigh_4HR or close > Support_4HR * NearPctLow_4HR and close < Support_4HR * NearPctHigh_4HR ; def lower_close_4HR = (SMA crosses below Support_4HR[1]); def higher_close_4HR = (SMA crosses above Resistance_4HR[1]); #--------------------------------------- def ph_4HR = Round(A_4HR, 2); def pl_4HR = Round(B_4HR, 2); #-------------------------------------------------------------- Resistance_4HR.SetPaintingStrategy(PaintingStrategy.DASHES); Resistance_4HR.SetDefaultColor(Color.GREEN); AddChartBubble(show and xx and getaggregationPeriod()<=AggregationPeriod.four_hours, Resistance_4HR, "4", Color.WHITE, yes); #-------------------------------------------------------------- Support_4HR.SetPaintingStrategy(PaintingStrategy.DASHES); Support_4HR.SetDefaultColor(Color.RED); AddChartBubble(show and xx and getaggregationPeriod()<=AggregationPeriod.four_hours, Support_4HR, "4", Color.WHITE, yes); ################################ def DayAgg = if getaggregationPeriod()<=AggregationPeriod.DAY then aggregationPeriod.DAY else getaggregationPeriod(); def High_D = high(period = DayAgg); def Low_D = low(period = DayAgg); def Open_D = open(period = DayAgg); def Close_D = close(period = DayAgg); def LookbackPeriod_D = 8; def FirstBar_D = BarNumber(); def Highest_D = fold i_D = 1 to LookbackPeriod_D + 1 with p_D = 1 while p_D do High_D > GetValue(High_D, -i_D); def A_D = if (FirstBar_D > LookbackPeriod_D and High_D == Highest(High_D, LookbackPeriod_D) and Highest_D) then High_D else Double.NaN; def Lowest_D = fold j_D = 1 to LookbackPeriod_D + 1 with q_D = 1 while q_D do Low_D < GetValue(Low_D, -j_D); def B_D = if (FirstBar_D > LookbackPeriod_D and Low_D == Lowest(Low_D, LookbackPeriod_D) and Lowest_D) then Low_D else Double.NaN; #-------------------------------------------------------------- def _highInPeriod_D = Highest(High_D, LookbackPeriod_D); def _lowInPeriod_D = Lowest(Low_D, LookbackPeriod_D); #-------------------------------------------------------------- def marketLow_D = if _lowInPeriod_D < _lowInPeriod_D[-LookbackPeriod_D] then _lowInPeriod_D else _lowInPeriod_D[-LookbackPeriod_D]; def _markedLow_D = Low_D == marketLow_D; rec _lastMarkedLow_D = CompoundValue(1, if IsNaN(_markedLow_D) then _lastMarkedLow_D[1] else if _markedLow_D then Low_D else _lastMarkedLow_D[1], Low_D); #-------------------------------------------------------------- def marketHigh_D = if _highInPeriod_D > _highInPeriod_D[-LookbackPeriod_D] then _highInPeriod_D else _highInPeriod_D[-LookbackPeriod_D]; def _markedHigh_D = High_D == marketHigh_D; rec _lastMarkedHigh_D = CompoundValue(1, if IsNaN(_markedHigh_D) then _lastMarkedHigh_D[1] else if _markedHigh_D then High_D else _lastMarkedHigh_D[1], High_D); #-------------------------------------------------------------- plot Resistance_D = _lastMarkedHigh_D; plot Support_D = _lastMarkedLow_D; #plot isbtw = close > Resistance_D* NearPctLow_D and close < Resistance_D* NearPctHigh_D or close > Support_D * NearPctLow_D and close < Support_D * NearPctHigh_D ; def lower_close_D = (SMA crosses below Support_D[1]); def higher_close_D = (SMA crosses above Resistance_D[1]); #--------------------------------------- def ph_D = Round(A_D, 2); def pl_D = Round(B_D, 2); #-------------------------------------------------------------- Resistance_D.SetPaintingStrategy(PaintingStrategy.DASHES); Resistance_D.SetDefaultColor(Color.GREEN); AddChartBubble(show and xx and getaggregationPeriod()<=AggregationPeriod.day, Resistance_D, "D", Color.WHITE, yes); #-------------------------------------------------------------- Support_D.SetPaintingStrategy(PaintingStrategy.DASHES); Support_D.SetDefaultColor(Color.RED); AddChartBubble(show and xx and getaggregationPeriod()<=AggregationPeriod.day, Support_D, "D", Color.WHITE, yes);
def isLastBar = if IsNan(Close[-1]) then 1 else 0;
Addchartbubble(isLastBar, 22.0, "Today'sHi", Color.GRAY, no);
Code:def isLastBar = if IsNan(Close[-1]) then 1 else 0; Addchartbubble(isLastBar, 22.0, "Today'sHi", Color.GRAY, no);
In TOS, the code above displays a bubble at 22.0 level, at current bar. Bubble moves horizontally as new bar forms.
Question - How to display a chart bubble few (say 4) bars in future instead of at current bar?
input showOnlyToday = No;
def Market_Open_Time = 0930;
def Market_Close_Time = 1600;
def day = GetDay();
def lastDay = GetLastDay();
def isToday = If(day == lastDay, 1, 0);
def isRTH = getTime() >= RegularTradingStart(getYYYYMMDD()) and getTime() < RegularTradingEnd(getYYYYMMDD());
def shouldPlot = If(showOnlyToday and isToday, 1, If(!showOnlyToday, 1, 0)) and isRTH;
def pastOpen = If((SecondsTillTime(Market_Open_Time) > 0), 0, 1);
def pastClose = If((SecondsTillTime(Market_Close_Time) > 0), 0, 1);
def Post = secondsFromTime(Market_Close_Time);
def Pre = secondsTillTime(Market_Open_Time);
def Closed = Post >=0 or Pre>=0;
########################
def o = open;
def h = high;
def l = low;
def c = close;
def GlobeX = Closed;
def ONhigh = if GlobeX and !GlobeX[1]
then h
else if GlobeX and h > ONhigh[1]
then h
else ONhigh[1];
########################
input bars_in_future = 3;
def cls = close;
def x1 = (!IsNaN(cls) and IsNaN(cls[-1]));
def x2 = isNaN(cls[bars_in_future]) and !isNaN(cls[bars_in_future+1]);
input showBubble = yes;
def bubbleAtClose = showBubble and x1; #Display bubble at close of price.
#def bubbleAtClose = showBubble and x2; # Do not display bubble
############################################################
def pmHi = ONhigh;
plot plot_pmHi = If (shouldPlot) then pmHi else double.nan;
plot_pmHi.SetLineWeight(1);
plot_pmHi.SetDefaultColor(CreateColor(0,155,183));
plot_pmHi.HideBubble();
AddChartBubble(bubbleAtClose and shouldPlot, pmHi, "pmHi", Color.Gray, yes);
#################
def FiftyPercentOffPreMarketHigh = pmHi * 0.5;
plot plot_FiftyPercentOffPreMarketHigh = If (shouldPlot) then FiftyPercentOffPreMarketHigh else double.nan;
plot_FiftyPercentOffPreMarketHigh.SetLineWeight(1);
plot_FiftyPercentOffPreMarketHigh.SetDefaultColor(Color.BLUE);
plot_FiftyPercentOffPreMarketHigh.HideBubble();
Addchartbubble(bubbleAtClose, FiftyPercentOffPreMarketHigh, "-50%", Color.GRAY, yes);
###########
Thanks for sharing the code. I plaugged it into following script. Trying to display the bubble in future bars but does not work.
1. Note two lines of code:
def bubbleAtClose = showBubble and x1; ### Display bubble at close of price.
Or
def bubbleAtClose = showBubble and x2; ### Do not display bubble
2. Note that the ticker is of Option. " .SPXW210908P4490 "
Looks like value of pmHi become null beyond Close of price. Please advise on how to display bubble in future bar with followng code.
Thanks
Ruby:input showOnlyToday = No; def Market_Open_Time = 0930; def Market_Close_Time = 1600; def day = GetDay(); def lastDay = GetLastDay(); def isToday = If(day == lastDay, 1, 0); def isRTH = getTime() >= RegularTradingStart(getYYYYMMDD()) and getTime() < RegularTradingEnd(getYYYYMMDD()); def shouldPlot = If(showOnlyToday and isToday, 1, If(!showOnlyToday, 1, 0)) and isRTH; def pastOpen = If((SecondsTillTime(Market_Open_Time) > 0), 0, 1); def pastClose = If((SecondsTillTime(Market_Close_Time) > 0), 0, 1); def Post = secondsFromTime(Market_Close_Time); def Pre = secondsTillTime(Market_Open_Time); def Closed = Post >=0 or Pre>=0; ######################## def o = open; def h = high; def l = low; def c = close; def GlobeX = Closed; def ONhigh = if GlobeX and !GlobeX[1] then h else if GlobeX and h > ONhigh[1] then h else ONhigh[1]; ######################## input bars_in_future = 3; def cls = close; def x1 = barnumber()==highestall(barnumber());#(!IsNaN(cls) and IsNaN(cls[-1])); def x2 = isNaN(cls[bars_in_future]) and !isNaN(cls[bars_in_future+1]); input showBubble = yes; def bubbleAtClose = showBubble and x1; #Display bubble at close of price. #def bubbleAtClose = showBubble and x2; # Do not display bubble ############################################################ def pmHi = if isnan(close) then pmHi[1] else ONhigh; plot plot_pmHi = If (shouldPlot) then pmHi else double.nan; plot_pmHi.SetLineWeight(1); plot_pmHi.SetDefaultColor(CreateColor(0,155,183)); plot_pmHi.HideBubble(); AddChartBubble(bubbleAtClose and shouldPlot, pmHi, "pmHi", Color.Gray, yes); ################# def FiftyPercentOffPreMarketHigh = pmHi * 0.5; plot plot_FiftyPercentOffPreMarketHigh = If (shouldPlot) then FiftyPercentOffPreMarketHigh else double.nan; plot_FiftyPercentOffPreMarketHigh.SetLineWeight(1); plot_FiftyPercentOffPreMarketHigh.SetDefaultColor(Color.BLUE); plot_FiftyPercentOffPreMarketHigh.HideBubble(); Addchartbubble(bubbleAtClose, FiftyPercentOffPreMarketHigh, "-50%", Color.GRAY, yes); ###########
# Priceline level
# Plots a Horizontal Line that follows the price/close value
# cabe1332
# start code
input price=close;
input offset=0;
input length = 100;
def sma = SimpleMovingAvg(price, 1, length);
rec line = if IsNaN(sma) then line[1] else sma[offset];
plot priceline=if isnan(sma) then line else double.nan;
priceline.setpaintingStrategy(paintingStrategy.LINE);
priceline.setlineWeight(3);
priceline.setdefaultColor(color.magenta);
priceline.hideBubble();
# end code
Start a new thread and receive assistance from our community.
useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.
We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.
If you are new, or just looking for guidance, here are some helpful links to get you started.