Reversal_EA_MT4





//+------------------------------------------------------------------+
//|                                              Reversal_EA_MT4.mq4 |
//|                         Copyright © 2007, Metex Investments Inc. |
//|                                       http://www.metexinvest.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, Metex Investments Inc."
#property link      "http://www.metexinvest.com"

#include <stdlib.mqh>

//+------------------------------------------------------------------+
//| Common External variables                                        |
//+------------------------------------------------------------------+
extern double Lots = 1.00;
extern double StopLoss = 99.00;
extern double TakeProfit = 15.00;
extern double TrailingStop = 7.00;

//+------------------------------------------------------------------+
//| External variables                                               |
//+------------------------------------------------------------------+
extern double Slippage = 3;
extern double risklevel = 3;

//+------------------------------------------------------------------+
//| Special Convertion Functions                                     |
//+------------------------------------------------------------------+

int LastTradeTime;

bool MOrderModify( int ticket, double price, double stoploss, double 
takeprofit, datetime expiration, color arrow_color=CLR_NONE)
{
  LastTradeTime = TimeCurrent();
  price = MathRound(price*10000)/10000;
  stoploss = MathRound(stoploss*10000)/10000;
  takeprofit = MathRound(takeprofit*10000)/10000;
  return ( OrderModify( ticket, price, stoploss, takeprofit, 
expiration, arrow_color) );
}

int MOrderSend( string symbol, int cmd, double volume, double price, 
int slippage, double stoploss, double takeprofit, string comment="", int 
magic=0, datetime expiration=0, color arrow_color=CLR_NONE)
{
  LastTradeTime = TimeCurrent();
  price = MathRound(price*10000)/10000;
  stoploss = MathRound(stoploss*10000)/10000;
  takeprofit = MathRound(takeprofit*10000)/10000;
  return ( OrderSend( symbol, cmd, volume, price, slippage, stoploss, 
takeprofit, comment, magic, expiration, arrow_color ) );
}

int OrderValueTicket(int index)
{
  OrderSelect(index, SELECT_BY_POS);
  return(OrderTicket());
}

int OrderValueType(int index)
{
  OrderSelect(index, SELECT_BY_POS);
  return(OrderType());
}

double OrderValueOpenPrice(int index)
{
  OrderSelect(index, SELECT_BY_POS);
  return(OrderOpenPrice());
}

double OrderValueStopLoss(int index)
{
  OrderSelect(index, SELECT_BY_POS);
  return(OrderStopLoss());
}

double OrderValueTakeProfit(int index)
{
  OrderSelect(index, SELECT_BY_POS);
  return(OrderTakeProfit());
}

string OrderValueSymbol(int index)
{
  OrderSelect(index, SELECT_BY_POS);
  return(OrderSymbol());
}

//+------------------------------------------------------------------+
//| End                                                              |
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
//| Initialization                                                   |
//+------------------------------------------------------------------+

int init()
{
   return(0);
}
int start()
{
//+------------------------------------------------------------------+
//| Local variables                                                  |
//+------------------------------------------------------------------+
double temp = 0;
double lotss = 0;
int i = 0;
double OpenTrades = 0;
int cnt = 0;

lotss=MathCeil((AccountBalance()*risklevel*Ask)/100000);

if ((Open[2]>Close[2] && Close[1]>Open[1] && Open[2]-Close[2]>0 && Close[1]-Open[1]>1*Point) )
  
  {
 OpenTrades = 0;
  	for(i =1;i <=OrdersTotal();i ++){
        if( OrderValueSymbol(i) == Symbol() ) 
             OpenTrades++;
  		}
   if( OpenTrades<1 ) 
	    {
MOrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,Ask-StopLoss*Point,Ask+TakeProfit*Point,"",16384,0,Blue);
	    }
  }

if( TrailingStop>0 ) 
{
for(cnt=1;cnt<=OrdersTotal();cnt++){
   if( OrderValueType(cnt) == OP_BUY && OrderValueSymbol(cnt) == Symbol() ) 
     {
      if( (Bid-OrderValueOpenPrice(cnt))>(TrailingStop*Point) ) 
      	{
         if( OrderValueStopLoss(cnt)<(Bid-TrailingStop*Point) ) 
           {
            
MOrderModify(OrderValueTicket(cnt),OrderValueOpenPrice(cnt),         
Bid-TrailingStop*Point,OrderValueTakeProfit(cnt),0,Blue);
            return(0); 
           }
        }
     }
  }

if (Close[2]>Open[2] && Open[1]>Close[1] && Close[2]-Open[2]>0 && Open[1]-Close[1]>1*Point) 
 
  {
	 OpenTrades = 0;
  	for(i =1;i <=OrdersTotal();i ++){
        if( OrderValueSymbol(i) == Symbol() ) 
             OpenTrades++;
  		}
  		
   if( OpenTrades<1 ) 
    	{
MOrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,Bid+StopLoss*Point,Bid-TakeProfit*Point,"",16384,0,Red);
	    }
  }

   for(cnt=1;cnt<=OrdersTotal();cnt++){
     if( OrderValueType(cnt) == OP_SELL && OrderValueSymbol(cnt) == Symbol() )    
     {
      if( (OrderValueOpenPrice(cnt)-Ask)>(TrailingStop*Point) ) 
     	{
         if( OrderValueStopLoss(cnt)>(Ask+TrailingStop*Point) ||
            OrderValueStopLoss(cnt) == 0 ) 
           {
            
MOrderModify(OrderValueTicket(cnt),OrderValueOpenPrice(cnt),Ask+TrailingStop*Point,OrderValueTakeProfit(cnt),0,Red);
            return(0);
           }
     	}
  	 }  	 
   }
}

  return(0);
}





Sample





Analysis



Market Information Used:

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


Indicator Curves created:


Indicators Used:



Custom Indicators Used:

Order Management characteristics:
It can change open orders parameters, due to possible stepping strategy

Checks for the total of open orders
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.31 Total Net Profit:-9815.11

BackTest : USDCHF 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-12-01 to 2010-01-17 Profit Factor:0.32 Total Net Profit:-9776.00

BackTest : USDCAD on H1

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

BackTest : EURUSD on H1

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

BackTest : GBPUSD on H1

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

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 Reversal_EA_MT4


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

Pair: Period: