Draw support line until it is broken by subsequent price action

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #202677 quote
    nils_k
    Participant
    New

    Dear Members of the Forum,

    I want to draw a support line on the lowest low of an umbrella line (significant candle in hammer and hanging man patterns).
    My code so far is:

    REM Measure the length of real body, lower shadow, and upper shadow for white and black candles
    IF OPEN < CLOSE THEN REM white candle
    realbody = CLOSE - OPEN
    lowershadow = OPEN - LOW
    uppershadow = HIGH - CLOSE
    ELSIF OPEN > CLOSE THEN REM black candle
    realbody = OPEN - CLOSE
    lowershadow = CLOSE - LOW
    uppershadow = HIGH - OPEN
    ENDIF
    
    REM Draw support
    IF ((lowershadow / realbody) >= 2 AND (realbody/uppershadow) >= 2) AND NOT(OPEN = CLOSE) THEN
     DRAWSEGMENT(BARINDEX, LOW, BARINDEX+10,LOW) COLOURED(0,255,0)
    ENDIF
    
    RETURN

    In the code above I have hardcoded the length of the support line as being 10 bars long, ideally I would like the length of the line to be determined by subsequent price action breaking it.
    That is, if a subsequent candle’s low is below the line, then, and only then, the line should end.

    Does andybody know how this can be done? If the solution involves arrays, I would be happy if you could also provide some code showing how this would work in this case, since I have tried it but couldn’t wrap my head around it.

    I thank you in advance!

    Greetings,
    Nils

    Screenshot-2022-10-17-at-13.07.29.png Screenshot-2022-10-17-at-13.07.29.png
    #202686 quote
    Nicolas
    Keymaster
    Master

    Yes it would involves arrays, much better and faster to check an array than to loop the whole history on each candle.. anyway, I’ll try something.

    nils_k thanked this post
    #202688 quote
    Nicolas
    Keymaster
    Master

    Please find below a rough solution that work ok to me. Please confirm 😉

    defparam drawonlastbaronly=true
    
    REM Measure the length of real body, lower shadow, and upper shadow for white and black candles
    IF OPEN < CLOSE THEN REM white candle
    realbody = CLOSE - OPEN
    lowershadow = OPEN - LOW
    uppershadow = HIGH - CLOSE
    ELSIF OPEN > CLOSE THEN REM black candle
    realbody = OPEN - CLOSE
    lowershadow = CLOSE - LOW
    uppershadow = HIGH - OPEN
    ENDIF
    
    REM Store support
    IF ((lowershadow / realbody) >= 2 AND (realbody/uppershadow) >= 2) AND NOT(OPEN = CLOSE) THEN
     $support[i]=low
     $bar[i]=barindex
     i=i+1
    ENDIF
    
    REM check support line
    if islastbarupdate and i>1 then 
     for j = 0 to i-1
      checklow = $support[j]
      bars = max(1,barindex-$bar[j])
      check=0
      for z = 1 to bars 
       if low[z]<checklow then 
         check=1
         break
       endif 
     next
      if check=0 then 
       drawray($bar[j],$support[j],barindex,$support[j]) coloured(0,255,0)
      endif  
     next
    endif 
    
    
    RETURN
    nils_k thanked this post
    check-support-breakout.png check-support-breakout.png
    #202693 quote
    nils_k
    Participant
    New

    Dear Nicolas,

    Thank you so much for your fast response.

    The code does draw support lines if the price action has not been broken (as rays starting from the umbrella line’s lows). What it does not, is draw the support lines that have been broken (until they are broken; likely via DRAWSEGMENT).
    I attached two screenshots. All umbrella lines are highlighted with a grey background. The first screenshot shows the result of your code, the second one shows where support lines should be drawn as well (I just put them in by hand).

    I hope there is a solution for this. Thank you again for helping me with this!

    Greetings,
    Nils

    Screenshot-2022-10-17-at-14.23.21.png Screenshot-2022-10-17-at-14.23.21.png Screenshot-2022-10-17-at-14.25.24.png Screenshot-2022-10-17-at-14.25.24.png
    #202702 quote
    Nicolas
    Keymaster
    Master

    Ok, that new version should be what you required:

    defparam drawonlastbaronly=true
    
    REM Measure the length of real body, lower shadow, and upper shadow for white and black candles
    IF OPEN < CLOSE THEN REM white candle
    realbody = CLOSE - OPEN
    lowershadow = OPEN - LOW
    uppershadow = HIGH - CLOSE
    ELSIF OPEN > CLOSE THEN REM black candle
    realbody = OPEN - CLOSE
    lowershadow = CLOSE - LOW
    uppershadow = HIGH - OPEN
    ENDIF
    
    REM Store support
    IF ((lowershadow / realbody) >= 2 AND (realbody/uppershadow) >= 2) AND NOT(OPEN = CLOSE) THEN
    $support[i]=low
    $bar[i]=barindex
    i=i+1
    ENDIF
    
    REM check support line
    if islastbarupdate and i>1 then
    for j = 0 to i-1
    checklow = $support[j]
    bars = max(1,barindex-$bar[j])
    endbar=barindex
    for z = 1 to bars
    if low[z]<checklow then
    endbar=barindex[z]
    endif
    next
    if endbar<barindex then 
    drawsegment($bar[j],$support[j],endbar,$support[j]) coloured(0,255,0)
    else
    drawray($bar[j],$support[j],barindex+1,$support[j]) coloured(0,255,0)
    endif
    next
    endif
    
    
    RETURN
    nils_k and icharttop thanked this post
    support-lines-breakout-history.png support-lines-breakout-history.png
    #202705 quote
    nils_k
    Participant
    New

    Dear Nicolas,

    Thank you so much! This works perfect. You are legendary.

    Greetings,
    Nils

    #209096 quote
    bertrandpinoy
    Participant
    Veteran

    Hello, thank you for this interesting topic. I have an error see PJ. Cordially.

    Capture-decran-2023-02-04-110559.png Capture-decran-2023-02-04-110559.png
    #209992 quote
    Bel
    Participant
    New

    @Nicolas,

    won’t create new topic as it seems quite similar but would like to ask if creating something like you did here only to draw line from particular closing time, which we have an option to select, towards in time till it meets the session, which open and close time we also have an option to select, would involve arrays as well, or is there an easier way to go around it?

     

    Thank you.

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.

Draw support line until it is broken by subsequent price action


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
nils_k @nils_k Participant
Summary

This topic contains 7 replies,
has 4 voices, and was last updated by Bel
2 years, 11 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 10/17/2022
Status: Active
Attachments: 6 files
Logo Logo
Loading...