MetaEditor yapı 1490 - sayfa 2

 
Andrey Dik :

SL/TP'nin OnTradeTransaction() içinde çalıştığını nasıl bilebilirim?

OnTrade*'deki mesajların mantığını anlamak için, ilgilenilen olayın gerçekleştiği andaki giriş parametrelerini yazdırırım.

Aynısını yapın, her şey hemen netleşecek.

Not MT5'teki TP'nin her zaman (MT4'ün aksine) borsada / ECN'de değil, MT5 sunucusunda asılı olan bir piyasa emri olduğunu unutmayın. Buna göre tetiklendiğinde herhangi bir işarette gecikme + piyasa kayması olacaktır. Bazı MT4 TP'lerinde, doğrudan ECN'ye verilen limit emirleri vardır. Bu nedenle gecikme (MT-ECN) ve negatif kayma yoktur, ancak reddetmeler vardır. Dolayısıyla TP, MT5'in MT4'e göre güçlü dezavantajlarından biridir.

 
fxsaber :

OnTrade*'deki mesajların mantığını anlamak için, ilgilenilen olayın gerçekleştiği andaki giriş parametrelerini yazdırırım.

Aynısını yapın, her şey hemen netleşecek.

Sınanmış. Bu durumda OnTrade()'den, her bir ticaret olayının geçmişini işlemeniz gerektiğinden hiçbir faydası, hatta zararı yoktur.

Olay türüne göre filtreleyebileceğiniz için OnTradeTransaction()'da SL/TP tetiklemesi hakkında bilgi sahibi olmak mantıklıdır. Bu durumda olay tipini "Geçmişe Ekleme", ardından ticaret tipini "Çıkış" ve ardından çıkmaz sokak olarak tanımladım.

 
Andrey Dik :

Sınanmış. Bu durumda OnTrade()'den, her bir ticaret olayının geçmişini işlemeniz gerektiğinden hiçbir faydası, hatta zararı yoktur.

OnTrade * ile ilgiliydi.
 
fxsaber :
OnTrade * ile ilgiliydi.
Evet anladım. Sınanmış. Hiçbir şey bulmayı başaramadım (ihtiyacım olandan).
 
#include <MT4Orders.mqh> // https://www.mql5.com/ru/code/16006

bool FirstRun = true ;

void OnTick ()
{  
   if (FirstRun)    
  {
     const double Price = SymbolInfoDouble ( _Symbol , SYMBOL_ASK );
    
    FirstRun = ( OrderSend ( _Symbol , OP_BUY , 1 , Price, 0 , 0 , Price + 10 * _Point ) <= 0 );
  }
}

void OnTradeTransaction ( const MqlTradeTransaction &Trans, const MqlTradeRequest &Request, const MqlTradeResult &Result )
{
   if (!FirstRun)
     Print (ToString(Trans) + ToString(Request) + ToString(Result));
}

#define TOSTRING(A)   #A + " = " + ( string )(A) + "\n"
#define TOSTRING2(A) #A + " = " + EnumToString (A) + "\n"

string ToString( const MqlTradeTransaction &Trans )
{
   return (TOSTRING(Trans.deal) + TOSTRING(Trans.order) + TOSTRING(Trans.symbol) +
         TOSTRING2(Trans.type) + TOSTRING2(Trans.order_type) + TOSTRING2(Trans.order_state) +
         TOSTRING2(Trans.deal_type) + TOSTRING2(Trans.time_type) +
         TOSTRING(Trans.time_expiration) + TOSTRING(Trans.price) + TOSTRING(Trans.price_trigger) +
         TOSTRING(Trans.price_sl) + TOSTRING(Trans.price_tp) + TOSTRING(Trans.volume) +
         TOSTRING(Trans.position) + TOSTRING(Trans.position_by));
}

string ToString( const MqlTradeRequest &Request )
{
   return (TOSTRING2(Request.action) + TOSTRING(Request.magic) + TOSTRING(Request.order) +
         TOSTRING(Request.symbol) + TOSTRING(Request.volume) + TOSTRING(Request.price) +
         TOSTRING(Request.stoplimit) + TOSTRING(Request.sl) +  TOSTRING(Request.tp) +
         TOSTRING(Request.deviation) + TOSTRING2(Request.type) + TOSTRING2(Request.type_filling) +
         TOSTRING2(Request.type_time) + TOSTRING(Request.expiration) + TOSTRING(Request.comment) +
         TOSTRING(Request.position) + TOSTRING(Request.position_by));
}

string ToString( const MqlTradeResult &Result )
{
   return (TOSTRING(Result.retcode) + TOSTRING(Result.deal) + TOSTRING(Result.order) +
         TOSTRING(Result.volume) + TOSTRING(Result.price) + TOSTRING(Result.bid) +  
         TOSTRING(Result.ask) + TOSTRING(Result.comment) + TOSTRING(Result.request_id) +  
         TOSTRING(Result.retcode_external));
}
test sonucu
2016.11 . 23 23 : 59 : 57    take profit triggered # 2 buy 1.00 EURUSD 1.06235 tp: 1.06245 [ # 3 sell 1.00 EURUSD at 1.06245 ]
2016.11 . 23 23 : 59 : 57    deal # 3 sell 1.00 EURUSD at 1.06245 done (based on order # 3 )
2016.11 . 23 23 : 59 : 57    deal performed [ # 3 sell 1.00 EURUSD at 1.06245 ]
2016.11 . 23 23 : 59 : 57    order performed sell 1.00 at 1.06245 [ # 3 sell 1.00 EURUSD at 1.06245 ]
2016.11 . 23 23 : 59 : 57    Trans.deal = 3
2016.11 . 23 23 : 59 : 57    Trans.order = 3
2016.11 . 23 23 : 59 : 57    Trans.type = TRADE_TRANSACTION_DEAL_ADD
2016.11 . 23 23 : 59 : 57    Trans.order_type = ORDER_TYPE_BUY
2016.11 . 23 23 : 59 : 57    Trans.order_state = ORDER_STATE_STARTED
2016.11 . 23 23 : 59 : 57    Trans.deal_type = DEAL_TYPE_SELL
2016.11 . 23 23 : 59 : 57    Trans.time_type = ORDER_TIME_GTC
2016.11 . 23 23 : 59 : 57    Trans.time_expiration = 1970.01 . 01 00 : 00 : 00
2016.11 . 23 23 : 59 : 57    Trans.price = 1.06245
2016.11 . 23 23 : 59 : 57    Trans.price_trigger = 0.0
2016.11 . 23 23 : 59 : 57    Trans.price_sl = 0.0
2016.11 . 23 23 : 59 : 57    Trans.volume = 1.0
2016.11 . 23 23 : 59 : 57    Trans.position = 2
2016.11 . 23 23 : 59 : 57    Trans.position_by = 0
2016.11 . 23 23 : 59 : 57    Request.action = ENUM_TRADE_REQUEST_ACTIONS :: 0
2016.11 . 23 23 : 59 : 57    Request.magic = 0
2016.11 . 23 23 : 59 : 57    Request.order = 0
2016.11 . 23 23 : 59 : 57    Request.symbol =
2016.11 . 23 23 : 59 : 57    Request.volume = 0.0
2016.11 . 23 23 : 59 : 57    Request.price = 0.0
2016.11 . 23 23 : 59 : 57    Request.sl = 0.0
2016.11 . 23 23 : 59 : 57    Request.tp = 0.0
2016.11 . 23 23 : 59 : 57    Request.deviation = 0
2016.11 . 23 23 : 59 : 57    Request.type = ORDER_TYPE_BUY
2016.11 . 23 23 : 59 : 57    Request.type_filling = ORDER_FILLING_FOK
2016.11 . 23 23 : 59 : 57    Request.type_time = ORDER_TIME_GTC
2016.11 . 23 23 : 59 : 57    Request.expiration = 1970.01 . 01 00 : 00 : 00
2016.11 . 23 23 : 59 : 57    Request.comment =
2016.11 . 23 23 : 59 : 57    Request.position = 0
2016.11 . 23 23 : 59 : 57    Result.retcode = 0
2016.11 . 23 23 : 59 : 57    Result.deal = 0
2016.11 . 23 23 : 59 : 57    Result.order = 0
2016.11 . 23 23 : 59 : 57    Result.volume = 0.0
2016.11 . 23 23 : 59 : 57    Result.price = 0.0
2016.11 . 23 23 : 59 : 57    Result.bid = 0.0
2016.11 . 23 23 : 59 : 57    Result.ask = 0.0
2016.11 . 23 23 : 59 : 57    Result.comment =
2016.11 . 23 23 : 59 : 57    Result.request_id = 0
2016.11 . 23 23 : 59 : 57   
2016.11 . 23 23 : 59 : 57    Trans.deal = 0
2016.11 . 23 23 : 59 : 57    Trans.order = 3
2016.11 . 23 23 : 59 : 57    Trans.symbol = EURUSD
2016.11 . 23 23 : 59 : 57    Trans.type = TRADE_TRANSACTION_ORDER_DELETE
2016.11 . 23 23 : 59 : 57    Trans.order_type = ORDER_TYPE_SELL
2016.11 . 23 23 : 59 : 57    Trans.order_state = ORDER_STATE_FILLED
2016.11 . 23 23 : 59 : 57    Trans.deal_type = DEAL_TYPE_BUY
2016.11 . 23 23 : 59 : 57    Trans.time_type = ORDER_TIME_GTC
2016.11 . 23 23 : 59 : 57    Trans.price = 1.06245
2016.11 . 23 23 : 59 : 57    Trans.price_trigger = 0.0
2016.11 . 23 23 : 59 : 57    Trans.price_sl = 0.0
2016.11 . 23 23 : 59 : 57    Trans.price_tp = 0.0
2016.11 . 23 23 : 59 : 57    Trans.volume = 1.0
2016.11 . 23 23 : 59 : 57    Trans.position = 2
2016.11 . 23 23 : 59 : 57    Trans.position_by = 0
2016.11 . 23 23 : 59 : 57    Request.action = ENUM_TRADE_REQUEST_ACTIONS :: 0
2016.11 . 23 23 : 59 : 57    Request.magic = 0
2016.11 . 23 23 : 59 : 57    Request.symbol =
2016.11 . 23 23 : 59 : 57    Request.volume = 0.0
2016.11 . 23 23 : 59 : 57    Request.price = 0.0
2016.11 . 23 23 : 59 : 57    Request.stoplimit = 0.0
2016.11 . 23 23 : 59 : 57    Request.sl = 0.0
2016.11 . 23 23 : 59 : 57    Request.tp = 0.0
2016.11 . 23 23 : 59 : 57    Request.deviation = 0
2016.11 . 23 23 : 59 : 57    Request.type = ORDER_TYPE_BUY
2016.11 . 23 23 : 59 : 57    Request.type_filling = ORDER_FILLING_FOK
2016.11 . 23 23 : 59 : 57    Request.expiration = 1970.01 . 01 00 : 00 : 00
2016.11 . 23 23 : 59 : 57    Request.comment =
2016.11 . 23 23 : 59 : 57    Request.position = 0
2016.11 . 23 23 : 59 : 57    Request.position_by = 0
2016.11 . 23 23 : 59 : 57    Result.retcode = 0
2016.11 . 23 23 : 59 : 57    Result.deal = 0
2016.11 . 23 23 : 59 : 57    Result.order = 0
2016.11 . 23 23 : 59 : 57    Result.volume = 0.0
2016.11 . 23 23 : 59 : 57    Result.price = 0.0
2016.11 . 23 23 : 59 : 57    Result.ask = 0.0
2016.11 . 23 23 : 59 : 57    Result.comment =
2016.11 . 23 23 : 59 : 57    Result.request_id = 0
2016.11 . 23 23 : 59 : 57    Result.retcode_external = 0
2016.11 . 23 23 : 59 : 57   
2016.11 . 23 23 : 59 : 57    Trans.deal = 0
2016.11 . 23 23 : 59 : 57    Trans.order = 3
2016.11 . 23 23 : 59 : 57    Trans.symbol = EURUSD
2016.11 . 23 23 : 59 : 57    Trans.type = TRADE_TRANSACTION_HISTORY_ADD
2016.11 . 23 23 : 59 : 57    Trans.order_state = ORDER_STATE_FILLED
2016.11 . 23 23 : 59 : 57    Trans.deal_type = DEAL_TYPE_BUY
2016.11 . 23 23 : 59 : 57    Trans.time_type = ORDER_TIME_GTC
2016.11 . 23 23 : 59 : 57    Trans.time_expiration = 1970.01 . 01 00 : 00 : 00
2016.11 . 23 23 : 59 : 57    Trans.price = 1.06245
2016.11 . 23 23 : 59 : 57    Trans.price_trigger = 0.0
2016.11 . 23 23 : 59 : 57    Trans.price_sl = 0.0
2016.11 . 23 23 : 59 : 57    Trans.price_tp = 0.0
2016.11 . 23 23 : 59 : 57    Trans.volume = 0.0
2016.11 . 23 23 : 59 : 57    Trans.position_by = 0
2016.11 . 23 23 : 59 : 57    Request.action = ENUM_TRADE_REQUEST_ACTIONS :: 0
2016.11 . 23 23 : 59 : 57    Request.magic = 0
2016.11 . 23 23 : 59 : 57    Request.order = 0
2016.11 . 23 23 : 59 : 57    Request.symbol =
2016.11 . 23 23 : 59 : 57    Request.volume = 0.0
2016.11 . 23 23 : 59 : 57    Request.price = 0.0
2016.11 . 23 23 : 59 : 57    Request.stoplimit = 0.0
2016.11 . 23 23 : 59 : 57    Request.sl = 0.0
2016.11 . 23 23 : 59 : 57    Request.deviation = 0
2016.11 . 23 23 : 59 : 57    Request.type = ORDER_TYPE_BUY
2016.11 . 23 23 : 59 : 57    Request.type_filling = ORDER_FILLING_FOK
2016.11 . 23 23 : 59 : 57    Request.type_time = ORDER_TIME_GTC
2016.11 . 23 23 : 59 : 57    Request.expiration = 1970.01 . 01 00 : 00 : 00
2016.11 . 23 23 : 59 : 57    Request.comment =
2016.11 . 23 23 : 59 : 57    Request.position = 0
2016.11 . 23 23 : 59 : 57    Request.position_by = 0
2016.11 . 23 23 : 59 : 57    Result.retcode = 0
2016.11 . 23 23 : 59 : 57    Result.order = 0
2016.11 . 23 23 : 59 : 57    Result.volume = 0.0
2016.11 . 23 23 : 59 : 57    Result.price = 0.0
2016.11 . 23 23 : 59 : 57    Result.bid = 0.0
2016.11 . 23 23 : 59 : 57    Result.ask = 0.0
2016.11 . 23 23 : 59 : 57    Result.comment =
2016.11 . 23 23 : 59 : 57    Result.request_id = 0
2016.11 . 23 23 : 59 : 57    Result.retcode_external = 0
 

fxsaber :

test sonucu

Evet, peki ya sonra?

SL/TP'nin çalıştığını nerede görebilirsiniz? - bu zorluk

 

bir pozisyonu kapattıktan sonra MQL5 kullanarak kar alma ve stoploss değerlerini bulamayacaksınız .

Sorun bu. Ancak MT5, kapalı pozisyonların günlüğüne ve çizimine bakarak bir şekilde bu bilgiyi alır.
 
fxsaber :
Sorun bu. Ancak MT5, kapalı pozisyonların günlüğüne ve çizimine bakarak bir şekilde bu bilgiyi alır.

Ve bu artık işe yaramıyor mu?

ve kapanış fiyatının TP'ye eşit veya daha iyi ve SL'ye eşit veya daha kötü olup olmadığını kontrol ettim.


 
Stanislav Korotky :

Ve bu artık işe yaramıyor mu?

belki bir kod?

... evet, evet, uyluktan Masha yapabilirsin, üzgünüm ... bana kodu göster, lütfen.

 
Stanislav Korotky :

Ve bu artık işe yaramıyor mu?

Evet, belirlenemez. SL ve TP, yalnızca MT sunucusunun özüdür.
Neden: