Donchian channel right code?

Studies that have been contributed to the community by other users. If you’ve got something useful to share, that’s great!
Mar
Posts: 2
Joined: 26 Aug 2014

Donchian channel right code?

Postby Mar » 23 Nov 2015

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

User avatar
TJ
Posts: 6584
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 970 times
Been thanked: 1907 times

Re: Donchian channel right code?  Topic is solved

Postby TJ » 23 Nov 2015

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");



Return to “User Contributed Studies and Indicator Library”