Opening Range Trader V0_01





//+------------------------------------------------------------------+
//|                                   Opening Range Trader V0_01.mq4 |
//|                                    Copyright © 2006, Bundyraider |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, Bundyraider"
#property link      ""

//---- input parameters
extern datetime  BeginTime=6;
extern datetime  EndTime=8;
extern bool      IgnoreDate=TRUE;
extern int       PipsAbove=10;
extern int       PipsBelow=10;
extern int       TakeProfit=20;
extern int       StopLoss=20;
extern double    LotSize=0.1;
extern int       TrailingStop=20;
extern int       Breakeven=20;
extern int       MaxRange=40;
extern datetime  StopTime=14;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
   //------------------------------------------------------------------------
   // Creat Global variables to remember some of our info between "ticks"
   //------------------------------------------------------------------------
   
   GlobalVariableSet("OpeningRange",0);
   GlobalVariableSet("LowestPriceOfRange" , 0);
   GlobalVariableSet("HighestPriceOfRange", 0);
   GlobalVariableSet("RangeTimeComplete",FALSE);
   GlobalVariableSet("WeAreInATrade",FALSE); 
   GlobalVariableSet("TicketNumber" ,0);

  
//----
   
//----
   return(0);
  }
  
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function (executed every tick)                                         |
//+------------------------------------------------------------------+
int start()
  {
   //-------------------------------------------------------------
   //    Declare local variables
   //-------------------------------------------------------------
   int      BeginHour,BeginMinute,EndHour,EndMinute,StopHour,StopMinute, NumberOfBarsInRange;
   double   LowestPriceOfRange, HighestPriceOfRange, OpeningRange ,EMA200, PreviousEMA200;
   bool     RangeTimeComplete,WeAreInATrade;
  
   //-------------------------------------------------------------
   //    Reload GlobalVariable into Local ones
   //-------------------------------------------------------------
   
   OpeningRange         =GlobalVariableGet("OpeningRange");
   LowestPriceOfRange   =GlobalVariableGet("LowestPriceOfRange" );
   HighestPriceOfRange  =GlobalVariableGet("HighestPriceOfRange");
   RangeTimeComplete    =GlobalVariableGet("RangeTimeComplete");
   WeAreInATrade        =GlobalVariableGet("WeAreInATrade"); 
   
   //-------------------------------------------------------------
   //    Calculate the basic variables we have inputs for...
   //-------------------------------------------------------------
   BeginHour   =TimeHour(BeginTime);
   BeginMinute =TimeMinute(BeginTime);
   EndHour     =TimeHour(EndTime);
   EndMinute   =TimeMinute(EndTime);
   
   NumberOfBarsInRange=((EndTime-BeginTime)/60)/Period();

   StopHour    =TimeHour(StopTime);
   StopMinute  =TimeMinute(StopTime);
   
   //#######################################################################################
   //    Let's check for range completion (time) and calculate that range if so.
   //#######################################################################################
 
   if(TimeHour(Time[0])==EndHour && TimeMinute(Time[0])==EndMinute && RangeTimeComplete==FALSE)
     {
      RangeTimeComplete=TRUE;

      LowestPriceOfRange   =Low  [Lowest  (NULL,0,MODE_LOW  ,NumberOfBarsInRange ,0)];
      HighestPriceOfRange  =High [Highest (NULL,0,MODE_HIGH ,NumberOfBarsInRange ,0)];
      OpeningRange         =HighestPriceOfRange-LowestPriceOfRange;
      
      // We need the EA to remember all this, so save as global variables
      
      GlobalVariableSet("OpeningRange",OpeningRange);
      GlobalVariableSet("LowestPriceOfRange" , LowestPriceOfRange);
      GlobalVariableSet("HighestPriceOfRange", HighestPriceOfRange);
      GlobalVariableSet("RangeTimeComplete",TRUE); 
     }   

   //-----------------------------------------------------------------------------
   //    If we have hit our stop time then set RangeTimeComplete to FALSE to 
   //    prevent any new trades till next range end.
   //-----------------------------------------------------------------------------

   if(TimeHour(Time[0])==StopHour && TimeMinute(Time[0])==StopMinute && RangeTimeComplete==TRUE)
     {
      RangeTimeComplete=FALSE;
      GlobalVariableSet("RangeTimeComplete",FALSE); 
      WeAreInATrade=FALSE;
      GlobalVariableSet("WeAreInATrade",FALSE);
     }  
     
   //#########################################################################################
   //     OK.  If we have our range now, then watch for trading opportunities.
   //     BUT, only if range is within MaxRange
   //#########################################################################################
   if(OpeningRange>MaxRange*Point)
     {
     // Print("Out OF RANGE!!!!!!");
     }
   if(RangeTimeComplete==TRUE && OpeningRange<=(MaxRange*Point) && WeAreInATrade==FALSE)
     {
      //-------------------------------------------------------------
      //       Check for BUY...
      //-------------------------------------------------------------
      if(Close[0]>HighestPriceOfRange+(PipsAbove*Point))
        {
         int ticket=OrderSend(Symbol(),OP_BUY,LotSize,Ask,5,HighestPriceOfRange-StopLoss*Point,HighestPriceOfRange+TakeProfit*Point,"Opening-Range Trade BUY",16384,0,Yellow);
         if(ticket>0)
            {
             if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) 
               {
               Print("BUY order opened : ",OrderOpenPrice());
               WeAreInATrade=TRUE;
               GlobalVariableSet("WeAreInATrade",TRUE);     //...To prevent multiple entries per day.
               GlobalVariableSet("TicketNumber" ,ticket);   //...Remember ticket number for manageing trade later on.
                                                            //   This will help with Break even, trailing stop coed etc
               }
            }
            else Print("Error opening BUY order : ",GetLastError()); 
            return(0); 
        }
        
        
      //-------------------------------------------------------------
      //       Check for SELL...
      //-------------------------------------------------------------
      //  
      /*
      if(Close[0]<LowestPriceOfRange-(PipsBelow*Point))
        {
         ticket=OrderSend(Symbol(),OP_SELL,LotSize,Bid,5,LowestPriceOfRange+StopLoss*Point,LowestPriceOfRange-TakeProfit*Point,"Opening-Range Trade SELL",16384,0,Yellow);
         if(ticket>0)
            {
             if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) 
               {
               Print("SELL order opened : ",OrderOpenPrice());
               WeAreInATrade=TRUE;
               GlobalVariableSet("WeAreInATrade",TRUE);     //...To prevent multiple entries per day.
               GlobalVariableSet("TicketNumber" ,ticket);   //...Remember ticket number for manageing trade later on.
                                                            //   This will help with Break even, trailing stop coed etc
               }
            }
            else Print("Error opening SELL order : ",GetLastError()); 
            return(0); 
        }
      */
       

     }

   //#########################################################################################
   //     ...End OF Trading opportunities   
   //     Now Let's manage any open trade...
   //#########################################################################################
 
   if(WeAreInATrade==TRUE)
      {
      
      } 
 
 
 
   
  
   //#########################################################################################
   //------------------------------------------------------------------------
   //   Per Tick routine all done and we're out of here (till next tick)
   //------------------------------------------------------------------------
   return(0);
  }
//+------------------------------------------------------------------+



Sample





Analysis



Market Information Used:

Series array that contains open time of each bar
Series array that contains close prices for each bar


Indicator Curves created:


Indicators Used:



Custom Indicators Used:

Order Management characteristics:
It automatically opens orders when conditions are reached


Other Features:

BackTest : USDJPY on H1

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

BackTest : EURUSD on H1

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

BackTest : USDCAD on H1

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

BackTest : EURUSD on H1

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

BackTest : GBPUSD on H1

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

BackTest : EURUSD on H1

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

BackTest : EURUSD on H1

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

BackTest : EURUSD on H1

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

Request Backtest for Opening Range Trader V0_01


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

Pair: Period: