Page 1 of 1

Donchian channel right code?

Posted: 23 Nov 2015
by Mar
I found many posts about Donchian channel code. Although neither one starts the look-back period without including the last bar. To have the price crossing the channel it is important that today´s bar is not included. It is a very simple question but I couldn´t figure out how to code it in a simple way.
Thanks in advance
Marcela Carvalho

Re: Donchian channel right code?

Posted: 23 Nov 2015
by TJ

Code: Select all


{ Donchian Channel based on "Previous Close" prices }

Inputs: Length(13), ShowAvg(true);

Var: DonchianHi(0), DonchianLo(0), Donavg(0);

DonchianHi = Highest(C, Length)[1];
DonchianLo = Lowest(C, Length)[1];
DonAvg = ((DonchianHi + DonchianLo) / 2);

Plot1(DonchianHi, "DonchianHi");
Plot2(DonchianLo, "DonchianLo");

if ShowAvg = true then
Plot3(DonAvg, "DonchianAvg");