Donchian turtles

Posted By: Sniv

Donchian turtles - 02/14/19 09:55

Hi all) please write why this script don't work. Does not open orders with donch 10,20 and dont close orders.

Code:
function run()
{
  StartDate = 20180301;
  Capital = 400;
  Lots = 1;
    vars Price = series(price());
	vars Close = series(priceClose());
	vars High = series(priceHigh());
	vars Low = series(priceLow());
	vars Open = series(priceOpen());
	//set(PARAMETERS);
	
   DChannel(10);
   vars donch_10_up = series(rRealUpperBand);
   vars donch_10_dn = series(rRealLowerBand);
   DChannel(20);
   vars donch_20_up = series(rRealUpperBand);
   vars donch_20_dn = series(rRealLowerBand);
   DChannel(55);
   vars donch_55_up = series(rRealUpperBand);
   vars donch_55_dn = series(rRealLowerBand);

  if((Close[0]>donch_20_up[0])or(Close[0]>donch_55_up[0])or(Close[0]>donch_10_up[0])) exitShort();
  if((Close[0]<donch_20_dn[0])or(Close[0]<donch_55_dn[0])or(Close[0]<donch_10_dn[0])) exitLong();

  if((NumOpenShort<6 and Close[0]>donch_20_dn[0])or(NumOpenShort<6 and Close[0]>donch_55_dn[0])or(NumOpenShort<6 and Close[0]>donch_10_dn[0])) enterShort();
  if((NumOpenLong<6 and Close[0]>donch_20_up[0])or(NumOpenLong<6 and Close[0]>donch_55_up[0])or(NumOpenLong<6 and Close[0]>donch_10_up[0])) enterLong();


/*
  plot("EChannelUp10",donch_10_up,BAND1,RED);
  plot("EChannelDn10",donch_10_dn,BAND2,GREEN);
  
  plot("EChannelUp20",donch_20_up,BAND1,ORANGE);
  plot("EChannelDn20",donch_20_dn,BAND2,GREY);
  
  PlotWidth = 1200;//1200
  PlotHeight1 = 600;//600
  */
}


Why? :((
Posted By: Petra

Re: Donchian turtles - 02/14/19 10:47

Close condition looks always false to me. Price cannot be higher than the high or lower than the low.
Posted By: Sniv

Re: Donchian turtles - 02/14/19 11:20

thanks), forgot about the value of the price on the bar 0
it works like this):

//FIXED - "donch_10_dn"
Code:
function trade(){

   vars Close = series(priceClose());
   vars High = series(priceHigh());
   vars Low = series(priceLow());
   DChannel(10);
   vars donch_10_up = series(rRealUpperBand);
   vars donch_10_dn = series(rRealLowerBand);
   DChannel(20);
   vars donch_20_up = series(rRealUpperBand);
   vars donch_20_dn = series(rRealLowerBand);
   DChannel(55);
   vars donch_55_up = series(rRealUpperBand);
   vars donch_55_dn = series(rRealLowerBand);
   Stop = optimize(1,1,5,1)*ATR(optimize(10,10,100,5));

  if((NumOpenShort<1 and Low[0]<donch_20_dn[1])or(NumOpenShort<1 and Low[0]<donch_55_dn[1])or(NumOpenShort<1 and Low[0]<donch_10_dn[1])) {enterShort();exitLong();}
  if((NumOpenLong<1 and High[0]>donch_20_up[1])or(NumOpenLong<1 and High[0]>donch_55_up[1])or(NumOpenLong<1 and High[0]>donch_10_up[1])) {enterLong();exitShort();}
}
function run()
{
  StartDate = 20170301;
  Capital = 400;
  Lots = 1;
  
  if(Train) {Hedge = 2;LookBack = 400;NumWFOCycles = 5;}

    vars Price = series(price());	
	vars High = series(priceHigh());
	vars Low = series(priceLow());
	vars Open = series(priceOpen());
	set(PARAMETERS);

while(asset(loop("AUD/CAD","AUD/CHF","AUD/JPY","AUD/NZD","AUD/USD","CAD/CHF","CAD/JPY","CHF/JPY","EUR/AUD","EUR/CAD","EUR/CHF","EUR/GBP","EUR/JPY","EUR/NZD","EUR/USD","GBP/AUD","GBP/CAD","GBP/CHF","GBP/JPY","GBP/NZD","GBP/USD","NZD/CAD","NZD/CHF","NZD/JPY","NZD/USD","USD/CAD","USD/CHF","USD/JPY")))
{
trade();
}
}

Posted By: OptimusPrime

Re: Donchian turtles - 02/14/19 14:50

Hi Sniv: You have a typo in your second line.. you did not include donch_10
Posted By: Sniv

Re: Donchian turtles - 02/14/19 16:43

Hi, thanks) in my version I have already fixed it. And this is only a template.
© 2024 lite-C Forums