Historical back testing VS Real trading

Studies that have been contributed to the community by other users. If you’ve got something useful to share, that’s great!
faraz
Posts: 144
Joined: 25 Feb 2011
Has thanked: 26 times
Been thanked: 57 times

Historical back testing VS Real trading

Postby faraz » 31 Dec 2014

Historical back testing VS Real trading

Designing treatable strategy is a big challenge. Once you start trading your strategy you start to face some unknown issues which needs further coding to make the code work as close to Historical Back Testing. Here are some issues which you should consider further programming before going to Live Trading;

Note: The strategy issues over here are discussed about Emini S&P (ES) of CME exchange with Rithmic Data Feed.

1. Limit order issues
1.1. Out of Band order Rejection issue: Try to place Buy limit order at current price +10 points. Mean if the current rate is 1200 then try to place Buy Limit Order at 1210.
1.1.1. For Real Trading issue: Exchange will reject this order.
1.1.2. For Back Testing: Multichars will convert this order as Market order and gave you fill.
1.1.3. Solution: In such case tell you strategy to place limit at the price where the Price is. If you strategy is not using IOG then “Open Tomorrow” can provide you the solution. “Buy next bar at open tomorrow limit”

1.2. UnFilled Limit order cancelation after Close Session: If you are using Custom session trading and not Globex session then if your limit order is placed during custom session and the session ended your Limit order will stay active and you can get fill.
1.2.1. For Back Testing: MC does not fill out of session limit orders and consider they are cancelled.
1.2.2. For Real Trading: MC limit orders will stay active and you could get fill.
1.2.3. Solution:
1.2.3.1. Cancel all unfilled orders manually. Note: You need to set Closebartime out in Registry. By default you cannot cancel manually un-filled limit order for 5 minutes. Registry value: HKEY_CURRENT_USER\Software\TS Support\MultiCharts64\Shaper\CloseBarTimeout
1.2.3.2. Or by some Auto Mouse recorder which could run at your specified time
1.2.3.3. Or Code the strategy to cancel orders 10 seconds before session close. If your strategy is IOG, you can do this.

1.3. Slippage issue at Limit orders: Suppose your strategy place buy limit order at 1210 but the price was at 1208 so your order will be converted to market order and slippage will be added.
1.3.1. For Back Testing: MC will still show you fill at 1208 and will not add any slippage.
1.3.2. For Real Trading: You did get 1 tick slippage as limit order was converted to market order.
1.3.3. Solution:
1.3.3.1. Add coding to your strategy to place “Buy next bar at open tomorrow limit” on these situations.
1.3.3.2. In MC for back testing there is a way to add Slippage for limit orders but I do not recommend that. MC support team can provide you details.

1.4. Open Tomorrow Limit orders: If your strategy is using More than one “Buy next bar at open tomorrow limit” then you must understand that on such days all these orders will get FILL and your number of traded contract will increase.
1.4.1. For Back Testing: MC keep the desired number of contracts and will not give your addition fill.
1.4.2. For Real Trading: All orders with TRUE conditions will be sent as MC regard less if you get fill in all of them AT ONCE.
1.4.3. Solution:
1.4.3.1. Code your strategy to cancel all other “Buy next bar at open tomorrow limit” orders if you are sending it at top. You can do like this;

Code: Select all

Value1: 0;
If condition1 and value1=0 then begin Buy next bar at open tomorrow limit; value1=1; end;
If condition2 and value1=0 then begin Buy next bar at open tomorrow limit; value1=1; end;

1.4.3.2. Further more you could add this code at the end of your strategy to monitor your contracts all the time:

Code: Select all

vars: AllowedContracts(1);
If marketposition<>0 and CurrentContracts > AllowedContracts then begin
Sell ("EROR1") (CurrentContracts - AllowedContracts) contract next bar at market;
BuyToCover ("EROR2") (CurrentContracts - AllowedContracts) contract next bar at market;
End;
2. SetProfitTarget Issues;
2.1. Order Rejection issue: If your strategy is using SetProfitTarget and the price is above the allowed Band as discussed in above then your order will be rejected from Exchange.
2.1.1. For Back Testing: MC will gave you fill
2.1.2. For Real Trading: Exchange will reject your order
2.1.3. Solution:
2.1.3.1. Add code in your strategy to update your order price “Buy next bar at open tomorrow limit”
2.1.3.2. Further enable to turn off your AutoTrading if you get more then x Rejected orders. You can find its settings in Strategy Properties > Auto Trading > Stop Auto-Trading after x Rejected orders. If you do not do this then Exchange will block your trading account for sending extra out of band orders and you will not be able to trade further.

2.2. SetProfitTarget placed to close to Limit order; If your strategy is placing SetProfitTarget order + Limit/Stop order to close to it then be aware then there is a chance of double fill.
2.2.1. For Back Testing: MC will show only one first order fill.
2.2.2. For Real Trading: you can get double fill
2.2.3. Solution:
2.2.3.1. Add extra coding to send only one closer to price order at such times.
2.2.3.2. And extra coding is require if you are using “SetProfitTarget” at more then one place in your strategy.

3. Stop Orders Issue;
3.1. Wrong fill without Slippage addition; If your strategy is using Stop orders and you are using PT contracts instead of Electronic data and your PT Data got a lot of Gaps then your back testing is not correct. Suppose Market open at 1200 and you put a stop order for 1201 and then Next tick was at 1205 then MC will gave you 1201 fill but You will not get exact slippage. We are taking about Daily bars. MC create full bar if it have 2 price ticks.
3.1.1. For Back Testing: MC will not calculate the exact slippage for you but will add the slippage which you have entered in its settings.
3.1.2. For Real Trading: you will get big slippages and your Profitable strategy will turn as losing strategy.
3.1.3. Solution: Remove Slippage from MC Strategy Properties and calculate Extra slippage from Strategy and then manually subtract it from Net Profit.

4. This bar on close orders Or SetExitOnClose;
4.1. Exchange close time (Regular or Holidays both) issue: If your strategy is generating “This bar on close” OR “SetExitOnClose” order at the time when Exchange does not accept orders then you will not get fill.
4.1.1. For Back Testing: MC will gave you fill.
4.1.2. For Real Trading: Exchange will not accept Market order after it is closed.
4.1.3. Solution:
4.1.3.1. You can create a custom session to close 1 minute before market close.
4.1.3.2. Code your strategy to send order 10 seconds before market close if your strategy is using IOG.

5. Number of Orders Generating at one time; More order types in strategy would require more programming to keep it Back Testing and Real trading close to each other.

6. Data Isses:
6.1. Bad Tick Issues by data feed or MC Crash or non response force full MC Close: Some time bad tick create issues and strategy does not work as per requirement.
6.1.1. For back testing: When you back test you get fresh clean data load from data feed. And MC will not show any problems.
6.1.2. For Real trading: Bad ticks can come and create problems.
6.1.3. Solution: Time to time Re-Load your data to keep clean data all the time.

7. Upgrading MC or Broker API: Monitor strategy very closely after MC upgradation. Many bugs can arise in latest upgradations either from MC or Broker API side.

8. Tracking orders at MC and Broker statement: There could be difference in Profit/Loss calculation with MC and your broker statement as MC calculate on First IN > First Out order calculation but Broker uses First IN > Last Out calculation. But calculation would provide exact same total once all trades are closed.

9. for further study please refer to the following links;
https://www.multicharts.com/trading-sof ... ve_Trading
https://www.multicharts.com/trading-sof ... acktesting
https://www.multicharts.com/trading-sof ... acktesting
https://www.multicharts.com/trading-sof ... n_Priority

10. Above all that I recommend good monitoring setup at your trading PC to track any further issues. Please review
viewtopic.php?f=1&t=47391&p=109482#p109482

I hope this info will save all traders time and efforts.
Successful Trading!!!

Thanks

faraz
Posts: 144
Joined: 25 Feb 2011
Has thanked: 26 times
Been thanked: 57 times

Re: Historical back testing VS Real trading

Postby faraz » 10 Jul 2018

Non IOG strategies Solution update for above mentioned scenario in " 1.2. UnFilled Limit order cancelation after Close Session" ;

1.2.3.4. Or Add this below code for Strategies which are not using IOG and it will Disable the auto trading which will cancel automatically all the pending Un-Filled orders only 10 seconds before Market Close in below case 15:15:00 is the market close time, but first settings requied, you must first Check both in File>Preferences>Trading;
"Do not show cancel active orders confirmation dialog when disabling auto trading"
and "Cancel active orders sent by the strategy"

Code: Select all

RecalcLastBarAfter(1);
if CurrentTime_s >= 151450 and CurrentTime_s < 151505 then begin
if GetAppInfo(aiStrategyAuto)=1 then Once CommandLine(".at_toggle");
end else begin

// Put rest of your strategy code here

end;

Thanks


Return to “User Contributed Studies and Indicator Library”