Above snippet works fine in backtest, but first trade on live and BuyTP is short by exactly 6 * Spread + slippage. The shortage from slippage (if any) makes perfect sense, but any idea why Spread seems to have returned 0 in this instance? (Average spread at this broker is .4 pips and this was during Asia so really doubt spread was 0 when trade occurred).
Consensus seems to be use symbol() instead of NULL, but don't think this is issue.
Can easily rectify with an order modify after trade entry and will do this to account for slippage, but would like to fix spread issue at source.
Any help would be much appreciated.
Can easily rectify with an order modify after trade entry and will do this to account for slippage, but would like to fix spread issue at source. Any help would be much appreciated.
double Spread = Ask - Bid; // Ordouble Spread = MarketInfo( _Symbol, MODE_SPREAD ) * _Point; // MarketInfo Spread is in Points// Ordouble Spread = SymbolInfoInteger( _Symbol, SYMBOL_SPREAD ) * _Point; // Compatible with both MQL4 and MQL5
And, don't Hard-Code your constants:
double COpen = iOpen( NULL, PERIOD_H4, 0 ), P2Low = iLow( NULL, PERIOD_H4, 2 );
Also, don't just assume that your stops will work. You should check the Broker's conditions (such as StopLevel): Requirements and Limitations in Making Trades
Why do you divide with 100000? It is already in points.
Hi Fernando thanks for the reply
I note the second spread alternative is near identical to what I have, though it explicitly calls for current symbol rather than using NULL and * _Point is much more versatile if I want to work with JPY etc - you think this will fix my problem?
Regarding Hardcoding Chart Timeframe constants - why is this an issue? Whether I type the Value or ID here function exactly the same no? Former just requires less key strokes.
Regarding Stops - I (and I think most people these days) only work with 'True' ECNs that don't have limitations like this, so not really an issue.
1. Fair call
2. Right, sorry.
3. Thanks, just noticed doc for MI doesn't say 'NULL means the current symbol.'
4 / 5. Yes wanted price and yes * _Point much more efficient.
6. See my comment about stop limitations. This EA is for private use ... do 4 digit brokers still exist? Have JPY sorted in full code.
1. Great yep after WH pointed out doc doesn't mention NULL works makes sense.
2. Fair call.
3. See above, EA for private use. Waste of time coding for this when I never trade with MMs or pseudo-ECNs but fair call re: best practice / good code.
Thanks guys, always a pleasure and once again sorry re: wrong forum
Don't assume that non-ECN automatically means MM/DD. There are other types of NDD (non MM/DD) accounts besides ECN, such as STP, DMA and other hybrids and variations.
Also, even if you are just coding for yourself, there might come a time when you want to use your EA in other environments and brokers, at which time it won't work correctly and you will waste time trying to fix something that could have done correctly the first time around. The added bonus of doing it right the first time, is that you can reuse the code for other EA projects.
Think like a professional coder and don't slack off. The same "professional" attitude is also required for successful trading. If you tend to slack-off in one area of your life, you probably do it in other areas too. So develop that trait in yourself to be rigorous in all that you do.