Code: Select all
If ... then begin
SellShort ("Partial Up SE") next bar at close limit ;
end ;
if ... then begin
Buy ("Partial Down LE") next bar at close limit ;
end ;
SetStopContract ;
SetProfitTarget( 225 ) ;
SetStopLoss( 350 ) ;
When I'm backtesting this, I'm seeing two results in the list of trades that don't make sense to me. I've attached an Excel file with the performance report for reference.
First, the strategy hits the profit target numerous times during backtesting. However, each time it exits with a "Profit Target" exit, it shows a profit of $233.50 -- not the $225 that is coded in the strategy. For example, on June 24, 2003, it shows a long entry at 1067.25 followed by a "Profit Target" exit at 1072, for a gain of 4.75 points or $233.50. I.e., it is essentially showing positive slippage of $12.50 (one tick for the e-mini).
Second, the strategy only deducts commissions from the trades when hitting the stop loss, not when hitting the profit target. For example, in the above June 24, 2003 transaction, it shows a profit of exactly $233.50 (4.75 points), without deducting $4.00 for the round-trip commission. However, when it hit the stop loss in a transaction on June 27, 2003, it shows a loss of $354 -- i.e., the $350 stop-loss amount plus the $4.00 round-trip commission.
Note, however, that Strategy Performance Summary page shows the correct total amount of commissions. It reports "Commissions Paid: $3000," based on 750 round-trip trades (i.e., $4.00 per round-trip). Does this mean that the Strategy Performance Report might be double-counting some commissions -- including them as a loss in the stop-loss calculations, plus including them a second time in the Strategy Performance Summary?
I ran this strategy during automated trading on Interactive Brokers this morning, and it hit the profit target. I ended up with the expected results -- a gain of $225 per contract, less a round-trip commission of about $4.00 per contract. However, when I disabled the automated trading and instead looked at the backtesting results, the strategy likewise showed a gain of $233.50 for today (i.e., $12.50 higher, with no commission). Consequently, the backtesting results are not matching reality.
Can anyone explain why these two issues are happening? Are these bugs, or are they expected behavior? If it's expected behavior, is there a way to improve the code so that the backtesting results are more accurate? Thanks in advance.