# Plot 25% and 50% of previous day’s range?

##### Active member
2019 Donor
VIP
Could someone make this code, plot the 25% and 50% extension of the previous day's range automatically @Trading51 Per your request, here is a study that plots the 25% and 50% extension of the previous day's range. This is to be used on intraday charts only

Code:
``````# Range Extension of Previous Day Range
# tomsk
# 1.11.2020

# This study plots the 25% and 50% extension of the previous day's range
# To be used on intraday charts only

declare hide_on_daily;

def CurrentDay = GetDay() == GetLastDay();
def prevHigh = if CurrentDay then high(period = AggregationPeriod.Day) else Double.NaN;
def prevLow = if CurrentDay then low(period = AggregationPeriod.Day) else Double.NaN;
def prevRange = if CurrentDay then prevHigh - prevLow else Double.NaN;

plot UExt25 = prevHigh + (prevRange * 0.25);
plot UExt50 = prevHigh + (prevRange * 0.50);
plot LExt25 = prevLow  - (prevRange * 0.25);
plot LExt50 = prevLow  - (prevRange * 0.50);

UExt25.SetDefaultColor(Color.Cyan);
UExt50.SetDefaultColor(Color.Pink);
LExt25.SetDefaultColor(Color.White);
LExt50.SetDefaultColor(Color.Green);

# End Range Extension of Previous Day Range``````

• perfect thank you, is it possible to add the previous day's midpoint?

perfect thank you, is it possible to add the previous day's midpoint?

Here is version 1.1 of the Range Extension study with the previous day's midpoint plotted as dotted yellow line to make it distinct from the other plots

Code:
``````# Range Extension of Previous Day Range
# tomsk
# 1.11.2020

# V1.0 - 01.11.2020 - tomsk - Range Extension of Previous Day Range
# V1.1 - 01.11.2020 - tomsk - Added plot of previous day range midpoint

# This study plots the 25% and 50% extension of the previous day's range
# To be used on intraday charts only

declare hide_on_daily;

def CurrentDay = GetDay() == GetLastDay();
def prevHigh = if CurrentDay then high(period = AggregationPeriod.Day) else Double.NaN;
def prevLow = if CurrentDay then low(period = AggregationPeriod.Day) else Double.NaN;
def prevRange = if CurrentDay then prevHigh - prevLow else Double.NaN;

plot UExt25 = prevHigh + (prevRange * 0.25);
plot UExt50 = prevHigh + (prevRange * 0.50);
plot LExt25 = prevLow  - (prevRange * 0.25);
plot LExt50 = prevLow  - (prevRange * 0.50);
plot PrevMid = prevLow + (prevRange / 2);

UExt25.SetDefaultColor(Color.Cyan);
UExt50.SetDefaultColor(Color.Pink);
LExt25.SetDefaultColor(Color.White);
LExt50.SetDefaultColor(Color.Green);

PrevMid.SetDefaultColor(Color.Yellow);
PrevMid.SetStyle(Curve.Short_Dash);
PrevMid.SetLineWeight(3);

# End Range Extension of Previous Day Range``````

perfect, if I wanted to use that on a higher time frame like the weekly, what would I have to adjust in the code would it be simple?

perfect, if I wanted to use that on a higher time frame like the weekly, what would I have to adjust in the code would it be simple?

@Trading51 OK, here is a study that plots the 25% and 50% extension of the previous week's range. Remember this is to be used on intraday charts only

Code:
``````# Range Extension of Previous Week Range
# tomsk
# 1.11.2020

# This study plots the 25% and 50% extension of the previous week's range
# To be used on intraday charts only

declare hide_on_daily;

def CurrentDay = GetDay() == GetLastDay();
def prevHigh = if CurrentDay then high(period = AggregationPeriod.Week) else Double.NaN;
def prevLow = if CurrentDay then low(period = AggregationPeriod.Week) else Double.NaN;
def prevRange = if CurrentDay then prevHigh - prevLow else Double.NaN;

plot UExt25 = prevHigh + (prevRange * 0.25);
plot UExt50 = prevHigh + (prevRange * 0.50);
plot LExt25 = prevLow  - (prevRange * 0.25);
plot LExt50 = prevLow  - (prevRange * 0.50);
plot PrevMid = prevLow + (prevRange / 2);

UExt25.SetDefaultColor(Color.Cyan);
UExt50.SetDefaultColor(Color.Pink);
LExt25.SetDefaultColor(Color.White);
LExt50.SetDefaultColor(Color.Green);

PrevMid.SetDefaultColor(Color.Yellow);
PrevMid.SetStyle(Curve.Short_Dash);
PrevMid.SetLineWeight(3);

# End Range Extension of Previous Week Range``````

• @tomsk thanks for taking the time and doing this, cheers mate!

@tomsk thanks for taking the time and doing this, cheers mate!

Glad to help @Trading51 I had the essential framework from a similar study I did for a forum requestor a few days ago and it was a seamless extension to meet your requirements

I gave it a shot to add a label but I can tell I'm way off, this is what I have (addchartBubble price location" = PrevHigh, text = "+25% Ext " color = Color.White); Zero coding ability I gave it a shot to add a label but I can tell I'm way off, this is what I have (addchartBubble price location" = PrevHigh, text = "+25% Ext " color = Color.White); Zero coding ability @Trading51 Adding chart bubbles is a bit more involved than that. Since you asked, here then is Version 1.2 of the Range Extension of Previous Day Range study COMPLETE with chart bubbles added to all 5 plots. Have at it ...

Code:
``````# Range Extension of Previous Day Range
# tomsk
# 1.11.2020

# V1.0 - 01.11.2020 - tomsk - Range Extension of Previous Day Range
# V1.1 - 01.11.2020 - tomsk - Added plot of previous day range midpoint
# V1.2 - 01.11.2020 - tomsk - Added chart bubbles to identify all plot lines

# This study plots the 25% and 50% extension of the previous day's range
# To be used on intraday charts only

declare hide_on_daily;

input n = 3;

def bar = barNumber();
def CurrentDay = GetDay() == GetLastDay();
def prevHigh = if CurrentDay then high(period = AggregationPeriod.Day) else Double.NaN;
def prevLow = if CurrentDay then low(period = AggregationPeriod.Day) else Double.NaN;
def prevRange = if CurrentDay then prevHigh - prevLow else Double.NaN;

plot UExt25 = prevHigh + (prevRange * 0.25);
plot UExt50 = prevHigh + (prevRange * 0.50);
plot LExt25 = prevLow  - (prevRange * 0.25);
plot LExt50 = prevLow  - (prevRange * 0.50);
plot PrevMid = prevLow + (prevRange / 2);

UExt25.SetDefaultColor(Color.Cyan);
UExt50.SetDefaultColor(Color.Pink);
LExt25.SetDefaultColor(Color.White);
LExt50.SetDefaultColor(Color.Green);

PrevMid.SetDefaultColor(Color.Yellow);
PrevMid.SetStyle(Curve.Short_Dash);
PrevMid.SetLineWeight(3);

def lastBar = if isNaN(close[-1]) and !isNaN(close) then bar else lastBar;
def UExt25Loc = if isNaN(close[-1]) and !isNaN(close) then UExt25 else UExt25Loc;
def UExt50Loc = if isNaN(close[-1]) and !isNaN(close) then UExt50 else UExt50Loc;
def PrevMidLoc = if isNaN(close[-1]) and !isNaN(close) then PrevMid else PrevMidLoc;
def LExt25Loc = if isNaN(close[-1]) and !isNaN(close) then LExt25 else LExt25Loc;
def LExt50Loc = if isNaN(close[-1]) and !isNaN(close) then LExt50 else LExt50Loc;

addChartBubble(bar == HighestAll(lastBar+n), UExt25Loc, "Upper 25%", UExt25.TakeValueColor());
addChartBubble(bar == HighestAll(lastBar+n), UExt50Loc, "Upper 50%", UExt50.TakeValueColor());
addChartBubble(bar == HighestAll(lastBar+n), PrevMidLoc, "Prev Mid", PrevMid.TakeValueColor());
addChartBubble(bar == HighestAll(lastBar+n), LExt25Loc, "Lower 25%", LExt25.TakeValueColor());
addChartBubble(bar == HighestAll(lastBar+n), LExt50Loc, "Lower 50%", LExt50.TakeValueColor());
# End Range Extension of Previous Day Range``````

• @Trading51 Adding chart bubbles is a bit more involved than that. Since you asked, here then is Version 1.2 of the Range Extension of Previous Day Range study COMPLETE with chart bubbles added to all 5 plots. Have at it ...

Code:
``````# Range Extension of Previous Day Range
# tomsk
# 1.11.2020

# V1.0 - 01.11.2020 - tomsk - Range Extension of Previous Day Range
# V1.1 - 01.11.2020 - tomsk - Added plot of previous day range midpoint
# V1.2 - 01.11.2020 - tomsk - Added chart bubbles to identify all plot lines

# This study plots the 25% and 50% extension of the previous day's range
# To be used on intraday charts only

declare hide_on_daily;

input n = 3;

def bar = barNumber();
def CurrentDay = GetDay() == GetLastDay();
def prevHigh = if CurrentDay then high(period = AggregationPeriod.Day) else Double.NaN;
def prevLow = if CurrentDay then low(period = AggregationPeriod.Day) else Double.NaN;
def prevRange = if CurrentDay then prevHigh - prevLow else Double.NaN;

plot UExt25 = prevHigh + (prevRange * 0.25);
plot UExt50 = prevHigh + (prevRange * 0.50);
plot LExt25 = prevLow  - (prevRange * 0.25);
plot LExt50 = prevLow  - (prevRange * 0.50);
plot PrevMid = prevLow + (prevRange / 2);

UExt25.SetDefaultColor(Color.Cyan);
UExt50.SetDefaultColor(Color.Pink);
LExt25.SetDefaultColor(Color.White);
LExt50.SetDefaultColor(Color.Green);

PrevMid.SetDefaultColor(Color.Yellow);
PrevMid.SetStyle(Curve.Short_Dash);
PrevMid.SetLineWeight(3);

def lastBar = if isNaN(close[-1]) and !isNaN(close) then bar else lastBar;
def UExt25Loc = if isNaN(close[-1]) and !isNaN(close) then UExt25 else UExt25Loc;
def UExt50Loc = if isNaN(close[-1]) and !isNaN(close) then UExt50 else UExt50Loc;
def PrevMidLoc = if isNaN(close[-1]) and !isNaN(close) then PrevMid else PrevMidLoc;
def LExt25Loc = if isNaN(close[-1]) and !isNaN(close) then LExt25 else LExt25Loc;
def LExt50Loc = if isNaN(close[-1]) and !isNaN(close) then LExt50 else LExt50Loc;

addChartBubble(bar == HighestAll(lastBar+n), UExt25Loc, "Upper 25%", UExt25.TakeValueColor());
addChartBubble(bar == HighestAll(lastBar+n), UExt50Loc, "Upper 50%", UExt50.TakeValueColor());
addChartBubble(bar == HighestAll(lastBar+n), PrevMidLoc, "Prev Mid", PrevMid.TakeValueColor());
addChartBubble(bar == HighestAll(lastBar+n), LExt25Loc, "Lower 25%", LExt25.TakeValueColor());
addChartBubble(bar == HighestAll(lastBar+n), LExt50Loc, "Lower 50%", LExt50.TakeValueColor());
# End Range Extension of Previous Day Range``````
I was way off, thanks @tomsk could you add the option to add the previous high and low with the labels?

@tomsk could you add the option to add the previous high and low with the labels?

@Trading51 Sure thing, here's Version 1.3 of the code with the previous day's high/low added

Code:
``````# Range Extension of Previous Day Range
# tomsk
# 1.12.2020

# V1.0 - 01.11.2020 - tomsk - Range Extension of Previous Day Range
# V1.1 - 01.11.2020 - tomsk - Added plot of previous day range midpoint
# V1.2 - 01.11.2020 - tomsk - Added chart bubbles to identify all plot lines
# V1.3 - 01.12.2020 - tomsk - Added labels for previous day's high/low

# This study plots the 25% and 50% extension of the previous day's range
# To be used on intraday charts only

declare hide_on_daily;

input n = 3;

def bar = barNumber();
def CurrentDay = GetDay() == GetLastDay();
def prevHigh = if CurrentDay then high(period = AggregationPeriod.Day) else Double.NaN;
def prevLow = if CurrentDay then low(period = AggregationPeriod.Day) else Double.NaN;
def prevRange = if CurrentDay then prevHigh - prevLow else Double.NaN;

plot UExt25 = prevHigh + (prevRange * 0.25);
plot UExt50 = prevHigh + (prevRange * 0.50);
plot LExt25 = prevLow  - (prevRange * 0.25);
plot LExt50 = prevLow  - (prevRange * 0.50);
plot PrevMid = prevLow + (prevRange / 2);

UExt25.SetDefaultColor(Color.Cyan);
UExt50.SetDefaultColor(Color.Pink);
LExt25.SetDefaultColor(Color.White);
LExt50.SetDefaultColor(Color.Green);

PrevMid.SetDefaultColor(Color.Yellow);
PrevMid.SetStyle(Curve.Short_Dash);
PrevMid.SetLineWeight(3);

AddLabel(1, "Previous Day's High = " + prevHigh, Color.Yellow);
AddLabel(1, "Previous Day's Low = " + prevLow, Color.Pink);

def lastBar = if isNaN(close[-1]) and !isNaN(close) then bar else lastBar;
def UExt25Loc = if isNaN(close[-1]) and !isNaN(close) then UExt25 else UExt25Loc;
def UExt50Loc = if isNaN(close[-1]) and !isNaN(close) then UExt50 else UExt50Loc;
def PrevMidLoc = if isNaN(close[-1]) and !isNaN(close) then PrevMid else PrevMidLoc;
def LExt25Loc = if isNaN(close[-1]) and !isNaN(close) then LExt25 else LExt25Loc;
def LExt50Loc = if isNaN(close[-1]) and !isNaN(close) then LExt50 else LExt50Loc;

addChartBubble(bar == HighestAll(lastBar+n), UExt25Loc, "Upper 25%", UExt25.TakeValueColor());
addChartBubble(bar == HighestAll(lastBar+n), UExt50Loc, "Upper 50%", UExt50.TakeValueColor());
addChartBubble(bar == HighestAll(lastBar+n), PrevMidLoc, "Prev Mid", PrevMid.TakeValueColor());
addChartBubble(bar == HighestAll(lastBar+n), LExt25Loc, "Lower 25%", LExt25.TakeValueColor());
addChartBubble(bar == HighestAll(lastBar+n), LExt50Loc, "Lower 50%", LExt50.TakeValueColor());
# End Range Extension of Previous Day Range``````

• the labels you added are fine, I meant could you add the previous high and low lines with labels that go with the ones on the charts? sorry for the confusion @Trading51 Per your enhanced request, I have made the changes you requested in the revised version 1.3. Additionally to give you an added option, I have included an input "displayLabel" that you can set to "no" in the user interface should you no longer wish to see the labels. Here then is the revised code. Hope this helps

Code:
``````# Range Extension of Previous Day Range
# tomsk
# 1.12.2020

# V1.0 - 01.11.2020 - tomsk - Range Extension of Previous Day Range
# V1.1 - 01.11.2020 - tomsk - Added plot of previous day range midpoint
# V1.2 - 01.11.2020 - tomsk - Added chart bubbles to identify all plot lines
# V1.3 - 01.12.2020 - tomsk - Added labels and plot lines for previous day's high/low

# This study plots the 25% and 50% extension of the previous day's range
# To be used on intraday charts only

declare hide_on_daily;

input n = 3;
input displayLabel = yes;

def bar = barNumber();
def CurrentDay = GetDay() == GetLastDay();
def prevHigh = if CurrentDay then high(period = AggregationPeriod.Day) else Double.NaN;
def prevLow = if CurrentDay then low(period = AggregationPeriod.Day) else Double.NaN;
def prevRange = if CurrentDay then prevHigh - prevLow else Double.NaN;

plot UExt25 = prevHigh + (prevRange * 0.25);
plot UExt50 = prevHigh + (prevRange * 0.50);
plot LExt25 = prevLow  - (prevRange * 0.25);
plot LExt50 = prevLow  - (prevRange * 0.50);

plot PrevHigh_ = prevHigh;
plot PrevLow_ = prevLow;
plot PrevMid = prevLow + (prevRange / 2);

UExt25.SetDefaultColor(Color.Cyan);
UExt50.SetDefaultColor(Color.Pink);
LExt25.SetDefaultColor(Color.White);
LExt50.SetDefaultColor(Color.Green);

PrevHigh_.SetDefaultColor(Color.Green);
PrevHigh_.SetStyle(Curve.Short_Dash);
PrevHigh_.SetLineWeight(3);
PrevLow_.SetDefaultColor(Color.Red);
PrevLow_.SetStyle(Curve.Short_Dash);
PrevLow_.SetLineWeight(3);
PrevMid.SetDefaultColor(Color.Yellow);
PrevMid.SetStyle(Curve.Short_Dash);
PrevMid.SetLineWeight(3);

AddLabel(displayLabel, "Previous Day's High = " + prevHigh, Color.Yellow);
AddLabel(displayLabel, "Previous Day's Low = " + prevLow, Color.Pink);

def lastBar = if isNaN(close[-1]) and !isNaN(close) then bar else lastBar;
def UExt25Loc = if isNaN(close[-1]) and !isNaN(close) then UExt25 else UExt25Loc;
def UExt50Loc = if isNaN(close[-1]) and !isNaN(close) then UExt50 else UExt50Loc;
def PrevHighLoc = if isNaN(close[-1]) and !isNaN(close) then PrevHigh else PrevHighLoc;
def PrevLowLoc = if isNaN(close[-1]) and !isNaN(close) then PrevLow else PrevLowLoc;
def PrevMidLoc = if isNaN(close[-1]) and !isNaN(close) then PrevMid else PrevMidLoc;
def LExt25Loc = if isNaN(close[-1]) and !isNaN(close) then LExt25 else LExt25Loc;
def LExt50Loc = if isNaN(close[-1]) and !isNaN(close) then LExt50 else LExt50Loc;

addChartBubble(bar == HighestAll(lastBar+n), UExt25Loc, "Upper 25%", UExt25.TakeValueColor());
addChartBubble(bar == HighestAll(lastBar+n), UExt50Loc, "Upper 50%", UExt50.TakeValueColor());
addChartBubble(bar == HighestAll(lastBar+n), PrevHighLoc, "Prev Day High", PrevHigh_.TakeValueColor());
addChartBubble(bar == HighestAll(lastBar+n), PrevLowLoc, "Prev Day Low", PrevLow_.TakeValueColor());
addChartBubble(bar == HighestAll(lastBar+n), PrevMidLoc, "Prev Mid", PrevMid.TakeValueColor());
addChartBubble(bar == HighestAll(lastBar+n), LExt25Loc, "Lower 25%", LExt25.TakeValueColor());
addChartBubble(bar == HighestAll(lastBar+n), LExt50Loc, "Lower 50%", LExt50.TakeValueColor());
# End Range Extension of Previous Day Range``````

Last edited:
• @tomsk thanks for taking the time have a great week!!

@tomsk Could you please add a preference or input that can allow me to click on the previous two days verse the previous day? Thnaks

While the intraday high/low two days ago can easily be determined, logistically balancing the display between the previous day and the previous previous day is going to induce a layer of complexity. My suggestion is to just keep things simple and stick with the last version posted. If you still wish to reference the high/lows 2 days ago, all you need is to index it as follows. Personally I see no value add there.

Code:
``````def prevPrevHigh = if CurrentDay then high(period = AggregationPeriod.Day) else Double.NaN;
def prevPrevLow = if CurrentDay then low(period = AggregationPeriod.Day) else Double.NaN;``````

• @tomsk question if I wanted to change this code to the current day verse the previous day is this all I would have to do is remove the area where its says "Prev" ?

Is it possible to make it plot the history of prior days? Currently, it only plots the levels from one day ago. Thank you.

### Not the exact question you're looking for?

87k+ Posts
135 Online ## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

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?