Ea only works in demo mode

 

Hello, I'm working on an ea that executes buyStops and sellStops at specific signals already defined. The code works well in in the demo account of the metaQuotes. Switching to the broker account (The broker is Credit Financial Invest CFI and the symbol is EURUSD ) no trades are executed as I get the 10015 error code (Invalid Price). I tried a real account and a demo account from this broker and it fails with the same error.

This is the buy function:

  

 if(trade.BuyStop(getLot(), NormalizePrice(SymbolInfoDouble(_Symbol, SYMBOL_ASK)), _Symbol, NormalizeDouble(maValue, Digits()), symbolInfo.Ask() + getTakeProfitInput() * _Point))
     {
      operationsNumber++;
      lastAskPrice = symbolInfo.Ask();
      Print("Buy oparation number: ", operationsNumber, " succeeded with\nPrice: ", symbolInfo.Ask());
     }
   else
     {
      Print("Buy oparation failed, Return code: ", trade.ResultRetcode(), ". Code descriptino: ", trade.ResultRetcodeDescription());
      printData();
     }

double NormalizePrice(double p)
  {
   double ts = SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_SIZE);
   return(MathRound(p / ts) * ts);
  }

double NormalizeLots(double p)
  {
   double vs = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_STEP);
   return(MathRound(p / vs) * vs);
  }
Documentation on MQL5: Constants, Enumerations and Structures / Environment State / Symbol Properties
Documentation on MQL5: Constants, Enumerations and Structures / Environment State / Symbol Properties
  • www.mql5.com
Symbol Properties - Environment State - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 

1.***

2. Formula of normalization: ( [data folder]\MQL5\Include\Trade\SymbolInfo.mqh )

//+------------------------------------------------------------------+
//| Normalize price                                                  |
//+------------------------------------------------------------------+
double CSymbolInfo::NormalizePrice(const double price) const
  {
   if(m_tick_size!=0)
      return(NormalizeDouble(MathRound(price/m_tick_size)*m_tick_size,m_digits));
//---
   return(NormalizeDouble(price,m_digits));
  }
 
if(trade.BuyStop(getLot(), NormalizePrice(SymbolInfoDouble(_Symbol, SYMBOL_ASK)),

You can not place a Stop at the market.

 
Vladimir Karputov:

1. BUY opens at the Bid price

2. Formula of normalization: ( [data folder]\MQL5\Include\Trade\SymbolInfo.mqh )

Huh ? BUY opens at Ask price, not Bid.

 
Alain Verleyen :

Huh ? BUY opens at Ask price, not Bid.

Oh. I got it wrong. Now I will delete the first question.