You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
I called my DoubleRound function with MODE_TICKVALUE (which is 12.50) instead of MODE_TICKSIZE (0.25).
I fixed it, but it didn't make the #130 go away
Here's a log of the error with the updated DoubleRound line:
for comparison, here is a log, where it worked:
in any case, it seems to work more often now, we are definitely getting closer. :)
in any case, it seems to work more often now, we are definitely getting closer. :)
I can't see why that Modify failed . . . are you getting a fresh Bid/Ask between the OrderSend and OrderModify ?
All I can suggest now is that when you get an error 130 . . . print everything afresh, Bid, Ask (using MarketInfo), OOP, StopLevel, SL you are trying to set, etc, etc.
I called my DoubleRound function with MODE_TICKVALUE (which is 12.50) instead of MODE_TICKSIZE (0.25).
The #130 stoploss error does not appear anymore. The last steps seemed to have finally pinned down the problem.
I will post another post after this, summarizing all steps taken. So others in the forum fighting Error #130 can use this thread as a reference.
Thanks for your ongoing help :).
shinobi
Thanks for your ongoing help :).
shinobi
The most important technique for fighting errors is excessive logging. Make output for everything that could remotely be connected to the error. If you define a log function which you can switch on and off, you can keep the code after having solved the problem.
When initializing your expert adviser you should log all information MarketInfo can tell you: https://docs.mql4.com/constants/marketinfo
Also always be sure to check the return values of functions, e.g. for OrderModify:
ECN Broker require you to make separate orders for buy/sell and stoploss/takeprofit. So you need to split your code into two orders like this:
For sell orders you need to replace OP_BUY by OP_SELL. You also should check the return values of OrderSelect and OrderModify (see General Tips above).
Some Brokers demand stoploss, takeprofit and slippage to be adjusted to 4/5 digits. You can do that with putting the following code into your init() function (thx WHRoeder):
Then you need to multiply stoploss, takeprofit and slippage with pips2db1 before sending it to the Broker
Another possible cause is that market rates changed between the tick activated the Expert Advisor (EA), and the EA OrderSend() or OrderModify() was executed. To avoid this problem, there are two possible solutions:
The first one is to use: RefreshRates() before using predefined market variables like: Ask and Bid. (these variables get their values when the tick activates the EA)
The second one is not to use predefined market variables at all. Instead you can use the current market values with MarketInfo(). Instead of Ask, Bid and Point use
If stoploss or takeprofit are too close to the entry price, the order will be rejected. In order to avoid this problem, you should take into account the current spread between Ask and Bid. Again there are two solutions:
The first one is to compute the spread and add/subtract it to your stoploss/takeprofit.
The second solution to implicitly take the spread into account using Ask and Bid, when computing stoploss or takeprofit:
Brokers have a certain stop level. If your stoploss is below that level, your order will be rejected. You can check the stop level with MarketInfo(Symbol(), MODE_STOPLEVEL).
To avoid this check your stoploss against the broker's stop level and adjust it if necessary:
Freeze Level is a similar concept. Your stoploss also needs to be greater than the broker's freeze level. You can check the freeze level by MarketInfo(Symbol(), MODE_FREEZELEVEL).
To avoid this, again check your stoploss against the broker's freezelevel:
Finally your stoploss or takeprofit might be rejected, because the Symbol only supports stoploss/takeprofit which match it's ticksize. The ticksize is the minimal distance the prize of the symbol can go up and down. E.g. If the price is 1000 and the ticksize 0.25, then the price can only go up or down by a multiple of 0.25 (0.25 * n, where n is a natural number). So the price might go up by 0.25 to 1000.25 or down by 1.75 to 998.25.
To account for ticksize, you need a function to round double values to a certain step value (e.g. the nearest 0.25). Here is such a function:
E.g calling DoubleRound with number = 1023.81234 and step = 0.25 would return 1023.75. Calling it with 1023.967834 would return 1024.00
Now before sending stoploss or takeprofit, round it to the Symbol's ticksize with:
Here is a complete small example taking into account all of the above counter measures:
I hope that helps getting rid of #130. If modifying your code doesn't work, use a minimal example, like the one above, first. And then, when the error disappears take over the changed into your code.
Good Luck,
shinobi
My thanks to Raptor, WHRoeder, SDC, BigAl, gjol and 35806 for helping me get rid of the error and put together this reference.