I know, I know!! it's probably the most asked question but I am buggered if I can figure it so please take a look at this and tell me what I am doing wrong as it's not working in backtesting
There's multiple possible causes, and the Journal section of the backtesting should tell you why orders are being rejected.
But it's probably the distance to the s/l. You're reading the MODE_STOPLEVEL value, but not doing anything with it. You should also bear in mind that, on a market order, the minimum distance to the s/l is MODE_STOPLEVEL plus the spread. Therefore, your code will fail even when MODE_STOPLEVEL = 0 if the spread is more than 10 * Point.
JC:
Journal says #130 (stoploss) and I know I'm not doing anything with minstoplevel but as you can see I have (I think) set the stop level to Ask+10 / Bid-10 points, this should be more than enough right?
Steve
this should be more than enough right?
Probably not, no.
Point will usually be a value such as 0.00001. You may be assuming that it is a "pip", i.e. 10 times larger, at 0.0001. Unless you are using one of the very few remaining 4DP accounts offered by brokers, where Point is 0.0001, then your stop is 1 pip, not 10 pips.
Wow no wonder I am confused! OK printed out what Point is in the log and it's 0.1 so if I want a stop of 10 pips do I just multiply Point by 100? (hang on I tried that and the stop was way off, I then tried * 10 and it appears to work even though I don't understand why 10*0.1 = 10 and not 1) OK this appears to at least create an order but it says "close at stop" however there are days of data left to run so not sure why it closed the order.
Thanks
Steve
Wow no wonder I am confused! OK printed out what Point is in the log and it's 0.1 so if I want a stop of 10 pips do I just multiply Point by 100?
If Point is 0.1 then you're presumably dealing with a non-fx instrument, and there's absolutely no consensus about what a "pip" is on gold, or oil, or the S&P500 etc - it's not a term particularly widely used outside of fx.
Avoiding the term "pip"... If you want your stop-distance to be a change in price of 10 (e.g. a change in the gold price from 1262.5 to 1252.5), and Point is 0.1, then, yes, you would need to multiply Point by 100.
JC
No this is UKFTSE :-(
P.S. I amended my previous post as you replied
Steve
P.S. Thanks for your help so far.
stoploss=NormalizeDouble(Ask-(10*Point),Digits); takeprofit=NormalizeDouble(Ask+(10*Point),Digits); OrderPrice = Ask; ticket=OrderSend(Symbol(),OP_BUY,0.01,OrderPrice,3,stoploss,takeprofit,"My order",16384,0,clrGreen);
- You buy at the Ask, therefor your stops must be relative to the Bid. If the spread is greater than 10 points, your SL is below market.
- You can't move stops closer to the market than the minimum (MODE_STOPLEVEL *
_Point.) Requirements and Limitations in
Making Trades - Appendixes - MQL4 Tutorial Is stop level larger than 10?
- You are not adjusting SL, TP, and slippage; for 4/5 digit brokers and for JPY pairs.
- Do NOT use NormalizeDouble, EVER. For ANY Reason. It's a kludge, don't
use it. It's use is always
wrong
- SL/TP (stops) need to be normalized to tick size (not Point.) (On 5Digit Broker Stops are only allowed to be placed on full pip values. How to find out in mql? - MQL4 forum) and abide by the limits Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial and that requires understanding floating point equality Can price != price ? - MQL4 forum
- Open price for pending orders need to be adjusted. On Currencies, Point == TickSize, so you will get the same answer, but it won't work on Metals. So do it right: Trailing Bar Entry EA - MQL4 forum or Bid/Ask: (No Need) to use NormalizeDouble in OrderSend - MQL4 forum
- Lot size must also be adjusted to a multiple of LotStep and check against min and max. If that is not a power of 1/10 then NormalizeDouble is wrong. Do it right.
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi All,
I know, I know!! it's probably the most asked question but I am unable to figure it so please take a look at this and tell me what I am doing wrong as it's not working in backtesting
Broker = intertrader
Thanks Steve