Navigation:Home > Content >

3_Bar_Reversal.mq4

Time: 2014-02-05 | Download file:3_Bar_Reversal.mq4

//+------------------------------------------------------------------+
//| 3 Bar Reversal.mq4
//| Copyright © 2007, fxid10t@yahoo.com
//| "Gordon Gibson"  
//+------------------------------------------------------------------+

#property copyright "Copyright © 2007, fxid10t@yahoo.com"
#property link      "Gordon Gibson  "
#include 

extern double Lots=0.1;

string pairs[] = { "EURUSDm","USDJPYm","GBPUSDm","USDCHFm","EURCHFm","AUDUSDm","USDCADm",
                   "NZDUSDm","EURGBPm","EURJPYm","GBPJPYm","CHFJPYm","GBPCHFm","EURAUDm",
                   "EURCADm","AUDCADm","AUDJPYm","NZDJPYm","AUDNZDm" };
int periods[] = { 1,5,15,30,60,240,1440,10080,43200 };

string TradeSymbol, CommentHeader, CommentsPairs[];
int      TradePeriod,MagicNumber;
int      Pair = -1;
int      PPeriod = -1;
double   bid,ask,point,spread,ticket,bSL,sSL,btp,stp;
int b1,s1;

//initialize
int init(){
   if ( IsTesting() ) { if ( ArrayResize(pairs,1) != 0 )  pairs[0] = Symbol();   } 
   if ( IsTesting() ) { if ( ArrayResize(periods,1) != 0 )  periods[0] = Period(); }
return(0);  }
//deinitialize
int deinit()   {return(0);}

int start() {
b1=0;s1=0;
//Select Pair from Array
Pair = (Pair+1) % ArraySize(pairs);
TradeSymbol = pairs[Pair];
//Identify ibfx mini trade symbol
if(iClose(TradeSymbol,1440,0)==0) { TradeSymbol=StringSubstr(TradeSymbol,0,6);  }

//TradeSymbol MagicNumber Assignment
if (TradeSymbol=="AUDCADm" || TradeSymbol=="AUDCAD") {MagicNumber=200001;}
if (TradeSymbol=="AUDJPYm" || TradeSymbol=="AUDJPY") {MagicNumber=200002;}
if (TradeSymbol=="AUDNZDm" || TradeSymbol=="AUDNZD") {MagicNumber=200003;}
if (TradeSymbol=="AUDUSDm" || TradeSymbol=="AUDUSD") {MagicNumber=200004;}
if (TradeSymbol=="CHFJPYm" || TradeSymbol=="CHFJPY") {MagicNumber=200005;}
if (TradeSymbol=="EURAUDm" || TradeSymbol=="EURAUD") {MagicNumber=200006;}
if (TradeSymbol=="EURCADm" || TradeSymbol=="EURCAD") {MagicNumber=200007;}
if (TradeSymbol=="EURCHFm" || TradeSymbol=="EURCHF") {MagicNumber=200008;}
if (TradeSymbol=="EURGBPm" || TradeSymbol=="EURGBP") {MagicNumber=200009;}
if (TradeSymbol=="EURJPYm" || TradeSymbol=="EURJPY") {MagicNumber=200010;}
if (TradeSymbol=="EURUSDm" || TradeSymbol=="EURUSD") {MagicNumber=200011;}
if (TradeSymbol=="GBPCHFm" || TradeSymbol=="GBPCHF") {MagicNumber=200012;}   
if (TradeSymbol=="GBPJPYm" || TradeSymbol=="GBPJPY") {MagicNumber=200013;}
if (TradeSymbol=="GBPUSDm" || TradeSymbol=="GBPUSD") {MagicNumber=200014;}
if (TradeSymbol=="NZDJPYm" || TradeSymbol=="NZDJPY") {MagicNumber=200015;}
if (TradeSymbol=="NZDUSDm" || TradeSymbol=="NZDUSD") {MagicNumber=200016;}
if (TradeSymbol=="USDCHFm" || TradeSymbol=="USDCHF") {MagicNumber=200017;}
if (TradeSymbol=="USDJPYm" || TradeSymbol=="USDJPY") {MagicNumber=200018;}
if (TradeSymbol=="USDCADm" || TradeSymbol=="USDCAD") {MagicNumber=200019;}
if (MagicNumber==0) {MagicNumber = 200999;}  

//Assign Symbol Bid/Ask, Point & Spread values
bid=MarketInfo(TradeSymbol,MODE_BID);
ask=MarketInfo(TradeSymbol,MODE_ASK);
point=MarketInfo(TradeSymbol,MODE_POINT);
spread=MarketInfo(TradeSymbol,MODE_SPREAD); 
if(IsTesting()) { if(spread > 13*point) {spread=13*point;}}

//Pair Chart Period Setup check loop
/*for(int p=0;p<9;p++) {
      PPeriod = (PPeriod+1) % ArraySize(periods);
      TradePeriod = periods[PPeriod]; */
      TradePeriod = Period();
//Orders counter
int cnt,total=OrdersTotal();
if(TotalTradesThisSymbol(TradeSymbol)==0) {  b1=0;s1=0;   }
if(TotalTradesThisSymbol(TradeSymbol)>0)  {
   for(cnt=0;cntiHigh(TradeSymbol,TradePeriod,2) &&
         iHigh(TradeSymbol,TradePeriod,2)>iHigh(TradeSymbol,TradePeriod,1) )  {
//modify open buystop order
      if(OrderSelect(b1,SELECT_BY_TICKET)==true && OrderType()==OP_BUYSTOP)   {
         if(iHigh(TradeSymbol,TradePeriod,3)+spread < OrderOpenPrice()) {
         OrderModify(b1,iHigh(TradeSymbol,TradePeriod,3)+spread,//swing high
                     OrderStopLoss(),OrderTakeProfit(),OrderExpiration(),Orchid);   }  }
//sell order modify initial/trailing stoploss
      if(OrderSelect(s1,SELECT_BY_TICKET)==true && OrderType()==OP_SELL)   {
         if( (iHigh(TradeSymbol,TradePeriod,3)+spread+(1*point) < OrderStopLoss() &&
              iHigh(TradeSymbol,TradePeriod,3)+spread+(1*point) < OrderOpenPrice() ) ||
            OrderStopLoss()==0)  {
         OrderModify(s1,OrderOpenPrice(),iHigh(TradeSymbol,TradePeriod,3)+spread+(1*point),//swing high
                     OrderTakeProfit(),OrderExpiration(),LightSalmon);  }  }  
//Buy Execution
      if(b1==0)   {
         ticket=OrderSend(TradeSymbol,
                          OP_BUYSTOP,
                          Lots,
                          iHigh(TradeSymbol,TradePeriod,3)+spread,//swing high
                          0,//slippage
                          0,//stoploss set when stop order is executed
                          0,//no tp defined
                          StringConcatenate(TradeSymbol," ",TradePeriod," 3BR Long"),
                          MagicNumber,
                          0,//time expire,
                          Aqua);
                          if(ticket>0)   {
                              if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))  {Print(ticket);}
                              else Print("Error Opening BuyStop Order: ",GetLastError());
                          return(0);   }}
}
//Sell Setup
   if(   iLow(TradeSymbol,TradePeriod,5)>iLow(TradeSymbol,TradePeriod,4) &&
         iLow(TradeSymbol,TradePeriod,4)>iLow(TradeSymbol,TradePeriod,3) &&//3 is swing low
         iLow(TradeSymbol,TradePeriod,3) OrderOpenPrice())  {
         OrderModify(s1,iLow(TradeSymbol,TradePeriod,3)-spread,//swing low
                     OrderStopLoss(),OrderTakeProfit(),OrderExpiration(),HotPink);  }  }
//buy order modify initial/trailing stoploss
      if(OrderSelect(b1,SELECT_BY_TICKET)==true && OrderType()==OP_BUY)  {
         if( (iLow(TradeSymbol,TradePeriod,3)-spread-(1*point) > OrderStopLoss() &&
              iLow(TradeSymbol,TradePeriod,3)-spread-(1*point) > OrderOpenPrice() ) ||
         OrderStopLoss()==0)   {
         OrderModify(b1,OrderOpenPrice(),iLow(TradeSymbol,TradePeriod,3)-spread-(1*point),//swing low
                     OrderTakeProfit(),OrderExpiration(),Orchid); }  }  
//Sell Execution
      if(s1==0)   {
         ticket=OrderSend(TradeSymbol,
                          OP_SELLSTOP,
                          Lots,
                          iLow(TradeSymbol,TradePeriod,3)-spread,//3 is swing low
                          0,//slippage
                          0,//stoploss set when stop order is executed
                          0,//no tp defined
                          StringConcatenate(TradeSymbol," ",TradePeriod," 3BR Short"),
                          MagicNumber,
                          0,//time expire,
                          HotPink);
                          if(ticket>0)   {
                              if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))   {Print(ticket);}
                              else Print("Error Opening SellStop Order: ",GetLastError());
                          return(0);   }}
}
//   }//end period loop
return(0);}//end start()
//+------------------------------------------------------------------+
int TotalTradesThisSymbol(string TradeSymbol) {
   int i, TradesThisSymbol=0;
   for(i=0;i        

Recommend