Download MetaTrader 5
To add comments, please log in or register
Are you a good trader? Become a signals provider and make even more money!
Scarlett
34
Scarlett 2014.11.14 13:06 

Hi,

 I'm trying to open a BUYSTOP order but get  error 130 even though I follow the StopLevel Minimum Distance Limitation.

 

Print("ask price=",DoubleToStr(Ask, print_digits));
Print("bid price=",DoubleToStr(Bid, print_digits));

double stop_level_points = MarketInfo(Symbol(),MODE_STOPLEVEL);
Print("Stop level in points=",stop_level_points);
   
double stop_level = stop_level_points * Point;
Print("stop_level=",stop_level);

double price_diff = enter_price - Ask;
Print("price_diff=",DoubleToStr(price_diff, print_digits));
                
if(price_diff >= stop_level)
{
    Print("Enter price is far enough from Ask to use pending");
    order_type = OP_BUYSTOP;
}
else if(price_diff >= 0)
{
    Print("Ask is below enter price but not far enough for pending");
                   
    if(price_diff > allowed_advancement)
    {
        Print("enter price is more than " , allowed_advancement , " pip away -  enter in pending");                   
        order_type = OP_BUYSTOP;
        enter_price = Ask + stop_level;
    }
    else
    {
        Print("enter price is less than " , allowed_advancement , " pip away -  enter in market");
        order_type = OP_BUY;
        enter_price = Ask;
    }
}

ticket = OrderSend(symbol, order_type, first_lot_size, enter_price, slippage, stoploss, takeprofit, comment, magic_number, expiration, arrow_color);               
      
if(ticket == -1)
{
    Print("OrderSend failed for first order with error #",GetLastError());
}

Print("ask price=",DoubleToStr(Ask, print_digits));
Print("bid price=",DoubleToStr(Bid, print_digits));
Print("enter_price=",DoubleToStr(enter_price, print_digits));
Print("stoploss=",DoubleToStr(stoploss, print_digits));

The output is:

allowed_advancement=0.0001
ask price=1.3353700
bid price=1.3351900
Stop level in points=30.0
stop_level=0.0003
price_diff=0.0003000
Ask is below enter price but not far enough for pending
enter price is more than 0.0001 pip away -  enter in pending
OrderSend error 130
OrderSend failed for first order with error #130
ask price=1.3353700
bid price=1.3351900
enter_price=1.3356700
stoploss=1.3320100
Scarlett
34
Scarlett 2014.11.14 13:12  

The post got sent before I finished...

 I don't understand why the script doesn't return true in the first if statement : if(price_diff >= stop_level)

if stop_level=0.0003 and price_diff=0.0003000

and then why do I still get error 130 if I change the enter price to Ask + stop_level

 

any ideas?  

 

Thanks 

Keith Watford
Moderator
8016
Keith Watford 2014.11.14 13:16  
What is the value of takeprofit?
whroeder1
13644
whroeder1 2014.11.14 14:57  
sa1221: BUYSTOP order but get  error 130 even though I follow the StopLevel Minimum Distance Limitation.
Error 130 Pain - MQL4 forum 7A
Scarlett
34
Scarlett 2014.11.14 15:17  
GumRai:
What is the value of takeprofit?

No takeprofit. 

takeprofit = 0;

Scarlett
34
Scarlett 2014.11.14 15:19  
WHRoeder:
sa1221: BUYSTOP order but get  error 130 even though I follow the StopLevel Minimum Distance Limitation.
Error 130 Pain - MQL4 forum 7A
I've opened a lot of orders with the same code. The error happens only in this specific case when price_diff=0.0003 (and stop_level=0.0003), so I don't think it's because of the TP/SL... but I'll try
SYED NAUFAL GADDAFI
1401
SYED NAUFAL GADDAFI 2014.11.14 15:33  
if ( price_diff==0.0003 && stop_level==0.0003) stop_level = stop_level + 0.0001;
Well, something like that.
Scarlett
34
Scarlett 2014.11.15 17:57  

I've printed the price_diff without DoubleToStr and found it is actually: 0.000299999999999967

so I've added this code to fix this:

double compare_to_stop_level = stop_level - price_diff;
...

if(compare_to_stop_level < tenth_of_pip){

        Print("enter price is almost exactly " , stop_level , " pips away -  enter in pending");                      

        order_type = OP_BUYSTOP;         

        enter_price = Ask + stop_level + tenth_of_pip;

} 
/
To add comments, please log in or register