Please Help – Tops and Bottoms

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #220208 quote
    KhaledKhaled
    Participant
    Veteran

    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
    Capture-decran-2023-09-02-a-12.13.56.png Capture-decran-2023-09-02-a-12.13.56.png
    #220214 quote
    JSJS
    Participant
    Master

    Hi,

    Do you mean more like this…?

    Khaled thanked this post
    Scherm­afbeelding-2023-09-02-om-14.46.43.png Scherm­afbeelding-2023-09-02-om-14.46.43.png
    #220216 quote
    KhaledKhaled
    Participant
    Veteran

    @JS Yes, Thank you! your code seems to generate much cleaner results than mine. Any chance you can share your revised code? Thanks

    #220221 quote
    JSJS
    Participant
    Master

    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
    Khaled thanked this post
    #220222 quote
    KhaledKhaled
    Participant
    Veteran
    Thanks a million JS! Much appreciated.
    JS thanked this post
    #220223 quote
    KhaledKhaled
    Participant
    Veteran
    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
Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.
ProRealAI ProRealAI New

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

Please Help – Tops and Bottoms


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
Khaled @khaled Participant
Summary

This topic contains 5 replies,
has 2 voices, and was last updated by KhaledKhaled
3 years ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 09/02/2023
Status: Active
Attachments: 2 files
ProRealCode ProRealCode
Loading...