OrderSend - error 4059 ERR_FUNCTION_NOT_ALLOWED_IN_TESTING_MODE

 

hi, I have the problem...when i excute the EA. appear the error " ERROR: code=4059 - function is not allowed in testing mode"

double StopLoss=500;
double pips = 0.00001;
extern double TakeProfit=1000;

TicketNumber=OrderSend( Symbol(), OP_BUY, LotSize, Ask, 3, Ask-(StopLoss*pips), Ask+(TakeProfit*pips), CommentName, MAGIC,0,Green);

i copy the code where I think the error must be here because if I put to 0, in the stoploss and takeprofit it works....any idea..??


thanks a lot

 

Hello,

Try with

TicketNumber=OrderSend( Symbol(), OP_BUY, LotSize, Ask, 3, NormalizeDouble(Ask-(StopLoss*pips),Digits), NormalizeDouble(Ask+(TakeProfit*pips),Digits), CommentName, MAGIC,0,Green);
 

thank you very much for the help, but does not work.


the strange thing is that just opens the position...

thanks

 
serdan:

thank you very much for the help, but does not work.


the strange thing is that just opens the position...

thanks

Show the code that is producing the error message. Are you using MarketInfo() anywhere ?
 
franky:

Hello,

Try with

What does NormalizeDouble() have to do with this issue ?
 
RaptorUK:
What does NormalizeDouble() have to do with this issue ?


if the value "StopLoss" or "TakeProfit" is changed by a function before being called by OrderSend, it may send an error "Invalid S/L or T/P" if there is a lot of decimal
 
franky:

if the value "StopLoss" or "TakeProfit" is changed by a function before being called by OrderSend, it may send an error "Invalid S/L or T/P" if there is a lot of decimal
The error is 4059 ERR_FUNCTION_NOT_ALLOWED_IN_TESTING_MODE, it says at the top of the thread.
 

thanks for the help, the code is very simple, I'm just starting in the programming of mql.

double StopLoss=500;
double TakeProfit=1000;
double pips = 0.00001;

void openPosition(){ 
int TicketNumber;

        if(IsNewCandle()){
        if( AccountFreeMargin() > 0 ){
                        TicketNumber=OrderSend( Symbol(), OP_BUY, LotSize, Ask, 3, NormalizeDouble(Ask-(StopLoss*pips),Digits), NormalizeDouble(Ask+(TakeProfit*pips),Digits), CommentName, MAGIC,0,Green);
                        if(TicketNumber==-1){logError("openPosition()", "Error opening BUY order SMA4 >= SMA9");}
    }
  }
}                                                              

as data I'm working with micro lots and broker allows 50 points to put the stoploss

 
serdan:

thanks for the help, the code is very simple, I'm just starting in the programming of mql.

as data I'm working with micro lots and broker allows 50 points to put the stoploss


Where do you get error 4059 from ? your code doesn't Print() it or output it to a log . . . why aren't you outputting the error number ?

if(TicketNumber==-1){logError("openPosition() Error opening BUY order SMA4 >= SMA9.  Error # ", GetLastError() );}
 
serdan:

thanks for the help, the code is very simple, I'm just starting in the programming of mql. [...]

What is logError() ? If it uses something like MessageBox() or SendMail() to notify you of problems, then those functions will trigger an error in the backtesting.
 

sorry but my english is not good when i change this parameter works well

TicketNumber=OrderSend( Symbol(), OP_BUY, LotSize, Ask, slippage, 0, 0, CommentName, MAGIC,0,Green);

but if i change it, didnt work

double StopLoss=500;
double TakeProfit=1000;
double pips = 0.00001;
double LotSize=0.01;

void openPosition(){ 
int TicketNumber;
        if(IsNewCandle()){
        if( AccountFreeMargin() > 0 ){
                        TicketNumber=OrderSend( Symbol(), OP_BUY, LotSize, Ask, 3, NormalizeDouble(Ask-(StopLoss*pips),Digits), NormalizeDouble(Ask+(TakeProfit*pips),Digits), CommentName, MAGIC,0,Green);
                        if(TicketNumber==-1){logError("openPosition()", "Error opening BUY order SMA4 >= SMA9");}
    }
  }
}        

void logError(string functionName, string msg, int errorCode = -1)
  {
    Print("ERROR: in " + functionName + "()");
    Print("ERROR: " + msg );
    
    int err = GetLastError();
    if(errorCode != -1) 
        err = errorCode;
        
    if(err != ERR_NO_ERROR) 
      {
        Print("ERROR: code=" + err + " - " + ErrorDescription( err ));
      }    
  }
  
Reason: