It has been discussed so many times. I hope you searched on the forum at least.
In your log we can't see the order type. Are they market orders or pending orders? Seems like market orders but then, on attempt 434, for
example, why is the 'ask' different of the 'price' ?
What is the ND() code ?
Hi Alain, thanks for replying, I certainly searched the forum, as I stated I read almost all google results for error 130...
And you're right I planned on changing the logging code to be 200% sure I was entering market orders, but if you look below at this particular snippet of the code I'm confident (but may be wrong) I'm going with market orders as soon as the price goes beyond my planned entry price
at attempt 434 (and all attempts before) the Ask is still below my planned entry price (I try to enter beyond the close of the setup bar, for confirmation), so I'm still trying to enter with a limit order (failing because too close to Ask) at attempt 436 Ask reaches planned entry price, order type should change to market order (see below) but no trade :(
ND is NormalizeDouble with default Digits() (rewrote the function for brevity)
double price = ND(ep); if(tradedir>0 && Ask>=price) {otyp = OP_BUY; price = Ask;} else otyp = OP_BUYSTOP; if(tradedir<0 && Bid<=price) {otyp = OP_SELL; price = Bid;} else otyp = OP_SELLSTOP;
- www.mql5.com
Hi Alain, thanks for replying, I certainly searched the forum, as I stated I read almost all google results for error 130...
And you're right I planned on changing the logging code to be 200% sure I was entering market orders, but if you look below at this particular snippet of the code I'm confident (but may be wrong) I'm going with market orders as soon as the price goes beyond my planned entry price
at attempt 434 (and all attempts before) the Ask is still below my planned entry price (I try to enter beyond the close of the setup bar, for confirmation), so I'm still trying to enter with a limit order (failing because too close to Ask) at attempt 436 Ask reaches planned entry price, order type should change to market order (see below) but no trade :(
ND is NormalizeDouble with default Digits() (rewrote the function for brevity)
otyp = OP_BUY; price = Ask;
If it was a market order, the price should be equal to ask. So my hypothesis is it's actually not a market order but a pending order which is too
close to the market.
Sorry but I can't help without more information. Improve your log the include all relevant information. Add the order type, the 'ep' value, the
bid AND the ask (in all cases), before AND after your OrderSend(). To get the updated Bid/Ask after your OrderSend() use RefreshRates().
@Alain Verleyen thank you, I enriched the log, it will surely help
@lippmaje correct, the original code was meant to be more general, but I'm always using it on the current chart symbol. True that the extensions I made are not as general, will fix it
Also: today I also found an error 136 and searching the forum lead me to think that also the way I set my slippage at just "3" may be incorrect (was never a problem with Oanda... puzzling...)
tkt = OrderSend(sym, otyp, NL(lots), price, 3, ND(slMod), ND(tp), desc, magicno);
changed according to another suggestion I read there from WHROEDER, this is now SlippagePips * pips2points where SlippagePips =2 and pips2points is computed in init() to take into account the number of digits for the current pair. Just saying, maybe I'll catch 2 birds (136+130) with just this stone...
@Alain Verleyen thank you, I enriched the log, it will surely help
@lippmaje correct, the original code was meant to be more general, but I'm always using it on the current chart symbol. True that the extensions I made are not as general, will fix it
Also: today I also found an error 136 and searching the forum lead me to think that also the way I set my slippage at just "3" may be incorrect (was never a problem with Oanda... puzzling...)
changed according to another suggestion I read there from WHROEDER, this is now SlippagePips * pips2points where SlippagePips =2 and pips2points is computed in init() to take into account the number of digits for the current pair. Just saying, maybe I'll catch 2 birds (136+130) with just this stone...
Thank you Alain!!! The extended logging did the trick, I was seeing a Sell stop order when expecting a buy, due to this piece of code
if(tradedir>0 && Ask>=price) {otyp = OP_BUY; price = Ask;} else otyp = OP_BUYSTOP; if(tradedir<0 && Bid<=price) {otyp = OP_SELL; price = Bid;} else otyp = OP_SELLSTOP;
the program always went thru the second else even for long trades (tradedir>0) whenever Bid > price
as always, great contribution!
Thank you Alain!!! The extended logging did the trick, I was seeing a Sell stop order when expecting a buy, due to this piece of code
the program always went thru the second else even for long trades (tradedir>0) whenever Bid > price
as always, great contribution!
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I'm going crazy, I think I checked all google results on how to avoid error 130 but still... hope somebody can point me in the right direction
here's the function I use to send orders:
-order without Stoploss (0 for longs, 99999 for shorts, actual stoploss to be added only after the order is accepted) to avoid 130 coming from that side
-it tries iteratively to enter with a limit order a couple pips away, but if Ask/bid reach my entry price then tries a market order at Ask or Bid, in case of error 130 sleeps a while, refreshes rates and tries again with limit or market order, same logic
-Stoplevel + spreads are already included in actual SL distance, but at the moment SL is only a subsequent modification of the trade, I never get there
-NL = NormalizeLots, ND = NormalizeDigits
-it logs everything at every cycle, see the log below
Here's an example of the log
tryng to enter at 0.66934
Ask is initially 0.66932 but after some iterations (at 436) goes beyond my (buy) entry price, and then you can see that the entry price follows the ask to 0.66934, but the ordersend still gives 130...
SLDelta tracks the distance between entry price and Stoploss, but as I said that's for later modification of the ticket
Stoplevel is 60 points, spread 6 or 9 points, limit entry price is closer than that, but then why I can't enter with market order?
Thanks in advance
Luigi