Hope somebody can help me
How can i display a Donchian Channel with xPeriods that do not print channel on the resent candlestick like in attached example file
How have to change the code?
Upper = HIGHEST[a](HIGH[1])
Lower = LOWEST[a](LOW[1])
Middle = (Upper + Lower) / 2
>> For clarity of messages on ProRealCode’s forums, please use the “insert code PRT” button to separate the text of the code part! Thank you! <<
🙂
Your code is fine, but you cannot use RETURN since it will not allow you to skip the current candle.
You’ll have to use DRAWSEGMENT, instead, to plot data between the second last candle and the previous candle.
Try this (not tested):
Upper = HIGHEST[a](HIGH[1])
Lower = LOWEST[a](LOW[1])
Middle = (Upper + Lower) / 2
If barindex > 2 Then
Drawsegment(barindex-2,Upper,barindex-1,Upper) coloured(0,0,255,255)
Drawsegment(barindex-2,Lower,barindex-1,Lower) coloured(0,0,255,255)
Drawsegment(barindex-2,Middle,barindex-1,Middle) coloured(0,255,0,255)
Endif
Return
But you won’t be able to change the style of plotted lines in versions prior to 11.
Thank you very much Robert,
is it possible to draw lines without brakes (like in “original” Donchain)?
Unfortunately segments are straight llines, so it’s not possible.
Ok, thanks
Last Question … how can i print price label of the resent segment?
You cannot, since there’s an instruction to allow drawing object only on the last bar, but then you wouldn’t see the previous bars, only the last one drawn. It is useless in your case.
If we display a price label everytime your chart would become so messy!
Try this modified version:
Upper = HIGHEST[a](HIGH[1])
Lower = LOWEST[a](LOW[1])
Middle = (Upper + Lower) / 2
If barindex > 2 Then
Drawsegment(barindex-2,Upper[1],barindex-1,Upper) coloured(0,0,255,255)
Drawsegment(barindex-2,Lower[1],barindex-1,Lower) coloured(0,0,255,255)
Drawsegment(barindex-2,Middle[1],barindex-1,Middle) coloured(0,255,0,255)
Endif
Return
SUPER Roberto … your last version is exactly what i want to use
Thanks a lot !!
You could create a separate indicator that just draws the text of the value you want on the last bar only then apply it as a separate indicator to the price chart as well as Roberto’s last code.
defparam drawonlastbaronly = true
Upper = HIGHEST[a](HIGH[1])
Lower = LOWEST[a](LOW[1])
Middle = (Upper + Lower) / 2
If barindex > 2 Then
upper1 = upper[1]
lower1 = lower[1]
middle1 = middle[1]
DRAWTEXT(" #Upper1#",barindex,Upper,SansSerif,Bold,11)coloured(0,0,255)
DRAWTEXT(" #Lower1#",barindex,Lower,SansSerif,Bold,11)coloured(0,0,255)
DRAWTEXT(" #Middle1#",barindex,Middle,SansSerif,Bold,11)coloured(0,255,0)
Endif
Return