What causes error on my EA?

 

Hi i programming EA and it is work correctly in demo account, But when i want run it on real account i get the error 10004 and 10021.

I read this link "https://www.mql5.com/en/docs/constants/errorswarnings/enum_trade_return_codes" But the definition of some error is not clear and i do not understand what is the problem here exactly.

Please help and explain why these errors are displayed.thank you.
Documentation on MQL5: Constants, Enumerations and Structures / Codes of Errors and Warnings / Trade Server Return Codes
Documentation on MQL5: Constants, Enumerations and Structures / Codes of Errors and Warnings / Trade Server Return Codes
  • www.mql5.com
Trade Server Return Codes - Codes of Errors and Warnings - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
justlink:

Hi i programming EA and it is work correctly in demo account, But when i want run it on real account i get the error 10004 and 10021.

I read this link "https://www.mql5.com/en/docs/constants/errorswarnings/enum_trade_return_codes" But the definition of some error is not clear and i do not understand what is the problem here exactly.

Please help and explain why these errors are displayed.thank you.

Error 10004 and 10021 are related to wrong price used in your trading request. You always need to use the last available price.

Show the relevant code if you need help.

 
Alain Verleyen #:

Error 10004 and 10021 are related to wrong price used in your trading request. You always need to use the last available price.

Show the relevant code if you need help.

it is work correctly in demo account, But when i want run it on real account i get the error 10004 and 10021.

َAlso I use the open price as soon as the zero candle opens.

please help me.

thank you. this is my open trade function:

void OpenTrade(ENUM_ORDER_TYPE ENType,double ESID,
               double Volume, double SL, double roham_line, int roham_deviation
               ,int witch_roham,int witch_per, ENUM_TIMEFRAMES witch_timeframe)
  {
   bool result;
   MqlTradeRequest MTRequest= {}; 
   MqlTradeResult MTResult;
   MTRequest.action = TRADE_ACTION_DEAL;
   MTRequest.type = ENType;
   MTRequest.symbol = _Symbol;

   MTRequest.type_filling = ORDER_FILLING_FOK;
   MTRequest.price = ESID;
   if(ENType == ORDER_TYPE_BUY)
     {
      MTRequest.sl = roham_line - (SL *_Point) - (SYMBOL_SPREAD * _Point);
     }
   else
      if(ENType == ORDER_TYPE_SELL)
        {
         MTRequest.sl = roham_line + (SL *_Point) + (SYMBOL_SPREAD * _Point);
        }
   MTRequest.volume = Volume;
   MTRequest.deviation = roham_deviation;

   result = OrderSend(MTRequest,MTResult);
}
 
justlink #:

it is work correctly in demo account, But when i want run it on real account i get the error 10004 and 10021.

َAlso I use the open price as soon as the zero candle opens.

please help me.

thank you. this is my open trade function:

You answered partly inside the quote, I have fixed it.

If you are not used with mql I would recommend you to use the Standard Library <Trade.mqh>.

Anyway. What is the value of "ESID" ?

 

ESID is the Open of current candle and The OpenTrade is called immediately after the current candle is opened.

this is the parameter I pass to opentrade function:

OpenTrade(ORDER_TYPE_SELL,OpenArray[0],vol,myStopLossPoint,ResSup_line,myDeviation_point,3,per,roham3_Time);


So let my try trade.mql too.
 
justlink #:

ESID is the Open of current candle and The OpenTrade is called immediately after the current candle is opened.

this is the parameter I pass to opentrade function:


So let my try trade.mql too.
You should use symbol last price, not candle open price … we buy at ask and sell at bid 
 
Daniel Cioca #:
You should use symbol last price, not candle open price … we buy at ask and sell at bid 

I know that why i MTRquest.deviation parameter.

and i use <Trade.mqh> now. this is my code:

void OpenTrade(ENUM_ORDER_TYPE ENType,double ESID,
               double Volume, double SL, double roham_line, int roham_deviation
               ,int witch_roham,int witch_per, ENUM_TIMEFRAMES witch_timeframe)
  {
   bool resultOrder;
   uint retcodeOrder;
   ulong  dealticketOrder;

   if(ENType == ORDER_TYPE_BUY)
     {
      resultOrder = CT.Buy(Volume,NULL,ESID,roham_line - (SL *_Point) - (SYMBOL_SPREAD * _Point),0.0,NULL);
     }
   else
      if(ENType == ORDER_TYPE_SELL)
        {
         resultOrder = CT.Sell(Volume,NULL,ESID,roham_line + (SL *_Point) + (SYMBOL_SPREAD * _Point),0.0,NULL);
        }
   Sleep(1000);
   retcodeOrder = CT.ResultRetcode();
   dealticketOrder = CT.ResultDeal();

   Alert("retcode:    ", retcodeOrder);
   Alert("ticket:   ", dealticketOrder);
}

the Retcode return correctly and show 10009 in alert too. so the position open. But the ResultDeal always return 0. how can i get the ticket value?

 
Daniel Cioca #:
You should use symbol last price, not candle open price … we buy at ask and sell at bid 
i try ask and bid too, But there is no deference. I still get 10021 error in real account. but the demo account has worked perfectly and open position.

what is deference between real and demo account that cause this problem? the broker is Alpari.

please help.

 

My problem has not solve yet.

No matter I use MTRequest, <Trade.mqh> Library, Open Price or ASK and BID, my EA worked Currently on demo account and open or close the position. But in real Account I always get the 10021/price error. also no matter what is MTRequest.deviation. I even set this to 1,000,000 point for test and position not open yet.

I send email to Alpari, But they are not answer me properly.

I do not know what to do anymore. what is deference between real and demo account that cause this problem?

please help.

 
justlink #:

My problem has not solve yet.

No matter I use MTRequest, <Trade.mqh> Library, Open Price or ASK and BID, my EA worked Currently on demo account and open or close the position. But in real Account I always get the 10021/price error. also no matter what is MTRequest.deviation. I even set this to 1,000,000 point for test and position not open yet.

I send email to Alpari, But they are not answer me properly.

I do not know what to do anymore. what is deference between real and demo account that cause this problem?

please help.

I asked you to show the relevant code, still you didn't.

ESID is the Open of current candle and The OpenTrade is called immediately after the current candle is opened.

Error 10004 and 10021 are related to wrong price used in your trading request. You always need to use the last available price.

This error is about the price used, show all the relevant code and which price you are using.

 
Alain Verleyen #:

I asked you to show the relevant code, still you didn't.

Error 10004 and 10021 are related to wrong price used in your trading request. You always need to use the last available price.

This error is about the price used, show all the relevant code and which price you are using.

I post that my open trade above. however with out change my code, I change the broker and create new account and my expert work, but only in timeframe m1 to m30.

so i think my problem is servers rules. how can i find this rules and correct my code base on them?

Reason: