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
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.
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
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
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
Dear Nicolas,
Thank you so much! This works perfect. You are legendary.
Greetings,
Nils
Hello, thank you for this interesting topic. I have an error see PJ. Cordially.
BelParticipant
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.