Extend Price Level to the left towards the Respective Candles ?

AstroBoy

New member
Hey everyone! I'm trying to customize a Technical Indicator Study that plots the Previous Day's High, Previous Day's Close, and Present Day's Pre-Market High.
The study measures what I need it to do, but visually on the chart, how do I code the script so that the Previous Day's High Line and Previous Day's Close Line extends to the left to their respective candles?
The Pre-Market High Line is already on its respective candle, I just need the Day's High and Day's Close to do the same...Here's a visual example of what I am trying to accomplish:
jxfysjcgaoc71.png


And here is the script:

Code:
input aggregationPeriod = AggregationPeriod.DAY;
input length = 1;
input displace = -1;
input showOnlyLastPeriod = yes;

def h = high;
def bar = BarNumber();
def GlobeX = GetTime() < RegularTradingStart(GetYYYYMMDD());
def ONhigh = if GlobeX and !Globex[1]
then h
else if Globex and
h > ONhigh[1]
then h
else ONhigh[1];
def ONhighBar = if GlobeX and h == ONhigh
then Bar
else double.nan;
def OverNightHigh = if BarNumber() == HighestAll(ONhighBar)
then ONhigh
else OverNightHigh[1];

plot PrevDayHigh;
if showOnlyLastPeriod and !IsNaN(high(period = aggregationPeriod)[-1])
{
PrevDayHigh = Double.NaN;
}
else
{
PrevDayHigh = Highest(high(period = aggregationPeriod)[-displace], length);
}

plot PrevDayClose;
if showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1]) { PrevDayClose = Double.NaN;
} else { PrevDayClose = Highest(close(period = aggregationPeriod)[-displace], length);
}

plot PreMarketHigh = if OverNightHigh > 0
then OverNightHigh
else Double.NaN;

Transparency: This script is an aggregation of several other scripts from here and Reddit that I edited to measure the correct price levels I needed it to and be displayed to my preferences
 
Last edited:

halcyonguy

Active member
VIP
====== EDIT ============

i removed my garbled notes from this morning
and am posting a working code, that draws a line from yesterdays high


# ==== EDIT 2 ======
i changed a line of code.
before , sometimes if the highest price existed on an earlier day, the line started on an earlier day.


Ruby:
# linefromprevhigh
def na = double.nan;
def bn = barnumber();

#if you want a line to start on the 2nd to last day, then you need to determine when that is.
input agg = AggregationPeriod.DAY;

# is the next day valid and the one after that invalid?
def day2= ( !isnan(close(period = agg)[-1]) and isnan(close(period = agg)[-2]) );

# find highest high of 2nd day
def hh = highestall( if day2 then high else 0);

#find the bar that matches the highest and keep value thru remaining bars

# ==== EDIT ======
#def lineh = if bn == 1 then na else if high == hh then hh else lineh[1];

def lineh = if bn == 1 then na else if (day2 and high == hh) then hh else lineh[1];
# ==== EDIT ======


plot x = lineh;
x.SetDefaultColor(Color.white);
x.SetStyle(Curve.MEDIUM_DASH);
x.setlineweight(3);
# x.hidebubble();

# last bar  ( most recent)
def lastbar = !isnan(close[0]) and isnan(close[-1]);
#
addchartbubble(lastbar, x, "prev HI", color.green, yes);
#

kMvrPky.jpg
 
Last edited:

AstroBoy

New member
====== EDIT ============

i removed my garbled notes from this morning
and am posting a working code, that draws a line from yesterdays high [...]
I appreciate your insight! The code below is what I currently have, and if I understood you correctly, the solution was to def the highest candlebar from yesterday to plot a line from?

This is the current code that is working for me, courtesy of the forum folks here that helped out with this code:
Code:
input aggregationPeriod = AggregationPeriod.DAY;
input length = 1;
input displace = -1;
input showOnlyLastPeriod = yes;

plot PrevDayHigh;
if showOnlyLastPeriod and !IsNaN(high(period = aggregationPeriod)[-1])
{
PrevDayHigh = Double.NaN;
}
else
{
PrevDayHigh = Highest(high(period = aggregationPeriod)[-displace], length);
}
 
Last edited:

AstroBoy

New member
====== EDIT ============

i removed my garbled notes from this morning
and am posting a working code, that draws a line from yesterdays high


# ==== EDIT 2 ======
i changed a line of code.
before , sometimes if the highest price existed on an earlier day, the line started on an earlier day.


Ruby:
# linefromprevhigh
def na = double.nan;
def bn = barnumber();

#if you want a line to start on the 2nd to last day, then you need to determine when that is.
input agg = AggregationPeriod.DAY;

# is the next day valid and the one after that invalid?
def day2= ( !isnan(close(period = agg)[-1]) and isnan(close(period = agg)[-2]) );

# find highest high of 2nd day
def hh = highestall( if day2 then high else 0);

#find the bar that matches the highest and keep value thru remaining bars

# ==== EDIT ======
#def lineh = if bn == 1 then na else if high == hh then hh else lineh[1];

def lineh = if bn == 1 then na else if (day2 and high == hh) then hh else lineh[1];
# ==== EDIT ======


plot x = lineh;
x.SetDefaultColor(Color.white);
x.SetStyle(Curve.MEDIUM_DASH);
x.setlineweight(3);
# x.hidebubble();

# last bar  ( most recent)
def lastbar = !isnan(close[0]) and isnan(close[-1]);
#
addchartbubble(lastbar, x, "prev HI", color.green, yes);
#

kMvrPky.jpg

The code works! If I wanted to only have the line be plotted from the high of day of during normal trading hours of 9:30 AM to 4:00 PM EST, would I have to use
Code:
RegularTradingStart(GetYYYYMMDD())
?
 

Similar threads

Top