Showing Label issues for previous high/low


Category:
0
0

I have this previous high and low indicator that plots a line on the chart to give you a visual as well as alert you when it crosses.  I want to add a label on the chart as well and it works great on smaller time frames. When I switch over to a daily time frame the numbers are completely off. I’d also like to be able to hide the label on larger time frames if possible. Can you assist with the code?

plot Data = close;

input Hide_On = {Monthly, Weekly, Daily, “2 Hour”, default “4 Hour”, Hourly, None};
input showOnlyToday = YES;
input Market_Open_Time = 0930;
input Market_Close_Time = 1600;
input ShowpHigh = Yes;
input ShowpLow = Yes;

def day = GetDay();
def lastDay = GetLastDay();
def isToday = If(day == lastDay, 1, 0);
def shouldPlot = If(showOnlyToday and isToday, 1, If(!showOnlyToday, 1, 0));

def pastOpen = If((SecondsTillTime(Market_Open_Time) > 0), 0, 1);
def pastClose = If((SecondsTillTime(Market_Close_Time) > 0), 0, 1);
def marketOpen = If(pastOpen and !pastClose, 1, 0);
def firstBar = If (day[1] != day, 1, 0);

def closingBell = if SecondsTillTime(Market_Close_Time)[1] > 0 and
SecondsTillTime(Market_Close_Time) <= 0 or
(SecondsTillTime(Market_Close_Time)[1] < SecondsTillTime(Market_Close_Time)
and SecondsTillTime(Market_Close_Time)[1] > 0) then 1 else 0;

rec regHoursHigh = If(high > regHoursHigh[1] and marketOpen, high,
If(marketOpen and !firstBar, regHoursHigh[1], high));
rec regHoursLow = If(low < regHoursLow[1] and marketOpen, low,
If(marketOpen and regHoursLow[1] > 0 and !firstBar, regHoursLow[1], low));

rec runningClose = CompoundValue(1, if closingBell then close[1] else runningClose[1], close);
rec prevClose = CompoundValue(1, if closingBell then runningClose else prevClose[1], close);
rec prevHigh = CompoundValue(1, if closingBell then regHoursHigh[1] else prevHigh[1], high);
rec prevLow = CompoundValue(1, if closingBell then regHoursLow[1] else prevLow[1], low);
rec prevHigh2 = CompoundValue(1, if closingBell then prevHigh[1] else prevHigh2[1], high);
rec prevLow2 = CompoundValue(1, if closingBell then prevLow[1] else prevLow2[1], low);

plot pc = if shouldPlot then prevClose else Double.NaN;
pc.SetStyle(Curve.SHORT_DASH);
pc.SetDefaultColor(Color.WHITE);

plot pl = if shouldPlot then prevLow else Double.NaN;
pl.SetDefaultColor(Color.DARK_RED);
plot ph = if shouldPlot then prevHigh else Double.NaN;
ph.SetDefaultColor(Color.DARK_GREEN);

#Labels

AddLabel(ShowpHigh, “pHigh: ” + ph, (if prevhigh then Color.GREEN else Color.ORANGE));
AddLabel(ShowpLow, “pLow: ” + pl, (if prevlow then Color.RED else Color.ORANGE));

# Alerts:

def alerttrigger = if (high >= ph and low <= ph) or (high >= pl and low <= pl) then 1 else 0;

input alerttext = “Range Breakout!”;
input UseAlerts = {false, default true};
input AlertType = {default “BAR”, “ONCE”, “TICK”};
def at = AlertType;
input AlertSound = {“Bell”, “Chimes”, default “Ding”, “NoSound”, “Ring”};
Alert(alerttrigger and UseAlerts, alerttext, if at == 1 then Alert.ONCE else if at == 2 then Alert.TICK else Alert.BAR, AlertSound);

Marked as spam
Posted by (Questions: 21, Answers: 47)
Asked on June 1, 2018 5:35 pm
226 views
0
Private answer

def hideLabelOnHigherTimeFrame = GetAggregationPeriod() < AggregationPeriod.DAY;

 

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on June 2, 2018 8:25 am
0

Thank you. Could you see the issue about the daily chart not reporting the previous high and low correctly?

( at June 4, 2018 8:22 am)
0

There is nothing in this code that would permit it to work on anything but an intraday frame. I thought that was quite obvious so I didn’t even bring it up.

( at June 4, 2018 8:46 am)