there is another link that describes 0 as "floating". My old broker had 0, just like my current broker. But my current broker, never gives me that error when i set stop level of 20 points, however, with old broker I had to put 70 points to keep from getting that error. But note that these are floating or as you found "dynamic". So you wont get that error all the time.
However, as some moderators might comment -- you dont need to have an ea to do pending orders. I suggest that you make the ea wait until a desired price, and then open a market order, instead.
/EDIT: do not forget that you may need to add FREEZE_LEVEL as well as stop level.I followed your advice and set both Take Profit and Stop Loss to 0 now:
void SendOrder() { ResetLastError(); Print("StopLoss: ", stoploss.GetNormalizedPrice(), "; minimal sl: ", MarketInfo(_Symbol,MODE_STOPLEVEL)); Print("Entry: ", entry.GetNormalizedPrice()); Print("Take Profit: ", takeProfit); Print("Ask: ", Ask); Print("Bid: ", Bid); ticket = OrderSend( _Symbol, GetIsBuy() ? OP_BUYLIMIT : OP_SELLLIMIT, LotSize(), entry.GetNormalizedPrice(), GetIsBuy() ? gLiveSlippageBuy : gLiveSlippageSell, 0, 0 ); if (ticket < 0) { Print("OrderSend failed; error: ", GetLastError()); } else { Print("OrderSend placed successfully"); } }
but the error is still there. What do I do wrong?
I followed your advice and set both Take Profit and Stop Loss to 0 now:
but the error is still there. What do I do wrong?
Dare I ask the obvious question...
Shouldn't you be sending stop orders as stoplosses instead of limit orders?
I've been debugging this for the last 10 hours or so with multiple versions of the function open in the same time. Either I copied the wrong one to the comment above, or I am an idiot. Let me check.
I've been debugging this for the last 10 hours or so with multiple versions of the function open in the same time. Either I copied the wrong one to the comment above, or I am an idiot. Let me check.
You're welcome. You were rather straightforward in your OP when you said that you're fairly new to trading commands. There's no need to beat yourself up. This is the whole point of this forum.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello! I’ve been working on my EA for the past several months. Today, I finally reached the stage where I can start using the Strategy Tester. Unfortunately, I encountered an error. Since I am fairly new to trading commands, I searched the forum for general advice. Thanks to the courtesy of several forum members who uploaded their code in response to other users’ inquiries, I implemented the following functions in my code:
The part of the code responsible for sending an order is:
This is the output from the terminal for an attempt to send an order on Decemeber 30, 2024, at 12:10, EURUSD:
OrderSend failed; error: 130
OrderSend error 130
Bid 1.04462
Ask: 1.04464 (I set spread as 2 to see if it makes a difference; it doesn't)
Take Profit: 1.04094
Entry: 1.04461
StopLoss: 1.04598; minimal sl: 0.0
I read that if minal sl is set to 0, this means that the broker doesn't know it (https://www.mql5.com/en/forum/360654, comment #3) and it is stated on mql4 website (here: https://docs.mql4.com/trading/ordersend): "A zero value of MODE_STOPLEVEL means either absence of any restrictions on the minimal distance for Stop Loss/Take Profit or the fact that a trade server utilizes some external mechanisms for dynamic level control, which cannot be translated in the client terminal".However, I failed to find any source providing a definitive answer on how to deal with this situation. In comment #3 of the forum thread I linked, the user claims that at least 2 pips are required - but in my case, the difference is already greater than that. What can I do to resolve this error? Where is my mistake?