An EA that Open Buy and Sell Order according to the step Range

To add comments, please log in or register
pek4christ
94
pek4christ  

Please can any one help me fix this problem? I'm to build an EA that Opens Buy and Sell Position according to the RS_Step,that means if the Step is 10pips the EA Opens a buy and a Sell trade every 10pips move, I tried writting it but the problem I'm having is : its opens only one buy and one sell instead of opening buy and sell when the currennt price is 10pips greater than the open price or 10pips less than the opening price. Here is the source Code :

#property strict
//--- input parameters
input double   TakeProfit=20.0;
input double   TraillingStop=10.0;
input double   StopLoss=0.0;
extern double   RS_STEP=10.0;
extern double  LOTS=0.01;
double pips;
double TickSize;
double EMA_1;
int MagicNumberSeries;
double Gage;
double BuyTickFilter;
double SellTickFilter;
int Buy_Trade_Exist;
int Sell_Trade_Exist;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
 //---
      TickSize = MarketInfo(Symbol(),MODE_TICKSIZE);
     if(TickSize ==0.00001 || Point == 0.001)
      pips= TickSize * 10;
      else pips= TickSize;
//--
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   BuyOpenOrderCriteria();
   Buy_Trade_Checker();
   SellOpenOrderCriteria();
   Sell_Trade_Checker();
  }
//+------------------------------------------------------------------+
void BuyOpenOrderCriteria()
     {
 int BuyTicket=0; 
 int SellTicket=0;
 double Bsl=0;
 double Btp=0;
 double input_bstl_AND_btp=0;     
 EMA_1 = iMA(NULL,0,1,0,MODE_SMMA,PRICE_CLOSE,0);

  
if(StopLoss !=0)
       {
        Bsl=Ask-(StopLoss * pips );
     }
    if(TakeProfit !=0)
      {
    
      Btp = Ask+(TakeProfit * pips);   
    }   
    
 if(Buy_Trade_Checker()==0) 
 {
 BuyTicket = OrderSend(Symbol(),OP_BUY,LOTS,Ask,3,0,0, "testing ea",MagicNumberSeries, 0,clrGreen);

  }



 if(BuyTicket >0)
      {
      
      input_bstl_AND_btp = (OrderModify(BuyTicket,OrderOpenPrice(),Bsl,Btp,0,clrNONE));
      
      
    }

}

void SellOpenOrderCriteria()
{

 int SellTicket=0;
 double Ssl=0;
 double Stp=0;
 double input_sstl_AND_stp=0;
EMA_1 = iMA(NULL,0,1,0,MODE_SMMA,PRICE_CLOSE,0);



 if(StopLoss !=0)
       {
        Ssl=Bid+(StopLoss * pips );
     }
    if(TakeProfit !=0)
      {
      Stp = Bid-(TakeProfit * pips);
    
    }
  if(Sell_Trade_Checker()==0) 
{
  SellTicket = OrderSend(Symbol(),OP_SELL,LOTS,Bid,3,0,0, "testing ea",MagicNumberSeries, 0,clrRed);

   }
 

 if(SellTicket >0)
      {
      
            input_sstl_AND_stp = (OrderModify(SellTicket,OrderOpenPrice(),Ssl,Stp,0,clrNONE));
      
    }

}
int Buy_Trade_Checker()
   {

 Buy_Trade_Exist =0;
 Gage = ( RS_STEP * pips);
    for(int i =0; i < OrdersTotal(); i++ )
    {
       if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
       {
        if(OrderMagicNumber()== MagicNumberSeries)
         {
         if( OrderSymbol()==Symbol())   // check for symbol
         {
           if(OrderType()==OP_BUY)  // check for opened position 
           {
            if((MathAbs(Bid - OrderClosePrice()))< Gage)
          {
         Buy_Trade_Exist++;
               
               }
            
            
                            
                         }
                     }
                  }
                }            
             }
   return(Buy_Trade_Exist); 
       }   
          
int Sell_Trade_Checker()
   {

 Sell_Trade_Exist =0;

    for(int s =0; s < OrdersTotal(); s++ )
    {
       if(OrderSelect(s,SELECT_BY_POS,MODE_TRADES))
       {
        if(OrderMagicNumber()== MagicNumberSeries)
         {
         if( OrderSymbol()==Symbol())   // check for symbol
         {
           if(OrderType()==OP_SELL)  // check for opened position 
           {
           
            if((MathAbs(Ask- OrderClosePrice())) < Gage)
          {
        Sell_Trade_Exist++;
               
               }
            
            
                            
                         }
                     }
                  }
                }            
             }
          return(Sell_Trade_Exist); 
          }

 void MagicNumber()
      {
 MagicNumberSeries=0;
   if(Symbol()=="EURUSD"){MagicNumberSeries=4321;}   if(Symbol()=="USDCHF"){MagicNumberSeries=43210;}   if(Symbol()=="NZDCHF"){MagicNumberSeries=432120;}
   if(Symbol()=="EURGBP"){MagicNumberSeries=43212;}  if(Symbol()=="GBPUSD"){MagicNumberSeries=432111;}  if(Symbol()=="AUDCHF"){MagicNumberSeries=432121;}
   if(Symbol()=="EURJPY"){MagicNumberSeries=43213;}  if(Symbol()=="NZDUSD"){MagicNumberSeries=432112;}  if(Symbol()=="AUDCAD"){MagicNumberSeries=432122;}
   if(Symbol()=="EURCHF"){MagicNumberSeries=43214;}  if(Symbol()=="GBPJPY"){MagicNumberSeries=432113;}  if(Symbol()=="AUDJPY"){MagicNumberSeries=432123;}
   if(Symbol()=="EURAUD"){MagicNumberSeries=43211;}  if(Symbol()=="GBPCAD"){MagicNumberSeries=432114;}  if(Symbol()=="AUDNZD"){MagicNumberSeries=432124;}
   if(Symbol()=="EURCAD"){MagicNumberSeries=43215;}  if(Symbol()=="GBPCHF"){MagicNumberSeries=432115;}  if(Symbol()=="NZDJPY"){MagicNumberSeries=432125;}
   if(Symbol()=="EURNZD"){MagicNumberSeries=43216;}  if(Symbol()=="GBPAUD"){MagicNumberSeries=432116;}  if(Symbol()=="NZDCAD"){MagicNumberSeries=432126;}
   if(Symbol()=="USDJPY"){MagicNumberSeries=43217;}  if(Symbol()=="GBPNZD"){MagicNumberSeries=432117;}  if(Symbol()=="CADJPY"){MagicNumberSeries=432127;}
   if(Symbol()=="USDCAD"){MagicNumberSeries=43218;}  if(Symbol()=="CHFJPY"){MagicNumberSeries=432118;}  
   if(Symbol()=="AUDUSD"){MagicNumberSeries=43219;}  if(Symbol()=="CADCHF"){MagicNumberSeries=432119;}  

  }
To add comments, please log in or register