Yes, my concern is about transaction in backtest. But in order to make it as most real as possible, transaction should be the same as in live trading.
TRADE_TRANSACTION_POSITION is not related to a deal, as you also mentioned before. I guess it indicates for instance, when you moved some money on your account.
The issue seems there is some transactions not available when backtesting. A bug or a limitation of backtesting. When running on a forward test, I have a TRADE_TRANSACTION_POSITION when SL/TP is triggered.
The issue seems there is some transactions not available when backtesting. A bug or a limitation of backtesting. When running on a forward test, I have a TRADE_TRANSACTION_POSITION when SL/TP is triggered.
still have the problem to get the executed price of a stop or loss attached to a postion - in backtest. Don't know so far, how it's behave under live conditions.
This is from backtest log:
KP 023:18:29 Core 12010.05.1111:00:00 instant buy 0.01 EURUSD at 1.26882 (1.26871 / 1.26882 / 1.26871)
EM 023:18:29 Core 12010.05.1111:00:00 deal #2buy 0.01 EURUSD at 1.26882 done (based on order #2)
MG 023:18:29 Core 12010.05.1111:00:00 deal performed [#2buy 0.01 EURUSD at 1.26882]
RI 023:18:29 Core 12010.05.1111:00:00 order performed buy 0.01 at 1.26882 [#2buy 0.01 EURUSD at 1.26882]
JS 023:18:29 Core 12010.05.1111:00:00 CTrade::OrderSend: instant buy 0.01 EURUSD at 1.26882 [done at 1.26882]
LP 023:18:29 Core 12010.05.1111:00:00 position modified [buy 0.01 EURUSD 1.26882 sl: 1.26809 tp: 1.27028]
LM 023:18:29 Core 12010.05.1111:00:00 CTrade::OrderSend: modify EURUSD (sl: 1.26809, tp: 1.27028) [done]
LR 023:18:29 Core 12010.05.1111:00:00 trans=symbol=EURUSD price=1.2688200 volume=0.01 sl=0.0000000 tp=0.0000000 order=2 deal=2 entry-type=IN trans-type=DEAL_ADD order_type=BUY deal_type=DEAL_TYPE_BUY type_time=0 expiration=1970.01.0100:00 price_trigger=0.0000000 profit=0.00 order-open=0.000000 order-current=0.000000 deal-price=0.000000
GG 023:18:29 Core 12010.05.1111:18:40 take profit triggered buy 0.01 EURUSD 1.26882 sl: 1.26809 tp: 1.27028 [#3sell 0.01 EURUSD at 1.27028]
MD 023:18:29 Core 12010.05.1111:18:40 deal #3sell 0.01 EURUSD at 1.27028 done (based on order #3)
PI 023:18:29 Core 12010.05.1111:18:40 deal performed [#3sell 0.01 EURUSD at 1.27028]
NO 023:18:29 Core 12010.05.1111:18:40 order performed sell 0.01 at 1.27028 [#3sell 0.01 EURUSD at 1.27028]
RS 023:18:29 Core 12010.05.1111:18:40 trans=symbol=EURUSD price=1.2702800 volume=0.01 sl=0.0000000 tp=0.0000000 order=3 deal=3 entry-type=IN trans-type=DEAL_ADD order_type=BUY deal_type=DEAL_TYPE_SELL type_time=0 expiration=1970.01.0100:00 price_trigger=0.0000000 profit=0.00 order-open=0.000000 order-current=0.000000 deal-price=0.000000
JM 023:18:29 Core 12010.05.2009:00:00 ut =3.00 candle=o=1.24130 c=1.24170 h=1.24360 l=1.24100 b=39 uw=190 lw=29
FK 023:18:29 Core 12010.05.2009:00:00 instant sell 0.01 EURUSD at 1.24180 (1.24180 / 1.24195 / 1.24180)
MG 023:18:29 Core 12010.05.2009:00:00 deal #4sell 0.01 EURUSD at 1.24180 done (based on order #4)
IG 023:18:29 Core 12010.05.2009:00:00 deal performed [#4sell 0.01 EURUSD at 1.24180]
CN 023:18:29 Core 12010.05.2009:00:00 order performed sell 0.01 at 1.24180 [#4sell 0.01 EURUSD at 1.24180]
EO 023:18:29 Core 12010.05.2009:00:00 CTrade::OrderSend: instant sell 0.01 EURUSD at 1.24180 [done at 1.24180]
EQ 023:18:29 Core 12010.05.2009:00:00 position modified [sell 0.01 EURUSD 1.24180 sl: 1.24253 tp: 1.24034]
DO 023:18:29 Core 12010.05.2009:00:00 CTrade::OrderSend: modify EURUSD (sl: 1.24253, tp: 1.24034) [done]
HI 023:18:29 Core 12010.05.2009:00:00 trans=symbol=EURUSD price=1.2418000 volume=0.01 sl=0.0000000 tp=0.0000000 order=4 deal=4 entry-type=IN trans-type=DEAL_ADD order_type=BUY deal_type=DEAL_TYPE_SELL type_time=0 expiration=1970.01.0100:00 price_trigger=0.0000000 profit=0.00 order-open=0.000000 order-current=0.000000 deal-price=0.000000
JH 023:18:29 Core 12010.05.2009:00:40 stop loss triggered sell 0.01 EURUSD 1.24180 sl: 1.24253 tp: 1.24034 [#5buy 0.01 EURUSD at 1.24253]
HI 023:18:29 Core 12010.05.2009:00:40 deal #5buy 0.01 EURUSD at 1.24253 done (based on order #5)
MK 023:18:29 Core 12010.05.2009:00:40 deal performed [#5buy 0.01 EURUSD at 1.24253]
NL 023:18:29 Core 12010.05.2009:00:40 order performed buy 0.01 at 1.24253 [#5buy 0.01 EURUSD at 1.24253]
KQ 023:18:29 Core 12010.05.2009:00:40 trans=symbol=EURUSD price=1.2425300 volume=0.01 sl=0.0000000 tp=0.0000000 order=5 deal=5 entry-type=IN trans-type=DEAL_ADD order_type=BUY deal_type=DEAL_TYPE_BUY type_time=0 expiration=1970.01.0100:00 price_trigger=0.0000000 profit=0.00 order-open=0.000000 order-current=0.000000 deal-price=0.000000
PJ 023:18:30 Core 12010.08.2609:08:00 ut =3.83 candle=o=1.27238 c=1.27274 h=1.27448 l=1.27238 b=35 uw=174 lw=0
IH 023:18:30 Core 12010.08.2609:08:00 instant sell 0.01 EURUSD at 1.27276 (1.27276 / 1.27287 / 1.27276)
GH 023:18:30 Core 12010.08.2609:08:00 deal #6sell 0.01 EURUSD at 1.27276 done (based on order #6)
MR 023:18:30 Core 12010.08.2609:08:00 deal performed [#6sell 0.01 EURUSD at 1.27276]
HR 023:18:30 Core 12010.08.2609:08:00 order performed sell 0.01 at 1.27276 [#6sell 0.01 EURUSD at 1.27276]
PR 023:18:30 Core 12010.08.2609:08:00 CTrade::OrderSend: instant sell 0.01 EURUSD at 1.27276 [done at 1.27276]
FE 023:18:30 Core 12010.08.2609:08:00 position modified [sell 0.01 EURUSD 1.27276 sl: 1.27349 tp: 1.27130]
LK 023:18:30 Core 12010.08.2609:08:00 CTrade::OrderSend: modify EURUSD (sl: 1.27349, tp: 1.27130) [done]
NE 023:18:30 Core 12010.08.2609:08:00 trans=symbol=EURUSD price=1.2727600 volume=0.01 sl=0.0000000 tp=0.0000000 order=6 deal=6 entry-type=IN trans-type=DEAL_ADD order_type=BUY deal_type=DEAL_TYPE_SELL type_time=0 expiration=1970.01.0100:00 price_trigger=0.0000000 profit=0.00 order-open=0.000000 order-current=0.000000 deal-price=0.000000
HM 023:18:30 Core 12010.08.2609:08:40 stop loss triggered sell 0.01 EURUSD 1.27276 sl: 1.27349 tp: 1.27130 [#7buy 0.01 EURUSD at 1.27349]
As you can see in last line, the executed price is given in the log -> [#7 buy 0.01 EURUSD at 1.27349]
But no structure, transaction, deal or order history provides this price.
This line dumps the transaction related to triggered stop:
angevoyageur: Thanks, I will go to study that ASAP.
This is really nice. Do not hurry.
I checked each transaction, request and result passed to OnTradeTransaction.
The triggered stop loss price mentioned in the backtest log (create by MetaTrader) can't be found except as sl price, but not as price or deal price or execution price.
I checked each transaction, request and result passed to OnTradeTransaction.
The triggered stop loss price mentioned in the backtest log (create by MetaTrader) can't be found except as sl price, but not as price or deal price or execution price.
So, we are talking about backtesting only. I have tested with my own code and I obtain 3 transactions when a stop is triggered :
With the DEAL_ADD I get the price of the deal, so the SL in my case. All seems correct to me. I suggest you send me the code you use, the backtest log (as a file) and a screenshot of Strategy tester Settings. Then I can reproduce the exact same test as yours and analyse the result. You can send me a PM if you prefer.
I checked. When a SL/TP is triggered you have these transaction :
When going short - from a virgin position, i get 3 transactions:
A entry )
Once stop loss triggered , i get
B exit )
No TRADE_TRANSACTION_POSITION. I think you can't use it here.
Summary:
A short is opened, the first transaction is
entry-type=IN trans-type=DEAL_ADD order_type=BUY sl=1.3119000 tp=1.3088000
Short closed, by stop or target, first reflected transaction
entry-type=IN trans-type=DEAL_ADD order_type=BUY sl=0.0 tp=0.0
This is confusing. It should be:
open short:
entry-type=IN trans-type=DEAL_ADD order_type=SELL sl=1.3119000 tp=1.3088000
close short:
entry-type=OUT trans-type=DEAL_ADD order_type=BUY sl=0.0 tp=0.0
I checked. When a SL/TP is triggered you have these transaction :
When going short - from a virgin position, i get 3 transactions:
A entry )
Once stop loss triggered , i get
B exit )
No TRADE_TRANSACTION_POSITION. I think you can't use it here.
...You are missing some transactions, don't know why. Because backtesting ?
Small digression, intead of :
you can use :
EnumToString(t.order_type)
Small digression, intead of :
you can use :
Thank you for EnumToString. Much smarter to use.
Yes, my concern is about transaction in backtest. But in order to make it as most real as possible, transaction should be the same as in live trading.
TRADE_TRANSACTION_POSITION is not related to a deal, as you also mentioned before. I guess it indicates for instance, when you moved some money on your account.
...
The issue seems there is some transactions not available when backtesting. A bug or a limitation of backtesting. When running on a forward test, I have a TRADE_TRANSACTION_POSITION when SL/TP is triggered.
2013.05.08 19:20:29 tc_ea_trans (EURUSD,M1) TRADE_TRANSACTION_ORDER_ADD
2013.05.08 19:20:29 tc_ea_trans (EURUSD,M1) trans=symbol=EURUSD price=1.3170100 volume=0.01 sl=0.0000000 tp=0.0000000 order=19683612 deal=0 entry-type=IN trans-type=ORDER_ADD order_type=BUY deal_type=DEAL_TYPE_BUY type_time=0 expiration=1970.01.01 00:00 price_trigger=0.0000000 profit=0.00
2013.05.08 19:20:29 tc_ea_trans (EURUSD,M1) TRADE_TRANSACTION_ORDER_DELETE
2013.05.08 19:20:29 tc_ea_trans (EURUSD,M1) trans=symbol=EURUSD price=1.3170100 volume=0.01 sl=0.0000000 tp=0.0000000 order=19683612 deal=0 entry-type=IN trans-type=ORDER_DELETE order_type=BUY deal_type=DEAL_TYPE_BUY type_time=0 expiration=1970.01.01 00:00 price_trigger=0.0000000 profit=0.00
2013.05.08 19:20:29 tc_ea_trans (EURUSD,M1) TRADE_TRANSACTION_HISTORY_ADD
2013.05.08 19:20:29 tc_ea_trans (EURUSD,M1) trans=symbol=EURUSD price=1.3170100 volume=0.00 sl=0.0000000 tp=0.0000000 order=19683612 deal=0 entry-type=IN trans-type=HISTORY_ADD order_type=BUY deal_type=DEAL_TYPE_BUY type_time=0 expiration=1970.01.01 00:00 price_trigger=0.0000000 profit=0.00
2013.05.08 19:20:29 tc_ea_trans (EURUSD,M1) TRADE_TRANSACTION_POSITION
2013.05.08 19:20:29 tc_ea_trans (EURUSD,M1) trans=symbol=EURUSD price=1.3173500 volume=0.01 sl=1.3174200 tp=1.3170100 order=0 deal=0 entry-type=IN trans-type=POSITION order_type=BUY deal_type=DEAL_TYPE_SELL type_time=0 expiration=1970.01.01 00:00 price_trigger=0.0000000 profit=0.00
2013.05.08 19:20:29 tc_ea_trans (EURUSD,M1) TRADE_TRANSACTION_DEAL_ADD
2013.05.08 19:20:29 tc_ea_trans (EURUSD,M1) trans=symbol=EURUSD price=1.3170100 volume=0.01 sl=0.0000000 tp=0.0000000 order=19683612 deal=16655372 entry-type=OUT trans-type=DEAL_ADD order_type=BUY deal_type=DEAL_TYPE_BUY type_time=0 expiration=1970.01.01 00:00 price_trigger=0.0000000 profit=0.34
The issue seems there is some transactions not available when backtesting. A bug or a limitation of backtesting. When running on a forward test, I have a TRADE_TRANSACTION_POSITION when SL/TP is triggered.
2013.05.08 19:20:29 tc_ea_trans (EURUSD,M1) TRADE_TRANSACTION_ORDER_ADD
2013.05.08 19:20:29 tc_ea_trans (EURUSD,M1) trans=symbol=EURUSD price=1.3170100 volume=0.01 sl=0.0000000 tp=0.0000000 order=19683612 deal=0 entry-type=IN trans-type=ORDER_ADD order_type=BUY deal_type=DEAL_TYPE_BUY type_time=0 expiration=1970.01.01 00:00 price_trigger=0.0000000 profit=0.00
2013.05.08 19:20:29 tc_ea_trans (EURUSD,M1) TRADE_TRANSACTION_ORDER_DELETE
2013.05.08 19:20:29 tc_ea_trans (EURUSD,M1) trans=symbol=EURUSD price=1.3170100 volume=0.01 sl=0.0000000 tp=0.0000000 order=19683612 deal=0 entry-type=IN trans-type=ORDER_DELETE order_type=BUY deal_type=DEAL_TYPE_BUY type_time=0 expiration=1970.01.01 00:00 price_trigger=0.0000000 profit=0.00
2013.05.08 19:20:29 tc_ea_trans (EURUSD,M1) TRADE_TRANSACTION_HISTORY_ADD
2013.05.08 19:20:29 tc_ea_trans (EURUSD,M1) trans=symbol=EURUSD price=1.3170100 volume=0.00 sl=0.0000000 tp=0.0000000 order=19683612 deal=0 entry-type=IN trans-type=HISTORY_ADD order_type=BUY deal_type=DEAL_TYPE_BUY type_time=0 expiration=1970.01.01 00:00 price_trigger=0.0000000 profit=0.00
2013.05.08 19:20:29 tc_ea_trans (EURUSD,M1) TRADE_TRANSACTION_POSITION
2013.05.08 19:20:29 tc_ea_trans (EURUSD,M1) trans=symbol=EURUSD price=1.3173500 volume=0.01 sl=1.3174200 tp=1.3170100 order=0 deal=0 entry-type=IN trans-type=POSITION order_type=BUY deal_type=DEAL_TYPE_SELL type_time=0 expiration=1970.01.01 00:00 price_trigger=0.0000000 profit=0.00
2013.05.08 19:20:29 tc_ea_trans (EURUSD,M1) TRADE_TRANSACTION_DEAL_ADD
2013.05.08 19:20:29 tc_ea_trans (EURUSD,M1) trans=symbol=EURUSD price=1.3170100 volume=0.01 sl=0.0000000 tp=0.0000000 order=19683612 deal=16655372 entry-type=OUT trans-type=DEAL_ADD order_type=BUY deal_type=DEAL_TYPE_BUY type_time=0 expiration=1970.01.01 00:00 price_trigger=0.0000000 profit=0.34
Hello angevoyageur,
still have the problem to get the executed price of a stop or loss attached to a postion - in backtest. Don't know so far, how it's behave under live conditions.
This is from backtest log:
As you can see in last line, the executed price is given in the log -> [#7 buy 0.01 EURUSD at 1.27349]
But no structure, transaction, deal or order history provides this price.
This line dumps the transaction related to triggered stop:
This is the dump function code:
So i tried to get execution price from order and deal history: no result
Hello angevoyageur,
...Thanks, I will go to study that ASAP.
This is really nice. Do not hurry.
I checked each transaction, request and result passed to OnTradeTransaction.
The triggered stop loss price mentioned in the backtest log (create by MetaTrader) can't be found except as sl price, but not as price or deal price or execution price.
This is really nice. Do not hurry.
I checked each transaction, request and result passed to OnTradeTransaction.
The triggered stop loss price mentioned in the backtest log (create by MetaTrader) can't be found except as sl price, but not as price or deal price or execution price.
So, we are talking about backtesting only. I have tested with my own code and I obtain 3 transactions when a stop is triggered :
2013.05.15 10:22:27 Core 1 2013.05.10 16:20:37 Symbol : EURUSD event : TRADE_TRANSACTION_DEAL_ADD(6)
2013.05.15 10:22:27 Core 1 2013.05.10 16:20:37 Symbol : EURUSD event : TRADE_TRANSACTION_ORDER_DELETE(2)
2013.05.15 10:22:27 Core 1 2013.05.10 16:20:37 Symbol : EURUSD event : TRADE_TRANSACTION_HISTORY_ADD(3)