0

I am trying to draw day's fresh high and low on 5 min time frame. But the problem that I am facing is this: it generates new fresh high/low. Requirement: I want one of the following solution a) either it stops after FIRST high or b) gives me the value (lets say 10 EMA) at FIRST instance only which does not change if condition is met again in the same day.

newDayStart = dayofmonth != dayofmonth[1] and 
     timeframe.isintraday
if newDayStart
    dayHighPrice := high
    dayLowPrice  := low
    prevDayClose := close[1]
else
    dayHighPrice := math.max(dayHighPrice, high)
    dayLowPrice  := math.min(dayLowPrice, low)
Fresh_high =  close > ( 1.0004*dayHighPrice[1])
Fresh_low = close < (0.9996*dayLowPrice[1])
// barcolor(Fresh_high ? color.rgb(255, 255, 255) : na, title = "Fresh High")
barcolor(Fresh_low ? color.rgb(255, 255, 255) : na, title = "Fresh low")


varip is_day_high_found = false

if (newDayStart)
    is_day_high_found := false       // Reset the flag when a new day starts

if (not is_day_high_found)
    Fresh_high 
    is_day_high_found := true 

barcolor(Fresh_high ? color.rgb(255, 255, 255) : na, title = "Fresh High")

1 Answers1

0

You need to use the keyword varip for this so that you can do intra bar actions.

varip (var intrabar persist) is the keyword used for the assignment and one-time initialization of a variable or a field of a user-defined type. It’s similar to the var keyword, but variables and fields declared with varip retain their values between executions of the script on the same bar.

varip is_day_high_found = false

if (newDayStart)
    is_day_high_found := false       // Reset the flag when a new day starts

if (not is_day_high_found)
    // Check for daily high here
    is_day_high_found := true       // Set the flag to true so it will not update any more until the next day starts
vitruvius
  • 15,740
  • 3
  • 16
  • 26