Hi,
Greetings. Looking for Donchian Channel indicator to be added to my chart.
Can anyone help?
Thanks.
Hi,
Greetings. Looking for Donchian Channel indicator to be added to my chart.
Can anyone help?
Thanks.
@xperia28 There are examples all over the internet. Just do a simple Google search.
Here is an example,
// Plots a 20 period Donchian channel
periods = Param("periods", 20, 5, 100, 1);
DonchianUpper =HHV(Ref(H,-1),periods);
DonchianLower = LLV(Ref(L,-1),periods);
DonchianMiddle = (DonchianUpper+DonchianLower)/2;
Plot(C,"C",colorBlack,styleBar| styleThick);
Plot(DonchianUpper,"DU",colorBlue,styleLine);
Plot(DonchianMiddle,"DM",colorGreen,styleLine);
Plot(DonchianLower,"DL",colorRed,styleLine);
Or if you want add a second channel and trading rules as in this one,
// Channel Trading system
////////////////////////////
// Constants
////////////////////////////
Float = 100000;
MaxPositions = 1;
////////////////////////
// Backtester Options
///////////////////////
SetOption( "MaxOpenPositions", MaxPositions );
SetOption( "InitialEquity", Float );
SetPositionSize( 100 / MaxPositions, spsPercentOfEquity );
Buy = Sell = Short = Cover = 0;
////////////////////
// Parameters
////////////////////
LTPeriods = Param("LongTermPeriods",60,40,100,1); // Long Term lookback period
STPeriods = Param("ShortTermPeriods",20,10,40,1); // Short Term lookback period
//////////////////////
// Arrays
//////////////////////
UpperLTChannel = HHV( Ref( H, -1 ), LTPeriods ); // Highest high value of highs in last LongTermPeriods
LowerLTChannel = LLV( Ref( L, -1 ), LTPeriods ); // Lowest low value of low in last LongTermPeriods
UpperSTChannel = HHV( Ref( H, -1 ), STPeriods ); // Highest high value of highs in last ShortTermPeriods
LowerSTChannel = LLV( Ref( L, -1 ), STPeriods ); // Lowest low value of low in last ShortTermPeriods
////////////////////////
// Entries and Exits
////////////////////////
Buy = H>Ref(UpperLTChannel,-1);
Short = L<Ref(LowerLTChannel,-1);
Cover = H>Ref(UpperSTChannel,-1);
Sell = L<Ref(LowerSTChannel,-1);
Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);
Short = ExRem(Short,Cover);
Cover = ExRem(Cover,Short);
////////////////////////
// Exploration
////////////////////////
Filter = 1;
AddColumn( C, "Close" );
AddColumn( UpperLTChannel, "Upper LT Channel", 1.2, colorBlack, colorLime );
AddColumn( UpperSTChannel, "Upper ST Channel", 1.2, colorGreen, colorLightYellow );
AddColumn( LowerLTChannel, "Lower LT Channel", 1.2, colorBlack, colorRose );
AddColumn( LowerSTChannel, "Lower ST Channel", 1.2, colorBlack, colorDefault );
////////////////////////
// Charting
////////////////////////
Plot(UpperLTChannel,"UpperLTChannel",colorBlue,styleThick);
Plot(LowerLTChannel,"LowerLTChannel",colorRed,styleThick);
Plot(UpperSTChannel,"UpperSTChannel",colorBlue,styleDashed);
Plot(LowerSTChannel,"LowerLTChannel",colorRed,styleDashed);