Basically when I open a buy stop order without stop loss and take profit I got the error number 130 (ERR_INVALID_STOPS) .
On my code I have checked the limitations as defined on this page:https://book.mql4.com/appendix/limits
So on the price order I have check the stop level and freeze level limitation. You will find below my code openind the order. I got the error 130 when I call the function as following:
int OrderOpenBuyStopOrder(
double OO_volume,
double OO_price,
int OO_magic)
{
int result = -1; //result of opening an orderint Error = 0; //error when opening an orderint attempt = 0; //amount of performed attemptsint attemptMax = 3; //maximum amount of attemptsbool exit_loop = false; //exit the loopdouble stoplevel = MarketInfo(Symbol(),MODE_STOPLEVEL)*Point; //minimum stop loss/ take profit level, in points or pending orderdouble freezelevel = MarketInfo(Symbol(),MODE_FREEZELEVEL)*Point;
//the module provides safe order opening. //--- check stop orders for buy stopdouble min_price=Ask-stoplevel; //limitation with stop leveldouble checked_price=OO_price;
checked_price=MathMax(min_price,checked_price);
min_price=Ask-freezelevel; //limitation with freeze level
checked_price=NormalizeDouble(MathMax(min_price,checked_price),Digits);
//--- while loopwhile(!exit_loop)
{
result=OrderSend(Symbol(),OP_BUYSTOP,OO_volume,checked_price,3,0,0,"test",OO_magic,0,clrWhite); //attempt to open an order using the specified parameters//--- if there is an error when opening an orderif(result<0)
{
Error = GetLastError(); //assign a code to an errorswitch(Error) //error enumeration
{ //order closing error enumeration and an attempt to fix themcase2:
if(attempt<attemptMax)
{
attempt=attempt+1; //define one more attemptSleep(3000); //3 seconds of delayRefreshRates();
break; //exit switch
}
if(attempt==attemptMax)
{
attempt=0; //reset the amount of attempts to zero
exit_loop = true; //exit whilebreak; //exit switch
}
case3:
RefreshRates();
exit_loop = true; //exit whilebreak; //exit switch case4:
if(attempt<attemptMax)
{
attempt=attempt+1; //define one more attemptSleep(3000); //3 seconds of delayRefreshRates();
break; //exit switch
}
if(attempt==attemptMax)
{
attempt = 0; //reset the amount of attempts to zero
exit_loop = true; //exit whilebreak; //exit switch
}
case130:
exit_loop=true; //exit whilebreak;
}
}
//--- if no errors detectedelse
{
Print("The order is successfully opened.", result);
Error = 0; //reset the error code to zerobreak; //exit while//errorCount =0; //reset the amount of attempts to zero
}
}
return(result);
}
//+------------------------------------------------------------------+
Tables below show calculation values that limit the conduction of trades when opening, closing, placing, deleting or modifying orders. To get the minimum distance to StopLevel and freezing distance FreezeLevel the MarketInfo() function should be called. Requirements. Correct prices used when performing trade operations. Order Type Open Price...
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
Hi,
Could you please help with the issue I am facing:
Basically when I open a buy stop order without stop loss and take profit I got the error number 130 (ERR_INVALID_STOPS) .
On my code I have checked the limitations as defined on this page:https://book.mql4.com/appendix/limits
So on the price order I have check the stop level and freeze level limitation. You will find below my code openind the order. I got the error 130 when I call the function as following:
Thanks for your help.