- Features of the mql4 language, subtleties and techniques
- Algorithms, solution methods, comparison of their performance
- Artificial neural networks.
whena position is successfullyopened by a market order, a null Result.deal is obtained every time?
After executing OrderSend, addressing the corresponding order, position, or trade is not always successful. There are situations when it is necessary to wait for several tens of milliseconds until historical or current trade information becomes correct.
Forum on trading, automated trading systems and trading strategies testing
TakeProfit (and StopLoss) of a closed position
fxsaber, 2016.07.17 20:19
This is not indiscriminate accusation, but the result of hours of trying to find out (no HistorySelectByPosition and other stuff helps) how everything works. And I'm happy to apologize if I'm wrong. So as not to be unfounded, I bring an Expert Advisor for the tester (it's easier to understand) on the server RoboForexEU-MetaTrader 5, which opens a position and then puts SL and TP levels.
void OnTick() { static bool Flag = true; if (Flag) { // Открываем SELL-позицию MqlTradeRequest Request = {0}; Request.action = TRADE_ACTION_DEAL; Request.symbol = Symbol(); Request.volume = 1; Request.price = SymbolInfoDouble(Symbol(), SYMBOL_BID); Request.type = ORDER_TYPE_SELL; MqlTradeResult Result; if (OrderSend(Request, Result)) { // Устанавливаем SL и TP Request.position = Result.deal; Request.action = TRADE_ACTION_SLTP; Request.tp = Result.ask - 10 * _Point; Request.sl = Result.ask + 10 * _Point; if (OrderSend(Request, Result)) Print("Сделка в тестере закроется либо по SL, TP, либо по окончании бэктеста") ; Flag = false; } } }
In this EA, SL and TP of the only closed position cannot be defined (in OnDeinit). Is it supposed to be like that?
Forum on trading, automated trading systems and trading strategies testing
Alternative to Sleep for running in the tester
Vitalie Postolache, 2017.02.10 18:01
Do the timers work in the MT5 tester?Forum on trading, automated trading systems and testing trading strategies
Alternative to Sleep for running in the tester
Slawa, 2017.02.22 11:16
Yes, but only for the tested Expert Advisor. For indicators used by the Expert Advisor - noForum on trading, automated trading systems and trading strategies testing
Slawa, 2017.02.14 13:46
Why? A single action is enough.While the symbol is selected in the market review and the history on the symbol is held by the Expert Advisor, it is kept in a synchronized state. If the Expert Advisor keeps the history at least once every 2 minutes, then it will be accessed, for example, by copying one bar. If the history is synchronized, no time is spent on copying one bar - only a few clock cycles of the processor. Or, as it was just said here, to ask the number of bars, also a few clock cycles
Forum on trading, automated trading systems and testing trading strategies
Alexey Kozitsyn, 2017.02.14 13:47
Do the indicators include an interval of 2 minutes?
Yes, and by checking the fact of synchronization synchronization will also hold?
Forum on trading, automated trading systems and testing trading strategies
Slawa, 2017.02.14 13:50
This also applies to indicators. Create a 1-minute timer and ask the number of bars of all the timeseries you are interested in.The synchronization is not held by checking the fact of synchronization.
After OrderSend is executed, calling the corresponding order, position, or trade is not always successful. There are situations when it is necessary to wait several tens of milliseconds for historical or current trade information to become correct.
You don't have to wait a few milliseconds.
The message will come in OnTradeTransaction
see code
You don't have to wait a few milliseconds.
The message will come in OnTradeTransaction
see code.
The scripts do not have it. It is stupid to use EA+ExpertRemove instead of script.
Moreover, OrderSend crashes by timeout if there is no response from the server for 180 seconds. This suggests that the OnTradeTransaction may accumulate tickets that are always pending. And the option of just one order_ticket for OnTradeTransaction, as in your script, is bad. The asynchronous sending is followed by the work with the lists of orders. That's why it's asynchronous - to work with batches. And if there is no work with batches, then asynchrony is never needed.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use