Changes to Donchain Requested

#1
Dear Seniors,

I request for help for some changes in the Double Donchain.

1)How to change the two lines to 55 day high and low (adjustable)as well as 20 day high and low (adjustable)

2) how to change the lines to the top of the candle not crossing the candle also can it be change to bars instead of candles

3) Please also help to Buy when it immediately when it crosses the 55day high and Sell when it crosses 20 day low and also short when it crosses 55 day low and Cover when it crosses 20 day low

HTML:
_SECTION_BEGIN;

SetBarsRequired(100000,0);

GraphXSpace = 1;

SetChartOptions(0,chartShowArrows|chartShowDates);

SetChartBkColor(ParamColor("bkcolor",ColorRGB(0,0, 0)));

GfxSetBkMode(0); 

GfxSetOverlayMode(1);

SetBarFillColor(IIf(C>O,ParamColor("Candle UP Color", colorGreen),IIf(C<=O,ParamColor("Candle Down Color", colorRed),colorLightGrey)));

Plot(C,"\nPrice",IIf(C>O,ParamColor("Wick UP Color", colorDarkGreen),IIf(C<=O,ParamColor("Wick Down Color", colorDarkRed),colorLightGrey)),64,0,0,0,0);

SetPositionSize(100,spsShares);

pds1 = param("param1",79,30,100,1);      //5min - 79 15min - 38
DonchianUpper1 = HHV( Ref( H, -1 ), pds1 ); // Highest high value of highs in last 40 periods
DonchianLower1 = LLV( Ref( L, -1 ), pds1 ); // Lowest low value of low in last 40 periods

pds2 = param("param2",24,5,50,1);;       //5min - 24 15min - 6
DonchianUpper2 = HHV( Ref( H, -1 ), pds2 ); // Highest high value of highs in last 14 periods
DonchianLower2 = LLV( Ref( L, -1 ), pds2 ); // Lowest low value of low in last 14 periods

Plot( DonchianUpper1, "Donchian U1", ParamColor( "DU Color1", colorBlue ), ParamStyle( "DU Style", styleLine ) );
Plot( DonchianLower1, "Donchian L1", ParamColor( "DL Color1", colorBlue ), ParamStyle( "DL Style", styleLine ) );
Plot( DonchianUpper2, "Donchian U2", ParamColor( "DU Color2", colorRed ), ParamStyle( "DU Style", styleLine ) );
Plot( DonchianLower2, "Donchian L2", ParamColor( "DL Color2", colorRed ), ParamStyle( "DL Style", styleLine ) );

Buy = H>Ref(DonchianUpper1,-1);
Short = L<Ref(DonchianLower1,-1);
Cover = H>Ref(DonchianUpper2,-1);
Sell = L<Ref(DonchianLower2,-1);

Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);

Short = ExRem(Short,Cover);
Cover = ExRem(Cover,Short);

PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40);

PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50);                      

PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-45); 

PlotShapes(IIf(Short, shapeSquare, shapeNone),colorRed, 0, H, Offset=40);

PlotShapes(IIf(Short, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);                      

PlotShapes(IIf(Short, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);

PlotShapes(IIf(Cover, shapeStar, shapeNone),colorRed, 0,L, Offset=-45); 

PlotShapes(IIf(Sell, shapeStar, shapeNone),colorGreen, 0, H, Offset=40);

_SECTION_END();
 
#2
Hello

Your code seems to be alright, except for the fact that it is using same period for buy/cover and short/sell i.e. a SAR system.

Can add 2 more parameters to change it to what you want.


Code:
_SECTION_BEGIN("NAME");
SetBarsRequired(100000,0);
GraphXSpace = 1;
SetChartOptions(0,chartShowArrows|chartShowDates);
SetChartBkColor(ParamColor("bkcolor",ColorRGB(0,0, 0)));
GfxSetBkMode(0); 
GfxSetOverlayMode(1);
SetBarFillColor(IIf(C>O,ParamColor("Candle UP Color", colorGreen),IIf(C<=O,ParamColor("Candle Down Color", colorRed),colorLightGrey)));
Plot(C,"\nPrice",IIf(C>O,ParamColor("Wick UP Color", colorDarkGreen),IIf(C<=O,ParamColor("Wick Down Color", colorDarkRed),colorLightGrey)),64,0,0,0,0);


SetPositionSize(100,spsShares);
pds1 = Optimize("Long  Period",Param("Long  Period",55, 2,200,1),10,30,2);
pds2 = Optimize("Short Period",Param("Short Period",55,2,200,1),90,140,10);
pds3 = Optimize("Sell  Period",Param("Sell  Period",20, 2,200,1),60,100,10);
pds4 = Optimize("Cover Period",Param("Cover Period",20, 2,200,1),30,50,10);

DonchianUpper1 = HHV( Ref( H, -1 ), pds1 ); // Highest high value 4 Buy
DonchianUpper2 = HHV( Ref( H, -1 ), pds3 ); // Highest high value 4 Cover
DonchianLower1 = LLV( Ref( L, -1 ), pds2 ); // Lowest low value   4 Short
DonchianLower2 = LLV( Ref( L, -1 ), pds4 ); // Lowest low value   4 Sell

Plot( DonchianUpper1, "\nDonchian Long  Above", ParamColor( "DU Color1", colorBlue ), ParamStyle( "DU Style 1", styleLine ) );
Plot( DonchianLower2, "  Donchian Sell  Below", ParamColor( "DL Color2", colorRed ),  ParamStyle( "DL Style 2", styleDashed));
Plot( DonchianLower1, "\nDonchian Short Below", ParamColor( "DL Color1", colorRed ),  ParamStyle( "DL Style 1", styleLine ) );
Plot( DonchianUpper2, "  Donchian Cover Above", ParamColor( "DU Color2", colorBlue ), ParamStyle( "DU Style 2", styleDashed));

Buy   = H > Ref(DonchianUpper1,-1);
Sell  = L < Ref(DonchianLower2,-1);
Short = L < Ref(DonchianLower1,-1);
Cover = H > Ref(DonchianUpper2,-1);

Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);

Short = ExRem(Short,Cover);
Cover = ExRem(Cover,Short);

PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50);                      
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-45); 
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorRed, 0, H, Offset=40);
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);                      
PlotShapes(IIf(Short, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);

PlotShapes(IIf(Cover, shapeStar, shapeNone),colorRed, 0,L, Offset=-45); 
PlotShapes(IIf(Sell, shapeStar, shapeNone),colorGreen, 0, H, Offset=40);

_SECTION_END();
have also added the parameter optimization code . . .


PS: Tested it on BNF gives good result, but if you compare it with Buy n Hold its almost same :)

Code:
// Code for simple Buy and Hold Logic
Buy   =  1;	Sell  =  0;	Short =  0;	Cover =  0;
 
Last edited:
#3
Sir Thanks for your Reply,

Ho do i change the line to rest on the top and bottom of the bars. and how to change to bars instead of candles.

When i do the old automatic analysis i get the results but when i do back test there are no results
 

mastermind007

Well-Known Member
#4
Dear Seniors,

I request for help for some changes in the Double Donchain.

1)How to change the two lines to 55 day high and low (adjustable)as well as 20 day high and low (adjustable)

2) how to change the lines to the top of the candle not crossing the candle also can it be change to bars instead of candles

3) Please also help to Buy when it immediately when it crosses the 55 day high and Sell when it crosses 20 day low and also short when it crosses 55 day low and Cover when it crosses 20 day low
allfreeacc

This is an interesting idea; What time-frame do you plot these on?

I can see that in code you've mentioned "5 mins 79". Are these optimised values? If not, how did you come up with such number?

I can see that BNFTrader has already given one corrected version of the code and his idea of optimising four parameters is nice too.

However, If you want to maintain the symmetry for long and short trades, you need to shrink down to two params and using optimiser in that scenario may actually be counter productive.

_SECTION_BEGIN("FREE AC");
SetBarsRequired(100000,0);
GraphXSpace = 1;
SetChartOptions(0,chartShowArrows|chartShowDates);
SetChartBkColor(ParamColor("bkcolor",ColorRGB(0,0, 0)));
GfxSetBkMode(0);
GfxSetOverlayMode(1);
SetBarFillColor(IIf(C>O,ParamColor("Candle UP Color", colorGreen),IIf(C<=O,ParamColor("Candle Down Color", colorRed),colorLightGrey)));
Plot(C,"\nPrice",IIf(C>O,ParamColor("Wick UP Color", colorDarkGreen),IIf(C<=O,ParamColor("Wick Down Color", colorDarkRed),colorLightGrey)),styleBar,0,0,0,0);


SetPositionSize(100,spsShares);
pds1 = param("Entry Period",55,30,100,1); //5min - 79 15min - 38
pds2 = param("Exit Period",20,5,50,1);; //5min - 24 15min - 6

DonchianUpper1 = HHV( Ref( H, -1 ), pds1 ); // Highest high value of highs in last 40 periods
DonchianLower1 = LLV( Ref( L, -1 ), pds1 ); // Lowest low value of low in last 40 periods

DonchianUpper2 = HHV( Ref( H, -1 ), pds2 ); // Highest high value of highs in last 14 periods
DonchianLower2 = LLV( Ref( L, -1 ), pds2 ); // Lowest low value of low in last 14 periods

Plot( DonchianUpper1, "Long Entry Above", ParamColor( "DU Color1", colorBlue ), ParamStyle( "DU Style", styleLine ) );
Plot( DonchianLower1, "Short Entry Below", ParamColor( "DL Color1", colorBlue ), ParamStyle( "DL Style", styleLine ) );
Plot( DonchianUpper2, "Long Exit Below", ParamColor( "DU Color2", colorRed ), ParamStyle( "DU Style", styleLine ) );
Plot( DonchianLower2, "Short Exit Above", ParamColor( "DL Color2", colorRed ), ParamStyle( "DL Style", styleLine ) );

Buy = H>Ref(DonchianUpper1,-1);
Short = L<Ref(DonchianLower1,-1);
Cover = H>Ref(DonchianUpper2,-1);
Sell = L<Ref(DonchianLower2,-1);

Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);

Short = ExRem(Short,Cover);
Cover = ExRem(Cover,Short);

PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50);
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-45);

PlotShapes(IIf(Short, shapeSquare, shapeNone),colorRed, 0, H, Offset=40);
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);
PlotShapes(IIf(Short, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);

PlotShapes(IIf(Cover, shapeStar, shapeNone),colorRed, 0,L, Offset=-45);
PlotShapes(IIf(Sell, shapeStar, shapeNone),colorGreen, 0, H, Offset=40);

_SECTION_END();
Also, please check the text of Rule #3 and re-confirm the rule. Instead of word "it" in your rules, I've used word High/Low. You may change it to Close if you had meant that.

Buy when High crosses above 55 day High
Sell when Low crosses below 20 day low

Short when Low crosses below 55 day low
Cover when High crosses above 20 day high
 
Last edited:

mastermind007

Well-Known Member
#5
Sir Thanks for your Reply,

Ho do i change the line to rest on the top and bottom of the bars. and how to change to bars instead of candles.

When i do the old automatic analysis i get the results but when i do back test there are no results
Lines will not align with high and low of bars because you are plotting one day later.