How can I make this previous day low/high script work on all time frames?

kingkunta

New member
I have this code that only works on daily, weekly and monthly when going into the settings.. is there anyway to make it work on whatever time frame it is CURRENTLY on? Thanks in advance!

Code:
input timeFrame = {default DAY, WEEK, MONTH};
plot High = high(period = timeFrame)[1];
plot Low = low(period = timeFrame)[1];
plot Close = close(period = timeFrame)[1];
High.SetDefaultColor (Color.GREEN);
High.SetPaintingStrategy(PaintingStrategy.DASHES);
Low.SetDefaultColor(Color.RED);
Low.SetPaintingStrategy(PaintingStrategy.DASHES);
Close.SetDefaultColor (Color.GRAY);
Close.SetPaintingStrategy(PaintingStrategy.DASHES);
 
Solution
@kingkunta not sure what you are trying to accomplish. The code above plots the high, low, and close for the previous day, week, or month. If you change the timeframe to your current chart time frame, then you will get high, low, and close for the previous bar only.

If you want high, low, and close of the current day, week, or month then just remove the '[1]' from the plot definitions;
Ruby:
plot High = high(period = timeFrame);
plot Low = low(period = timeFrame);
plot Close = close(period = timeFrame);
@kingkunta not sure what you are trying to accomplish. The code above plots the high, low, and close for the previous day, week, or month. If you change the timeframe to your current chart time frame, then you will get high, low, and close for the previous bar only.

If you want high, low, and close of the current day, week, or month then just remove the '[1]' from the plot definitions;
Ruby:
plot High = high(period = timeFrame);
plot Low = low(period = timeFrame);
plot Close = close(period = timeFrame);
 
Solution
@kingkunta not sure what you are trying to accomplish. The code above plots the high, low, and close for the previous day, week, or month. If you change the timeframe to your current chart time frame, then you will get high, low, and close for the previous bar only.

If you want high, low, and close of the current day, week, or month then just remove the '[1]' from the plot definitions;
Ruby:
plot High = high(period = timeFrame);
plot Low = low(period = timeFrame);
plot Close = close(period = timeFrame);
Hey thanks for the reply. what im asking for is the code to automatically show me study on whatever time frame I am currently on. instead of having to manually go into the settings and do it myself. Do you know how to do that?
 
I found another post by @subharmonic that shows how to use GetAggregationPeriod() to make your thinkScript aware of the current chart timeframe.
https://usethinkscript.com/threads/...-timeframe-mtf-in-thinkorswim.8050/post-19314

Change this:
Code:
input timeFrame = {default DAY, WEEK, MONTH};

To This:
Code:
def AP = GetAggregationPeriod();
def timeFrame = if AP <= AggregationPeriod.Day then AggregationPeriod.DAY
                else if AP <= AggregationPeriod.WEEK then AggregationPeriod.WEEK
                else AggregationPeriod.MONTH;

Full Code:
Code:
# https://usethinkscript.com/threads/how-can-i-make-this-previous-day-low-high-script-work-on-all-time-frames.12279/
# https://usethinkscript.com/threads/converting-indicator-to-multi-timeframe-mtf-in-thinkorswim.8050/post-19314
# https://tlc.thinkorswim.com/center/reference/thinkScript/Constants/AggregationPeriod
# https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Others/GetAggregationPeriod

def AP = GetAggregationPeriod();
def timeFrame = if AP <= AggregationPeriod.Day then AggregationPeriod.DAY
                else if AP <= AggregationPeriod.WEEK then AggregationPeriod.WEEK
                else AggregationPeriod.MONTH;

plot High = high(period = timeFrame)[1];
plot Low = low(period = timeFrame)[1];
plot Close = close(period = timeFrame)[1];
High.SetDefaultColor (Color.GREEN);
High.SetPaintingStrategy(PaintingStrategy.DASHES);
Low.SetDefaultColor(Color.RED);
Low.SetPaintingStrategy(PaintingStrategy.DASHES);
Close.SetDefaultColor (Color.GRAY);
Close.SetPaintingStrategy(PaintingStrategy.DASHES);

Disclaimer: This won't display for quarterly/yearly charts, (you limited to day, week, month in your request) but you could add additional if/else rows to accommodate higher time frames.

Example:
Code:
def AP = GetAggregationPeriod();
def timeFrame = if AP <= AggregationPeriod.Day then AggregationPeriod.DAY
                else if AP <= AggregationPeriod.WEEK then AggregationPeriod.WEEK
                else if AP <= AggregationPeriod.MONTH then AggregationPeriod.MONTH
                else if AP <= AggregationPeriod.QUARTER then AggregationPeriod.QUARTER
                else AggregationPeriod.YEAR
 
I found another post by @subharmonic that shows how to use GetAggregationPeriod() to make your thinkScript aware of the current chart timeframe.
https://usethinkscript.com/threads/...-timeframe-mtf-in-thinkorswim.8050/post-19314

Change this:
Code:
input timeFrame = {default DAY, WEEK, MONTH};

To This:
Code:
def AP = GetAggregationPeriod();
def timeFrame = if AP <= AggregationPeriod.Day then AggregationPeriod.DAY
                else if AP <= AggregationPeriod.WEEK then AggregationPeriod.WEEK
                else AggregationPeriod.MONTH;

Full Code:
Code:
# https://usethinkscript.com/threads/how-can-i-make-this-previous-day-low-high-script-work-on-all-time-frames.12279/
# https://usethinkscript.com/threads/converting-indicator-to-multi-timeframe-mtf-in-thinkorswim.8050/post-19314
# https://tlc.thinkorswim.com/center/reference/thinkScript/Constants/AggregationPeriod
# https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Others/GetAggregationPeriod

def AP = GetAggregationPeriod();
def timeFrame = if AP <= AggregationPeriod.Day then AggregationPeriod.DAY
                else if AP <= AggregationPeriod.WEEK then AggregationPeriod.WEEK
                else AggregationPeriod.MONTH;

plot High = high(period = timeFrame)[1];
plot Low = low(period = timeFrame)[1];
plot Close = close(period = timeFrame)[1];
High.SetDefaultColor (Color.GREEN);
High.SetPaintingStrategy(PaintingStrategy.DASHES);
Low.SetDefaultColor(Color.RED);
Low.SetPaintingStrategy(PaintingStrategy.DASHES);
Close.SetDefaultColor (Color.GRAY);
Close.SetPaintingStrategy(PaintingStrategy.DASHES);

Disclaimer: This won't display for quarterly/yearly charts, (you limited to day, week, month in your request) but you could add additional if/else rows to accommodate higher time frames.

Example:
Code:
def AP = GetAggregationPeriod();
def timeFrame = if AP <= AggregationPeriod.Day then AggregationPeriod.DAY
                else if AP <= AggregationPeriod.WEEK then AggregationPeriod.WEEK
                else if AP <= AggregationPeriod.MONTH then AggregationPeriod.MONTH
                else if AP <= AggregationPeriod.QUARTER then AggregationPeriod.QUARTER
                else AggregationPeriod.YEAR

Hey there, Im looking for something similar. What Im looking to do is draw extended to the right lines to the top and bottom of yesterday, last week, last month, last quarter, last year, and keep them on the chart on any time frame. So like when im on the 30, i can see im breaking through the monthly or weekly levels. Hop that someone can help me! Even if you can show how to get the last bar from any tf on any tf and draw the line it would be hepful, thanks!
 
Hey there, Im looking for something similar. What Im looking to do is draw extended to the right lines to the top and bottom of yesterday, last week, last month, last quarter, last year, and keep them on the chart on any time frame. So like when im on the 30, i can see im breaking through the monthly or weekly levels. Hop that someone can help me! Even if you can show how to get the last bar from any tf on any tf and draw the line it would be hepful, thanks!

This should help

Capture.jpg
Ruby:
input periodsback = 1;

def HD = if IsNaN(close) then HD[1] else high(period = "DAY")[periodsback];
def LD = if IsNaN(close) then LD[1] else low(period  = "DAY" )[periodsback];

plot HighD = if IsNaN(high(period = "DAY")[-1]) then HD else Double.NaN;
plot LowD  = if IsNaN(low(period = "DAY")[-1]) then LD else Double.NaN;

HighD.SetDefaultColor (Color.GREEN);
HighD.SetPaintingStrategy(PaintingStrategy.DASHES);
LowD.SetDefaultColor(Color.RED);
LowD.SetPaintingStrategy(PaintingStrategy.DASHES);

def HW = if IsNaN(close) then HW[1] else high(period = "WEEK" )[periodsback];
def LW = if IsNaN(close) then LW[1] else low(period  = "WEEK" )[periodsback];

plot HighW = if IsNaN(high(period = "WEEK")[-1]) then HW else Double.NaN;
plot LowW  = if IsNaN(low(period = "WEEK")[-1]) then LW else Double.NaN;

HighW.SetDefaultColor (Color.GREEN);
HighW.SetPaintingStrategy(PaintingStrategy.DASHES);
LowW.SetDefaultColor(Color.RED);
LowW.SetPaintingStrategy(PaintingStrategy.DASHES);

def HM = if IsNaN(close) then HM[1] else high(period = "MONTH" )[periodsback];
def LM = if IsNaN(close) then LM[1] else low(period  = "MONTH" )[periodsback];

plot HighM = if IsNaN(high(period = "MONTH")[-1]) then HM else Double.NaN;
plot LowM  = if IsNaN(low(period = "MONTH")[-1]) then LM else Double.NaN;

HighM.SetDefaultColor (Color.GREEN);
HighM.SetPaintingStrategy(PaintingStrategy.DASHES);
LowM.SetDefaultColor(Color.RED);
LowM.SetPaintingStrategy(PaintingStrategy.DASHES);

def HQ = if IsNaN(close) then HQ[1] else high(period = "QUARTER" )[periodsback];
def LQ = if IsNaN(close) then LQ[1] else low(period  = "QUARTER" )[periodsback];

plot HighQ = if IsNaN(high(period = "QUARTER")[-1]) then HQ else Double.NaN;
plot LowQ  = if IsNaN(low(period = "QUARTER")[-1]) then LQ else Double.NaN;

HighQ.SetDefaultColor (Color.GREEN);
HighQ.SetPaintingStrategy(PaintingStrategy.DASHES);
LowQ.SetDefaultColor(Color.RED);
LowQ.SetPaintingStrategy(PaintingStrategy.DASHES);

def HY = if IsNaN(close) then HY[1] else high(period = "YEAR" )[periodsback];
def LY = if IsNaN(close) then LY[1] else low(period  = "YEAR" )[periodsback];

plot HighY = if IsNaN(high(period = "YEAR")[-1]) then HY else Double.NaN;
plot LowY  = if IsNaN(low(period = "YEAR")[-1]) then LY else Double.NaN;

HighY.SetDefaultColor (Color.GREEN);
HighY.SetPaintingStrategy(PaintingStrategy.DASHES);
LowY.SetDefaultColor(Color.RED);
LowY.SetPaintingStrategy(PaintingStrategy.DASHES);

input bubbles     = yes;
input Highbubblemover = 2;
def b = Highbubblemover;
def b1 = b + 1;
input Lowbubblemover = 7;
def bm = Lowbubblemover;
def bm1 = bm + 1;

AddChartBubble(bubbles and IsNaN(close[b]) and !IsNaN(close[b1]) and
               HighD[b1], HighD[b1], "HD\n" + AsText(HighD[b1]), HighD.TakeValueColor());
AddChartBubble(bubbles and IsNaN(close[bm]) and !IsNaN(close[bm1]) and
               LowD[bm1], LowD[bm1], "LD\n" + AsText(LowD[bm1]), LowD.TakeValueColor(), no);

AddChartBubble(bubbles and IsNaN(close[b]) and !IsNaN(close[b1]) and
               HighW[b1], HighW[b1], "HW\n" + AsText(HighW[b1]), HighW.TakeValueColor());
AddChartBubble(bubbles and IsNaN(close[bm]) and !IsNaN(close[bm1]) and
               LowW[bm1], LowW[bm1], "LW\n" + AsText(LowW[bm1]), LowW.TakeValueColor(), no);

AddChartBubble(bubbles and IsNaN(close[b]) and !IsNaN(close[b1]) and
               HighM[b1], HighM[b1], "HM\n" + AsText(HighM[b1]), HighM.TakeValueColor());
AddChartBubble(bubbles and IsNaN(close[bm]) and !IsNaN(close[bm1]) and
               LowM[bm1], LowM[bm1], "LM\n" + AsText(LowM[bm1]), LowM.TakeValueColor(), no);

AddChartBubble(bubbles and IsNaN(close[b]) and !IsNaN(close[b1]) and
               HighQ[b1], HighQ[b1], "HQ\n" + AsText(HighQ[b1]), HighQ.TakeValueColor());
AddChartBubble(bubbles and IsNaN(close[bm]) and !IsNaN(close[bm1]) and
               LowQ[bm1], LowQ[bm1], "LQ\n" + AsText(LowQ[bm1]), LowQ.TakeValueColor(), no);

AddChartBubble(bubbles and IsNaN(close[b]) and !IsNaN(close[b1]) and
               HighY[b1], HighY[b1], "HY\n" + AsText(HighY[b1]), HighY.TakeValueColor());
AddChartBubble(bubbles and IsNaN(close[bm]) and !IsNaN(close[bm1]) and
               LowY[bm1], LowY[bm1], "LY\n" + AsText(LowY[bm1]), LowY.TakeValueColor(), no);
 
This should help
Dude, this is a beautiful thing! Thank you! So I just changed the dashed lines to solid, my only modification. I see it showing on all timeframes except the Weekly chart, but maybe thats because the new trading week hasnt opened yet, so I will check again during market hours, and let you know whats up. So far this is awesome.
Questions i think I know the answer is already no to lol:
1. are you able to use text labels instead of bubbles? I think i read thats not possible in thinkscript.
2. are we able to control line weight at all? like set a line weight of 2 instead of one? I think i read the same as above on this one also haha.
Again thank you!
 
So this is pretty awesome, once the week started, all the levels were good, except on the weekly chart, where it doesnt show any of the lines or bubbles. Wondering why, code looks ok.

Thanks for letting me know! This should fix that.

Capture.jpg
Ruby:
input periodsback = 1;

def HD;
def LD;
plot HighD;
plot LowD;

if GetAggregationPeriod() <= AggregationPeriod.DAY {
    HD = if IsNaN(close) then HD[1] else high(period = "DAY")[periodsback];
    LD = if IsNaN(close) then LD[1] else low(period  = "DAY" )[periodsback];
    HighD = if IsNaN(high(period = "DAY")[-1]) then HD else Double.NaN;
    LowD  = if IsNaN(low(period = "DAY")[-1]) then LD else Double.NaN;
} else {
    HD = Double.NaN;
    LD = Double.NaN;
    HighD = Double.NaN;
    LowD = Double.NaN;
}

HighD.SetDefaultColor (Color.GREEN);
HighD.SetPaintingStrategy(PaintingStrategy.DASHES);
LowD.SetDefaultColor(Color.RED);
LowD.SetPaintingStrategy(PaintingStrategy.DASHES);

def HW;
def LW;
plot HighW;
plot LowW;

if GetAggregationPeriod() <= AggregationPeriod.WEEK {
    HW = if IsNaN(close) then HW[1] else high(period = "WEEK" )[periodsback];
    LW = if IsNaN(close) then LW[1] else low(period  = "WEEK" )[periodsback];
    HighW = if IsNaN(high(period = "WEEK")[-1]) then HW else Double.NaN;
    LowW  = if IsNaN(low(period = "WEEK")[-1]) then LW else Double.NaN;
} else {
    HW = Double.NaN;
    LW = Double.NaN;
    HighW = Double.NaN;
    LowW = Double.NaN;
}

HighW.SetDefaultColor (Color.GREEN);
HighW.SetPaintingStrategy(PaintingStrategy.DASHES);
LowW.SetDefaultColor(Color.RED);
LowW.SetPaintingStrategy(PaintingStrategy.DASHES);

def HM;
def LM;
plot HighM;
plot LowM;

if GetAggregationPeriod() <= AggregationPeriod.MONTH {
    HM = if IsNaN(close) then HM[1] else high(period = "MONTH" )[periodsback];
    LM = if IsNaN(close) then LM[1] else low(period  = "MONTH" )[periodsback];
    HighM = if IsNaN(high(period = "MONTH")[-1]) then HM else Double.NaN;
    LowM  = if IsNaN(low(period = "MONTH")[-1]) then LM else Double.NaN;
} else {
    HM = Double.NaN;
    LM = Double.NaN;
    HighM = Double.NaN;
    LowM = Double.NaN;
}
HighM.SetDefaultColor (Color.GREEN);
HighM.SetPaintingStrategy(PaintingStrategy.DASHES);
LowM.SetDefaultColor(Color.RED);
LowM.SetPaintingStrategy(PaintingStrategy.DASHES);

def HQ;
def LQ;
plot HighQ;
plot LowQ;

if GetAggregationPeriod() <= AggregationPeriod.QUARTER {
    HQ = if IsNaN(close) then HQ[1] else high(period = "QUARTER" )[periodsback];
    LQ = if IsNaN(close) then LQ[1] else low(period  = "QUARTER" )[periodsback];
    HighQ = if IsNaN(high(period = "QUARTER")[-1]) then HQ else Double.NaN;
    LowQ  = if IsNaN(low(period = "QUARTER")[-1]) then LQ else Double.NaN;
} else {
    HQ = Double.NaN;
    LQ = Double.NaN;
    HighQ = Double.NaN;
    LowQ = Double.NaN;
}

HighQ.SetDefaultColor (Color.GREEN);
HighQ.SetPaintingStrategy(PaintingStrategy.DASHES);
LowQ.SetDefaultColor(Color.RED);
LowQ.SetPaintingStrategy(PaintingStrategy.DASHES);

def HY = if IsNaN(close) then HY[1] else high(period = "YEAR" )[periodsback];
def LY = if IsNaN(close) then LY[1] else low(period  = "YEAR" )[periodsback];
plot HighY = if IsNaN(high(period = "YEAR")[-1]) then HY else Double.NaN;
plot LowY  = if IsNaN(low(period = "YEAR")[-1]) then LY else Double.NaN;

HighY.SetDefaultColor (Color.GREEN);
HighY.SetPaintingStrategy(PaintingStrategy.DASHES);
LowY.SetDefaultColor(Color.RED);
LowY.SetPaintingStrategy(PaintingStrategy.DASHES);

input bubbles     = yes;
input Highbubblemover = 2;
def b = Highbubblemover;
def b1 = b + 1;
input Lowbubblemover = 7;
def bm = Lowbubblemover;
def bm1 = bm + 1;

AddChartBubble(bubbles and IsNaN(close[b]) and !IsNaN(close[b1]) and
               HighD[b1], HighD[b1], "HD\n" + AsText(HighD[b1]), HighD.TakeValueColor());
AddChartBubble(bubbles and IsNaN(close[bm]) and !IsNaN(close[bm1]) and
               LowD[bm1], LowD[bm1], "LD\n" + AsText(LowD[bm1]), LowD.TakeValueColor(), no);

AddChartBubble(bubbles and IsNaN(close[b]) and !IsNaN(close[b1]) and
               HighW[b1], HighW[b1], "HW\n" + AsText(HighW[b1]), HighW.TakeValueColor());
AddChartBubble(bubbles and IsNaN(close[bm]) and !IsNaN(close[bm1]) and
               LowW[bm1], LowW[bm1], "LW\n" + AsText(LowW[bm1]), LowW.TakeValueColor(), no);

AddChartBubble(bubbles and IsNaN(close[b]) and !IsNaN(close[b1]) and
               HighM[b1], HighM[b1], "HM\n" + AsText(HighM[b1]), HighM.TakeValueColor());
AddChartBubble(bubbles and IsNaN(close[bm]) and !IsNaN(close[bm1]) and
               LowM[bm1], LowM[bm1], "LM\n" + AsText(LowM[bm1]), LowM.TakeValueColor(), no);

AddChartBubble(bubbles and IsNaN(close[b]) and !IsNaN(close[b1]) and
               HighQ[b1], HighQ[b1], "HQ\n" + AsText(HighQ[b1]), HighQ.TakeValueColor());
AddChartBubble(bubbles and IsNaN(close[bm]) and !IsNaN(close[bm1]) and
               LowQ[bm1], LowQ[bm1], "LQ\n" + AsText(LowQ[bm1]), LowQ.TakeValueColor(), no);

AddChartBubble(bubbles and IsNaN(close[b]) and !IsNaN(close[b1]) and
               HighY[b1], HighY[b1], "HY\n" + AsText(HighY[b1]), HighY.TakeValueColor());
AddChartBubble(bubbles and IsNaN(close[bm]) and !IsNaN(close[bm1]) and
               LowY[bm1], LowY[bm1], "LY\n" + AsText(LowY[bm1]), LowY.TakeValueColor(), no);
 
That did it, thanks so much!
So I made some changes , basically dashes to lines, and formatting the price and label onto one line. Works on the original chart with no issue. If I detach and clear otu all studies and add this one back, it shows the lines but no bubbles, cant understand why its good on one and not on the other. Is it all working for you on a brand new chart? Here are my changes:


Code:
input periodsback = 1;

def HD;
def LD;
plot HighD;
plot LowD;

if GetAggregationPeriod() <= AggregationPeriod.DAY {
    HD = if IsNaN(close) then HD[1] else high(period = "DAY")[periodsback];
    LD = if IsNaN(close) then LD[1] else low(period  = "DAY" )[periodsback];
    HighD = if IsNaN(high(period = "DAY")[-1]) then HD else Double.NaN;
    LowD  = if IsNaN(low(period = "DAY")[-1]) then LD else Double.NaN;
} else {
    HD = Double.NaN;
    LD = Double.NaN;
    HighD = Double.NaN;
    LowD = Double.NaN;
}

HighD.SetDefaultColor (Color.GREEN);
HighD.SetPaintingStrategy(PaintingStrategy.LINE);
LowD.SetDefaultColor(Color.RED);
LowD.SetPaintingStrategy(PaintingStrategy.LINE);

def HW;
def LW;
plot HighW;
plot LowW;

if GetAggregationPeriod() <= AggregationPeriod.WEEK {
    HW = if IsNaN(close) then HW[1] else high(period = "WEEK" )[periodsback];
    LW = if IsNaN(close) then LW[1] else low(period  = "WEEK" )[periodsback];
    HighW = if IsNaN(high(period = "WEEK")[-1]) then HW else Double.NaN;
    LowW  = if IsNaN(low(period = "WEEK")[-1]) then LW else Double.NaN;
} else {
    HW = Double.NaN;
    LW = Double.NaN;
    HighW = Double.NaN;
    LowW = Double.NaN;
}

HighW.SetDefaultColor (Color.GREEN);
HighW.SetPaintingStrategy(PaintingStrategy.LINE);
LowW.SetDefaultColor(Color.RED);
LowW.SetPaintingStrategy(PaintingStrategy.LINE);

def HM;
def LM;
plot HighM;
plot LowM;

if GetAggregationPeriod() <= AggregationPeriod.MONTH {
    HM = if IsNaN(close) then HM[1] else high(period = "MONTH" )[periodsback];
    LM = if IsNaN(close) then LM[1] else low(period  = "MONTH" )[periodsback];
    HighM = if IsNaN(high(period = "MONTH")[-1]) then HM else Double.NaN;
    LowM  = if IsNaN(low(period = "MONTH")[-1]) then LM else Double.NaN;
} else {
    HM = Double.NaN;
    LM = Double.NaN;
    HighM = Double.NaN;
    LowM = Double.NaN;
}
HighM.SetDefaultColor (Color.GREEN);
HighM.SetPaintingStrategy(PaintingStrategy.LINE);
LowM.SetDefaultColor(Color.RED);
LowM.SetPaintingStrategy(PaintingStrategy.LINE);

def HQ;
def LQ;
plot HighQ;
plot LowQ;

if GetAggregationPeriod() <= AggregationPeriod.QUARTER {
    HQ = if IsNaN(close) then HQ[1] else high(period = "QUARTER" )[periodsback];
    LQ = if IsNaN(close) then LQ[1] else low(period  = "QUARTER" )[periodsback];
    HighQ = if IsNaN(high(period = "QUARTER")[-1]) then HQ else Double.NaN;
    LowQ  = if IsNaN(low(period = "QUARTER")[-1]) then LQ else Double.NaN;
} else {
    HQ = Double.NaN;
    LQ = Double.NaN;
    HighQ = Double.NaN;
    LowQ = Double.NaN;
}

HighQ.SetDefaultColor (Color.GREEN);
HighQ.SetPaintingStrategy(PaintingStrategy.LINE);
LowQ.SetDefaultColor(Color.RED);
LowQ.SetPaintingStrategy(PaintingStrategy.LINE);

def HY = if IsNaN(close) then HY[1] else high(period = "YEAR" )[periodsback];
def LY = if IsNaN(close) then LY[1] else low(period  = "YEAR" )[periodsback];
plot HighY = if IsNaN(high(period = "YEAR")[-1]) then HY else Double.NaN;
plot LowY  = if IsNaN(low(period = "YEAR")[-1]) then LY else Double.NaN;

HighY.SetDefaultColor (Color.GREEN);
HighY.SetPaintingStrategy(PaintingStrategy.LINE);
LowY.SetDefaultColor(Color.RED);
LowY.SetPaintingStrategy(PaintingStrategy.LINE);

input bubbles     = yes;
input Highbubblemover = 2;
def b = Highbubblemover;
def b1 = b + 1;
input Lowbubblemover = 7;
def bm = Lowbubblemover;
def bm1 = bm + 1;

AddChartBubble(bubbles and IsNaN(close[b]) and !IsNaN(close[b1]) and
               HighD[b1], HighD[b1], "HD " + AsText(HighD[b1]), HighD.TakeValueColor());
AddChartBubble(bubbles and IsNaN(close[bm]) and !IsNaN(close[bm1]) and
               LowD[bm1], LowD[bm1], "LD " + AsText(LowD[bm1]), LowD.TakeValueColor(), no);

AddChartBubble(bubbles and IsNaN(close[b]) and !IsNaN(close[b1]) and
               HighW[b1], HighW[b1], "HW " + AsText(HighW[b1]), HighW.TakeValueColor());
AddChartBubble(bubbles and IsNaN(close[bm]) and !IsNaN(close[bm1]) and
               LowW[bm1], LowW[bm1], "LW " + AsText(LowW[bm1]), LowW.TakeValueColor(), no);

AddChartBubble(bubbles and IsNaN(close[b]) and !IsNaN(close[b1]) and
               HighM[b1], HighM[b1], "HM " + AsText(HighM[b1]), HighM.TakeValueColor());
AddChartBubble(bubbles and IsNaN(close[bm]) and !IsNaN(close[bm1]) and
               LowM[bm1], LowM[bm1], "LM " + AsText(LowM[bm1]), LowM.TakeValueColor(), no);

AddChartBubble(bubbles and IsNaN(close[b]) and !IsNaN(close[b1]) and
               HighQ[b1], HighQ[b1], "HQ " + AsText(HighQ[b1]), HighQ.TakeValueColor());
AddChartBubble(bubbles and IsNaN(close[bm]) and !IsNaN(close[bm1]) and
               LowQ[bm1], LowQ[bm1], "LQ " + AsText(LowQ[bm1]), LowQ.TakeValueColor(), no);

AddChartBubble(bubbles and IsNaN(close[b]) and !IsNaN(close[b1]) and
               HighY[b1], HighY[b1], "HY " + AsText(HighY[b1]), HighY.TakeValueColor());
AddChartBubble(bubbles and IsNaN(close[bm]) and !IsNaN(close[bm1]) and
               LowY[bm1], LowY[bm1], "LY " + AsText(LowY[bm1]), LowY.TakeValueColor(), no);
 
So I made some changes , basically dashes to lines, and formatting the price and label onto one line. Works on the original chart with no issue. If I detach and clear otu all studies and add this one back, it shows the lines but no bubbles, cant understand why its good on one and not on the other. Is it all working for you on a brand new chart? Here are my changes:


Code:
input periodsback = 1;

def HD;
def LD;
plot HighD;
plot LowD;

if GetAggregationPeriod() <= AggregationPeriod.DAY {
    HD = if IsNaN(close) then HD[1] else high(period = "DAY")[periodsback];
    LD = if IsNaN(close) then LD[1] else low(period  = "DAY" )[periodsback];
    HighD = if IsNaN(high(period = "DAY")[-1]) then HD else Double.NaN;
    LowD  = if IsNaN(low(period = "DAY")[-1]) then LD else Double.NaN;
} else {
    HD = Double.NaN;
    LD = Double.NaN;
    HighD = Double.NaN;
    LowD = Double.NaN;
}

HighD.SetDefaultColor (Color.GREEN);
HighD.SetPaintingStrategy(PaintingStrategy.LINE);
LowD.SetDefaultColor(Color.RED);
LowD.SetPaintingStrategy(PaintingStrategy.LINE);

def HW;
def LW;
plot HighW;
plot LowW;

if GetAggregationPeriod() <= AggregationPeriod.WEEK {
    HW = if IsNaN(close) then HW[1] else high(period = "WEEK" )[periodsback];
    LW = if IsNaN(close) then LW[1] else low(period  = "WEEK" )[periodsback];
    HighW = if IsNaN(high(period = "WEEK")[-1]) then HW else Double.NaN;
    LowW  = if IsNaN(low(period = "WEEK")[-1]) then LW else Double.NaN;
} else {
    HW = Double.NaN;
    LW = Double.NaN;
    HighW = Double.NaN;
    LowW = Double.NaN;
}

HighW.SetDefaultColor (Color.GREEN);
HighW.SetPaintingStrategy(PaintingStrategy.LINE);
LowW.SetDefaultColor(Color.RED);
LowW.SetPaintingStrategy(PaintingStrategy.LINE);

def HM;
def LM;
plot HighM;
plot LowM;

if GetAggregationPeriod() <= AggregationPeriod.MONTH {
    HM = if IsNaN(close) then HM[1] else high(period = "MONTH" )[periodsback];
    LM = if IsNaN(close) then LM[1] else low(period  = "MONTH" )[periodsback];
    HighM = if IsNaN(high(period = "MONTH")[-1]) then HM else Double.NaN;
    LowM  = if IsNaN(low(period = "MONTH")[-1]) then LM else Double.NaN;
} else {
    HM = Double.NaN;
    LM = Double.NaN;
    HighM = Double.NaN;
    LowM = Double.NaN;
}
HighM.SetDefaultColor (Color.GREEN);
HighM.SetPaintingStrategy(PaintingStrategy.LINE);
LowM.SetDefaultColor(Color.RED);
LowM.SetPaintingStrategy(PaintingStrategy.LINE);

def HQ;
def LQ;
plot HighQ;
plot LowQ;

if GetAggregationPeriod() <= AggregationPeriod.QUARTER {
    HQ = if IsNaN(close) then HQ[1] else high(period = "QUARTER" )[periodsback];
    LQ = if IsNaN(close) then LQ[1] else low(period  = "QUARTER" )[periodsback];
    HighQ = if IsNaN(high(period = "QUARTER")[-1]) then HQ else Double.NaN;
    LowQ  = if IsNaN(low(period = "QUARTER")[-1]) then LQ else Double.NaN;
} else {
    HQ = Double.NaN;
    LQ = Double.NaN;
    HighQ = Double.NaN;
    LowQ = Double.NaN;
}

HighQ.SetDefaultColor (Color.GREEN);
HighQ.SetPaintingStrategy(PaintingStrategy.LINE);
LowQ.SetDefaultColor(Color.RED);
LowQ.SetPaintingStrategy(PaintingStrategy.LINE);

def HY = if IsNaN(close) then HY[1] else high(period = "YEAR" )[periodsback];
def LY = if IsNaN(close) then LY[1] else low(period  = "YEAR" )[periodsback];
plot HighY = if IsNaN(high(period = "YEAR")[-1]) then HY else Double.NaN;
plot LowY  = if IsNaN(low(period = "YEAR")[-1]) then LY else Double.NaN;

HighY.SetDefaultColor (Color.GREEN);
HighY.SetPaintingStrategy(PaintingStrategy.LINE);
LowY.SetDefaultColor(Color.RED);
LowY.SetPaintingStrategy(PaintingStrategy.LINE);

input bubbles     = yes;
input Highbubblemover = 2;
def b = Highbubblemover;
def b1 = b + 1;
input Lowbubblemover = 7;
def bm = Lowbubblemover;
def bm1 = bm + 1;

AddChartBubble(bubbles and IsNaN(close[b]) and !IsNaN(close[b1]) and
               HighD[b1], HighD[b1], "HD " + AsText(HighD[b1]), HighD.TakeValueColor());
AddChartBubble(bubbles and IsNaN(close[bm]) and !IsNaN(close[bm1]) and
               LowD[bm1], LowD[bm1], "LD " + AsText(LowD[bm1]), LowD.TakeValueColor(), no);

AddChartBubble(bubbles and IsNaN(close[b]) and !IsNaN(close[b1]) and
               HighW[b1], HighW[b1], "HW " + AsText(HighW[b1]), HighW.TakeValueColor());
AddChartBubble(bubbles and IsNaN(close[bm]) and !IsNaN(close[bm1]) and
               LowW[bm1], LowW[bm1], "LW " + AsText(LowW[bm1]), LowW.TakeValueColor(), no);

AddChartBubble(bubbles and IsNaN(close[b]) and !IsNaN(close[b1]) and
               HighM[b1], HighM[b1], "HM " + AsText(HighM[b1]), HighM.TakeValueColor());
AddChartBubble(bubbles and IsNaN(close[bm]) and !IsNaN(close[bm1]) and
               LowM[bm1], LowM[bm1], "LM " + AsText(LowM[bm1]), LowM.TakeValueColor(), no);

AddChartBubble(bubbles and IsNaN(close[b]) and !IsNaN(close[b1]) and
               HighQ[b1], HighQ[b1], "HQ " + AsText(HighQ[b1]), HighQ.TakeValueColor());
AddChartBubble(bubbles and IsNaN(close[bm]) and !IsNaN(close[bm1]) and
               LowQ[bm1], LowQ[bm1], "LQ " + AsText(LowQ[bm1]), LowQ.TakeValueColor(), no);

AddChartBubble(bubbles and IsNaN(close[b]) and !IsNaN(close[b1]) and
               HighY[b1], HighY[b1], "HY " + AsText(HighY[b1]), HighY.TakeValueColor());
AddChartBubble(bubbles and IsNaN(close[bm]) and !IsNaN(close[bm1]) and
               LowY[bm1], LowY[bm1], "LY " + AsText(LowY[bm1]), LowY.TakeValueColor(), no);
The bubblemovers move the bubbles sideways and have settings of 2 and 7. So you need room in the expansion area for them to display. Once you put the price on the same line as the descriptive part of the bubble, then even more space in the expansion area is needed.

Go to chart settings, time axis, expansion area and make sure you have some number of bars there. If necessary, increase the bars to allow the bubbles to display you want.

Here is a chart share link with only your code, an expansion setting of 10 bars and the bubbles displaying https://tos.mx/R1wGskT
 
The bubblemovers move the bubbles sideways and have settings of 2 and 7. So you need room in the expansion area for them to display. Once you put the price on the same line as the descriptive part of the bubble, then even more space in the expansion area is needed.

Go to chart settings, time axis, expansion area and make sure you have some number of bars there. If necessary, increase the bars to allow the bubbles to display you want.

Here is a chart share link with only your code, an expansion setting of 10 bars and the bubbles displaying https://tos.mx/R1wGskT
Good call, i have those 10 bars on the time axis on all my regular charts. Thanks!
 

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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