Hello all....pls help me fix this code.......dont know why Eas not open position

 

Eas not open position when the price reach EMA25

pls help me fix

Thanks 

Files:
EMA25_BUY.mq5  3 kb
 
BOC TRADER:

Eas not open position when the price reach EMA25

pls help me fix

Thanks 

//+------------------------------------------------------------------+
//|                                                       emabuy.mq5 |
//|                                  Copyright 2023, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2023, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"

#include<Trade\Trade.mqh>

CTrade trade;

// Define input parameters
input double LotSize = 0.1;    // Lot size
input double StopLoss = 300;    // Stop loss in points
input double TakeProfit = 500;  // Take profit in points

// Define global variables
int ema25;
double         iMABuffer[];
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit() {
//---
   ema25 = iMA(NULL,PERIOD_CURRENT, 25, 0, MODE_EMA, PRICE_CLOSE);
//---
   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason) {
//---

}
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick() {
   // Calculate EMA25 value

   double Bid = NormalizeDouble(SymbolInfoDouble(_Symbol, SYMBOL_BID),_Digits);
   double Ask = NormalizeDouble(SymbolInfoDouble(_Symbol, SYMBOL_ASK),_Digits);
   double ma_buffer[];
   MqlRates rates[];
   ArraySetAsSeries(ma_buffer,true);
   ArraySetAsSeries(rates,true);
   int start_pos=0,count=3;
   if(!iGetArray(ema25,0,start_pos,count,ma_buffer) || CopyRates(_Symbol,PERIOD_CURRENT,start_pos,count,rates)!=count)
      return;

   //--- prepare a request
   MqlTradeRequest request= {};
   request.action=TRADE_ACTION_DEAL;         // setting a pending order
   request.symbol=_Symbol;                      // symbol
   request.volume=LotSize;                          // volume in 0.1 lots
   request.sl=StopLoss;                                // Stop Loss is not specified
   request.tp=TakeProfit;                                // Take Profit is not specified
   request.type=ORDER_TYPE_BUY;                // order type Buy
   request.price=Ask;                           // open price

   MqlTradeResult result= {};
 

   // Check if the current price is equal to EMA25
   if (MathAbs(Bid - NormalizeDouble(ma_buffer[1],_Digits)) < 0.01) {
      // Open a BUY position
      int ticket=OrderSend(request,result);

      // Exit the EA
      ExpertRemove();
   }
}



//+------------------------------------------------------------------+
//| Get value of buffers                                             |
//+------------------------------------------------------------------+
bool iGetArray(const int handle,const int buffer,const int start_pos,
               const int count,double &arr_buffer[]) {
   bool result=true;
   if(!ArrayIsDynamic(arr_buffer)) {
      return(false);
   }
   ArrayFree(arr_buffer);
//--- reset error code
   ResetLastError();
//--- fill a part of the iBands array with values from the indicator buffer
   int copied=CopyBuffer(handle,buffer,start_pos,count,arr_buffer);
   if(copied!=count) {
      //--- if the copying fails, tell the error code
  
      return(false);
   }
   return(result);
}  
//+------------------------------------------------------------------+

you can play with this and see if it works for you. Focus on Line where you see

 if (MathAbs(Bid - NormalizeDouble(ma_buffer[1],_Digits)) < 0.01) {

if your symbol is having correct digit 0.01 then it should work

 


Arpit T #:

you can play with this and see if it works for you. Focus on Line where you see

if your symbol is having correct digit 0.01 then it should work


Thank you so much