Подскажите где мне прочитать такую информацию.
- Работа экспертов
- Советник
- Значение индикатора на другом временном интервале.
Both experts cannot send orders simultaneously. They must wait for the trade content to be free.
I'm using this code:
//+--------------------------------------------------------------------+ //| File name: MT4-FST Expert.mq4 | //| Version: 0.11 Beta 2009-12-10 | //| Copyright: © 2009, Miroslav Popov - All rights reserved! | //| Website: http://forexsb.com/ | //| Support: http://forexsb.com/forum/ | //| License: Freeware under the following circumstances: | //| | //| This code is a part of Forex Strategy Trader. It is free for | //| use and distribution as an integral part of Forex Strategy Trader. | //| One can modify it in order to improve the code or to fit it for | //| personal use. This code or any part of it cannot be used in | //| another applications without a permission. Contact information | //| cannot be changed. | //| | //| NO LIABILITY FOR CONSEQUENTIAL DAMAGES | //| | //| In no event shall the author be liable for any damages whatsoever | //| (including, without limitation, incidental, direct, indirect and | //| consequential damages, damages for loss of business profits, | //| business interruption, loss of business information, or other | //| pecuniary loss) arising out of the use or inability to use this | //| product, even if advised of the possibility of such damages. | //+--------------------------------------------------------------------+ #define TRADE_SEMA_NAME "TradeIsBusy" #define TRADE_SEMA_WAIT 100 #define TRADE_SEMA_TIMEOUT 10000 #define TRADE_RETRY_COUNT 4 #define TRADE_RETRY_WAIT 100 ... /// /// Expert's initialization function. /// int init() { ... ReleaseTradeContext(); ... } ... /// /// Modifies the position's Stop Loss and Take Profit. /// int ModifyPositionByTicket(string symbol, int orderTicket, double stopLossPrice, double takeProfitPrice) { ... for (int attempt = 0; attempt < TRADE_RETRY_COUNT; attempt++) { ... if (!GetTradeContext()) return (-1); bool rc = OrderModify(orderTicket, orderOpenPrice, stopLossPrice, takeProfitPrice, 0); ReleaseTradeContext(); ... Sleep(TRADE_RETRY_WAIT); } return (-1); } ... /// /// Sets a global variable to show that the trade content is busy. /// bool GetTradeContext() { int start = GetTickCount(); GetLastError(); while (!GlobalVariableSetOnCondition(TRADE_SEMA_NAME, 1, 0)) { int gle = GetLastError(); if (gle != 0) Print("GTC: Error in GlobalVariableSetOnCondition: ", GetErrorDescription(gle)); if (IsStopped()) return (false); if (GetTickCount() - start > TRADE_SEMA_TIMEOUT) { Print("GTC: Timeout!"); return (false); } Sleep(TRADE_SEMA_WAIT); } return (true); } /// /// Releases the global variable about the trade content. /// void ReleaseTradeContext() { while (!GlobalVariableSet(TRADE_SEMA_NAME, 0)) { int gle = GetLastError(); if (gle != 0) Print("RTC: Error in GlobalVariableSet: ", GetErrorDescription(gle)); if (IsStopped()) return; Sleep(TRADE_SEMA_WAIT); } }
Miroslav_Popov >>:
Both experts cannot send orders simultaneously. They must wait for the trade content to be free.
I'm using this code:
Получать от ворот поворот только потому что контекст занят?
I'm using this code:
void WaitForContext() { while (IsTradeContextBusy()) { Sleep(100); } }
Вызываю эту функцию непосредственно перед обращением к контексту. Не подводила ни разу, хотя иногда на счете стояло больше 10 роботов.
И кстати проще намного. А про критическую секцию разговор был -- средствами MQL без задействования WinAPI критическую секцию без коллизий получить нельзя.
Удачи.
Вы упускаете торговые возможности:
- Бесплатные приложения для трейдинга
- 8 000+ сигналов для копирования
- Экономические новости для анализа финансовых рынков
Регистрация
Вход
Вы принимаете политику сайта и условия использования
Если у вас нет учетной записи, зарегистрируйтесь