_Turtle Channel System





//+------------------------------------------------------------------+
//|                              Donchain counter-channel system.mq4 |
//|                      Copyright © 2005, MetaQuotes Software Corp. |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "by djindyfx"
#property link      ""


extern double Lots    =1.0;                  
extern int    Slippage=3;                    
extern int    Magic   =20051006;             
// Optimalization parameters:
extern int    LngPeriod=20;              
extern int    ShtPeriod=10;
extern int Entry_Stop=50;
//extern int    TimeFrame    =PERIOD_D1;       // Time frame of the Donchain indicator.
// Privete variables
datetime last_trade_time;                    // in order to execute maximum only one trade a day.
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//---- 
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
//----
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void ReportStrategy(int Magic)
  {
   int    totalorders=HistoryTotal();
   double StrategyProfit=0.0;
   int    StrategyOrders=0;
   for(int j=0; j<totalorders;j++)
     { if(OrderSelect(j, SELECT_BY_POS, MODE_HISTORY) && (OrderMagicNumber()==Magic))
        {
         if((OrderType()==OP_BUY) || (OrderType()==OP_SELL))
           {
            StrategyOrders++;
            StrategyProfit+=OrderProfit();
           }
        }
     }
   totalorders=OrdersTotal();
   for(j=0; j<totalorders;j++)
     { 
     if(OrderSelect(j, SELECT_BY_POS, MODE_TRADES) && (OrderMagicNumber()==Magic))
        {
         if((OrderType()==OP_BUY) ||(OrderType()==OP_SELL))
           {
            StrategyOrders++;
            StrategyProfit+=OrderProfit();
           }
        }
     }
   Comment("Executed ", StrategyOrders, " trades with ", StrategyProfit," of profit");
   return;
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
   double stop_short;
   double stop_long;
   double ELong, EShort;
   
//----
   bool entry_short;
   bool entry_long;
   bool are_we_long    =false;
   bool are_we_short   =false;
   int  orders_in_trade=0;
   int  active_order_ticket;
//---- 
   ReportStrategy(Magic);
   // Check current trades:
   int TotalOrders=OrdersTotal();
     for(int j=0;j<TotalOrders;j++)
     {
      OrderSelect(j, SELECT_BY_POS, MODE_TRADES);
      if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
             {
         are_we_long =are_we_long  || OrderType()==OP_BUY;
         are_we_short=are_we_short || OrderType()==OP_SELL;
         orders_in_trade++;
         active_order_ticket=OrderTicket();
        }
     }
     if(orders_in_trade > 1)
     {
      Alert("More than one active trade! Please close the wrong one.");
      return(-1);
     }
     // Lower channel:
     stop_long=Low[iLowest(NULL,0,MODE_LOW,ShtPeriod,0)];
     // Upper channel:
     stop_short=High[iHighest(NULL,0,MODE_HIGH,ShtPeriod,0)];
     
     if(are_we_long)
     {
      // We have long position. Check stop loss:
      OrderSelect(active_order_ticket, SELECT_BY_TICKET);
      if(OrderStopLoss() < stop_long)
         OrderModify(active_order_ticket,OrderOpenPrice(),stop_long,OrderTakeProfit(),0,Blue);
//----
      return(0);
     }
     if(are_we_short)
     {
      // We have long position. Check stop loss:
      OrderSelect(active_order_ticket, SELECT_BY_TICKET);
      if(OrderStopLoss() > stop_short)
         OrderModify(active_order_ticket,OrderOpenPrice(),stop_short,OrderTakeProfit(),0,Blue);
//----
      return(0);
     }
   //Do not execute new trade for a next 24 hours.
  if((CurTime() - last_trade_time)<24*60*60) return(0);
  
   // Upper channel:
   ELong=High[Highest(NULL,0,MODE_HIGH,LngPeriod,0)]; 
   // lower channel:
   EShort=Low[Lowest(NULL,0,MODE_LOW,LngPeriod,0)];
   
   if(entry_long && entry_short)
      Alert("Short and long entry. Probably one of the is wrong.");
     if (ELong==Ask)
     {
      OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, Bid-Entry_Stop*Point,0, "", Magic,0, FireBrick); 
      last_trade_time=CurTime();
     }
     if(EShort==Bid)
     {
      OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,Ask+Entry_Stop*Point,0,"",Magic,0,FireBrick);
      last_trade_time=CurTime();
     }
   
//----
   return(0);
  }
//+------------------------------------------------------------------+



Sample





Analysis



Market Information Used:

Series array that contains the lowest prices of each bar
Series array that contains the highest prices of each bar


Indicator Curves created:


Indicators Used:



Custom Indicators Used:

Order Management characteristics:

Checks for the total of open orders
It can change open orders parameters, due to possible stepping strategy
It automatically opens orders when conditions are reached

Other Features:

It issuies visual alerts to the screen

BackTest : EURUSD on H1

From 2009-11-01 to 2009-11-30 Profit Factor:0.19 Total Net Profit:-853.00

BackTest : USDJPY on H1

From 2009-11-01 to 2009-11-30 Profit Factor:0.09 Total Net Profit:-1138.02

BackTest : EURUSD on H1

From 2009-12-01 to 2010-01-17 Profit Factor:0.54 Total Net Profit:-604.20

BackTest : USDCAD on H1

From 2009-12-01 to 2010-01-01 Profit Factor:0.40 Total Net Profit:-974.45

BackTest : EURUSD on H1

From 2009-08-01 to 2009-10-01 Profit Factor:1.00 Total Net Profit:3.30

BackTest : GBPUSD on H1

From 2010-01-01 to 2010-02-27 Profit Factor:0.05 Total Net Profit:-2805.50

BackTest : USDCAD on H1

From 2009-01-01 to 2010-01-01 Profit Factor:0.04 Total Net Profit:-9897.45

BackTest : EURUSD on H1

From 2010-03-01 to 2010-03-27 Profit Factor:0.48 Total Net Profit:-475.80

BackTest : GBPUSD on H1

From 2010-01-01 to 2010-04-16 Profit Factor:0.10 Total Net Profit:-9882.30

BackTest : EURUSD on H1

From 2010-04-01 to 2010-04-30 Profit Factor:1.74 Total Net Profit:508.20

BackTest : EURUSD on H1

From 2010-05-01 to 2010-05-31 Profit Factor:0.00 Total Net Profit:-944.20

BackTest : EURUSD on H1

From 2010-06-01 to 2010-06-30 Profit Factor:0.64 Total Net Profit:-335.20

Request Backtest for _Turtle Channel System


From : (yyyy/mm/dd) To: (yyyy/mm/dd)

Pair: Period: