The EA I wrote three months ago can not pass the strategy testing now, but it used working well two or three months ago!! - page 2

 
angevoyageur:
Show your code, so we can say you where to add this line.

Bonsoir Angevoyageur,

Here is my code. The two part are separated in the onTick section.

Thank you

Vivaldie


      MqlTick latest_price;      // To be used for getting recent/latest price quotes
      MqlTradeRequest mrequest;  // To be used for sending our trade requests
      MqlTradeResult mresult;    // To be used to get our trade results
      MqlRates mrate[];          // To be used to store the prices, volumes and spread of each bar
      ZeroMemory(mrequest);      // Initialization of mrequest structure
   if(ConditionDICrossMain = -1)
     {
      if(Buy_opened)
        {
         return;    // Don't open a new Buy Position
        }
      mrequest.action = TRADE_ACTION_DEAL;                                  // immediate order execution
      mrequest.price = NormalizeDouble(latest_price.ask,_Digits);           // latest ask price
      mrequest.sl = NormalizeDouble(latest_price.ask - STP*_Point,_Digits); // Stop Loss
      mrequest.tp = NormalizeDouble(latest_price.ask + TKP*_Point,_Digits); // Take Profit
      mrequest.symbol = _Symbol;                                            // currency pair
      mrequest.volume = Lot;                                                 // number of lots to trade
      mrequest.magic = EA_Magic;                                             // Order Magic Number
      mrequest.type = ORDER_TYPE_BUY;                                        // Buy Order
      mrequest.type_filling = ORDER_FILLING_FOK;                             // Order execution type
      mrequest.deviation=100;                                                // Deviation from current price
      //--- send order
        
      OrderSend(mrequest,mresult);
      // get the result code
      if(mresult.retcode==10009 || mresult.retcode==10008) //Request is completed or order placed
        {
         Alert("A Buy order has been successfully placed with Ticket#:",mresult.order,"!!");
        }
      else
        {
         Alert("The Buy order request could not be COMPLETE -error:",GetLastError());
         ResetLastError();           
         return;
        }
     }
 
On this page I can see the error is in the ACCOUNT section. I have try with another MT5 and different account but I have the same message.
 
Vivaldi:

Bonsoir Angevoyageur,

Here is my code. The two part are separated in the onTick section.

Thank you

Vivaldie


  • What's the value of mresult.retcode when you have an error ?
  • What's the values of STP, TKP ?
  • OrderSend returned a bool, you have to check the returned value too.
  • As I don't what you have between the two parts, it's better to place ZeroMemory(mrequest) just before "mrequest.action=TRADE_ACTION_DEAL"
 

I didn't saw messages in the log and it says problem came from stop loss.

With value of 0 it works great : )

 
Vivaldi:

I didn't saw messages in the log and it says problem came from stop loss.

With value of 0 it works great : )

For your stoplevels (SL and TP) you have to take into account the STOP_LEVELS value for the symbol you are trading. See this topic.
 
angevoyageur:
  • What's the value of mresult.retcode when you have an error ?
  • What's the values of STP, TKP ?
  • OrderSend returned a bool, you have to check the returned value too.
  • As I don't what you have between the two parts, it's better to place ZeroMemory(mrequest) just before "mrequest.action=TRADE_ACTION_DEAL"


Ange I get it working now :) problem came from the STP variable.

Need to change the declaration with type double (instead of int) to please mr. NormalizeDouble.

Thanks

double STP, TKP;
 

I mistaken and changing the variable declaration didn't solve the error message. Problem come from STP and TKP variable that are 0 making sl = tp.

 

Is the necessity to add 

 

ZeroMemory(request);

 a bug in build 975 (x86)?

 

I recently encountered the error 4756 during a strategy test  and adding the line above fixed it.

 
k.doras:

Is the necessity to add 

 

 a bug in build 975 (x86)?

 

I recently encountered the error 4756 during a strategy test  and adding the line above fixed it.

These line is mandatory (or equivalent initialisation of request structure).
 

hi

send order work in demo account but in real account don't work(2014.11.30 18:21:00.062 55 (اخابر,D1) BuyA: error 4756, retcode = 10006)

{
//--- prepare the request
   MqlTradeRequest request;
   MqlTradeResult  result;
   MqlTradeCheckResult check;
   ZeroMemory(request);
   ZeroMemory(result);
   ZeroMemory(check);
   request.action=5;
   request.symbol=_Symbol;
   request.volume=1000.00;
   request.price=2652.000;
   request.stoplimit=2652.000;
   request.sl=0;
   request.tp=0;
   request.type=6;
   request.type_filling=2;
   request.type_time=0;
   request.expiration=0;
   request.magic=0;
   request.comment="";

   if(!OrderSend(request,result))
     {
      Print(__FUNCTION__,": error ",GetLastError(),", retcode = ",result.retcode);
     }
//---

 


Documentation on MQL5: Standard Constants, Enumerations and Structures / Data Structures / Structure of Request Check Results
Documentation on MQL5: Standard Constants, Enumerations and Structures / Data Structures / Structure of Request Check Results
  • www.mql5.com
Standard Constants, Enumerations and Structures / Data Structures / Structure of Request Check Results - Reference on algorithmic/automated trading language for MetaTrader 5