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
Donchian channel right code?
- TJ
- Posts: 7743
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2223 times
Re: Donchian channel right code?
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");