Good compilation but not running on EA Strategy Tester

 
//+------------------------------------------------------------------+
//| GLOBAL VARIABLES                                                 |
//+------------------------------------------------------------------+
string BUY_COMMENT   = "Long position open based on confirmation bullish engulfing candle";
string SELL_COMMENT  = "Short position open on confirmation of bearish engulfing candle";
bool glBuyPlaced, glSellPlaced;
//+------------------------------------------------------------------+
//| Input Variables                                                  |
//+------------------------------------------------------------------+
input long STOPLOSS        = 50, TAKEPROFIT      = 100;  input double TRADEVOLUME   = 0.1; 
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
   {
//--- Tine to place the trade
   MqlTradeRequest request; MqlTradeResult result; ZeroMemory(request);
   
//--- Define the open and close prices for the currency
   MqlRates bar[]; ArraySetAsSeries(bar,true); CopyRates(_Symbol,_Period,0,3,bar);
   
   bool openPosition = PositionSelect(_Symbol);
   long positionType = PositionGetInteger(POSITION_TYPE);
   
   
//--- Buy Market Order
   if((bar[3].close < bar[3].open && bar[2].close > bar[3].open && bar[1].close > bar[2].close)
      && glBuyPlaced == false && (openPosition == false || positionType != POSITION_TYPE_BUY)) 
   {
      request.action = TRADE_ACTION_DEAL;
      request.order = ORDER_TYPE_BUY;
      request.symbol = _Symbol;
      //request.price = SymbolInfoDouble(_Symbol,SYMBOL_ASK);
      request.volume = TRADEVOLUME;
      request.type_filling = ORDER_FILLING_FOK;
      request.comment = BUY_COMMENT;
      request.sl = 0; request.tp = 0; //request.deviation = 10; 
      
      OrderSend(request,result);
      
//--- Place stop loss and take profit if orders where placed or done
    if(result.retcode == TRADE_RETCODE_PLACED || result.retcode == TRADE_RETCODE_DONE)
      {
         request.action = TRADE_ACTION_SLTP;
      
         do Sleep(100); while(PositionSelect(_Symbol) == false);
         double positionOpenPrice = PositionGetDouble(POSITION_PRICE_OPEN);
      
         if(STOPLOSS > 0 && TAKEPROFIT > 0)
         {
            request.sl = positionOpenPrice - (STOPLOSS * _Point);
            request.tp = positionOpenPrice + (TAKEPROFIT * _Point);
         
            OrderSend(request,result); 
         }
         glBuyPlaced = true;
         glSellPlaced = false;
      }
   }
   
//--- Sell Market Order
   if((bar[3].open < bar[3].close && bar[2].close < bar[3].open && bar[1].close < bar[2].close)
       && glSellPlaced == false && (openPosition == false || positionType != POSITION_TYPE_SELL))
   {
      request.action = TRADE_ACTION_DEAL;
      request.order = ORDER_TYPE_SELL;
      request.symbol = _Symbol;
      request.price = SymbolInfoDouble(_Symbol,SYMBOL_BID);
      //request.volume = TRADEVOLUME + currentVolume;
      request.type_filling = ORDER_FILLING_FOK;
      request.comment = SELL_COMMENT;
      request.sl = 0; request.tp = 0; //request.deviation = 10;
      
      OrderSend(request,result);
      
//--- Place stop loss and take profit if order was placed or done
      if(result.retcode == TRADE_RETCODE_PLACED || result.retcode == TRADE_RETCODE_DONE)
      {
         request.action = TRADE_ACTION_SLTP;
      
         do Sleep(100); while(PositionSelect(_Symbol) == false);
         double positionOpenPrice = PositionGetDouble(POSITION_PRICE_OPEN);
      
         if(STOPLOSS > 0 && TAKEPROFIT > 0)
         {
            request.sl = positionOpenPrice + (STOPLOSS * _Point);
            request.tp = positionOpenPrice - (TAKEPROFIT * _Point);
         
            OrderSend(request,result);
         }
         glBuyPlaced = false;
         glSellPlaced = true;
       }
   }
   }

Please EA Programmers can u please tell what is wrong with the code. it compile without error but it won't place an order in the strategy tester. Anyone with a tip or clue on how to resolve it?

 
udoh.jeremiah.emem:

Please EA Programmers can u please tell what is wrong with the code. it compile without error but it won't place an order in the strategy tester. Anyone with a tip or clue on how to resolve it?

From the posted code.... I have no idea, however this is how I would approach the peoblem:

first, check the trade logic, by forcing one to be true;

ie comment out the trade if statement and replace  it with if(true){ for the purposes of testing the trade placement code.

   if((bar[3].open < bar[3].close && bar[2].close < bar[3].open && bar[1].close < bar[2].close)
       && glSellPlaced == false && (openPosition == false || positionType != POSITION_TYPE_SELL))
   {

would become

if(can_sell()){
bool can_sell(void){
   if((bar[3].open < bar[3].close && bar[2].close < bar[3].open && bar[1].close < bar[2].close)
       && glSellPlaced == false && (openPosition == false || positionType != POSITION_TYPE_SELL))  return(true);
return(false);
}

you will find this a lot easier if your entry logic is done in separate functions that return a bool. then your code looks something like this for the purposes of debugging

if(true) enter_sell();

where enter_sell() is another function that handles the sell code. and testing true just assumes that the entry logic says "yes" so we can see the order code in action.

then you will know which part of the code is failing.

 
udoh.jeremiah.emem:

Please EA Programmers can u please tell what is wrong with the code. it compile without error but it won't place an order in the strategy tester. Anyone with a tip or clue on how to resolve it?

Do not double/triple post!

It is selfish, narcissistic and wastes people's valuable time!

I have deleted your other 2 topics.