Hello everyone,
I would like to have Lows and Highs of a Range detected and mark the breakout/down with a row. One of the issues is the Lookback period can be variable. Would there be a way to improve the following code (for example by having the lookback period as a “variable” with a loop)? examples highlighted on the attached graph.
Thank you
DEFPARAM CALCULATEONLASTBARS = 1000
i = Lookback
Hipast = highest[i] (high[1])
Lopast = lowest[i] (low[1])
ATR = AverageTrueRange[14](close)
if high[1] <=Hipast and high >=Hipast then
DRAWSEGMENT(barindex, Hipast, barindex[i], Hipast) coloured("red")
elsif low[1] >=Lopast and low <=lopast then
DRAWSEGMENT(barindex, Lopast, barindex[i], Lopast) coloured("green")
endif
if time>=080000 and time<220000 then
if close crosses under lopast then
DRAWARROWDOWN(barindex, high[1]+atr) coloured("red")
elsif close crosses over hipast then
DRAWARROWUP(barindex, low[1]-ATR) coloured("green")
endif
endif
if time>=000000 and time<=080000 then
BACKGROUNDCOLOR (128,128,128,50)
elsif time>=220000 and time<=240000 then
BACKGROUNDCOLOR (128,128,128,50)
ENDIF
RETURN
JSParticipant
Senior
Hi,
Do you mean more like this…?
@JS Yes, Thank you! your code seems to generate much cleaner results than mine. Any chance you can share your revised code? Thanks
JSParticipant
Senior
Hi Khaled,
This works well for finding tops and bottoms…
If High[i] = Highest[i * 2 +1](High) then
If Low[i] = Lowest[i * 2 + 1](Low) then
You can make a profitable system out of this… (where i can be optimized)
DefParam DrawOnLastBarOnly=False
ATR=AverageTrueRange[i](Close)
If High[i]=Highest[i*2+1](High) then
xTop=High[i]
DrawSegment(BarIndex[i],xTop, BarIndex[i-i/2],xTop)Coloured("Red")
ElsIf Low[i]=Lowest[i*2+1](Low) then
xBottom=Low[i]
DrawSegment(BarIndex[i],xBottom, BarIndex[i-i/2],xBottom)Coloured("Green")
EndIf
If Close Crosses Under xBottom[1] then
DrawArrowDown(BarIndex,High+ATR)Coloured("Red")
ElsIf Close Crosses Over xTop[1] then
DrawArrowUp(BarIndex,Low-ATR)Coloured("Green")
EndIf
Return
I don’t want to abuse of your kindness, but I’d be most grateful if you have the time to look at this too
https://www.prorealcode.com/topic/please-help-take-only-the-first-cross/#post-220212