The Trading Holy Grail of Time Traveler-“Back to the Future"

Questions about MultiCharts and user contributed studies.
Amour
Posts: 13
Joined: 06 May 2015
Has thanked: 9 times

The Trading Holy Grail of Time Traveler-“Back to the Future"

Postby Amour » 06 May 2015

“Back to the Future” Problem in Backtesting of MultiCharts

I am seeking an effective solution to make MultiChats backtesting representable and reliable to all my trading in reality.

The problem of “Back to the Future” is often existent during backtesting with DataN operations. Data at the time of DataN could be a future, or past, values for Data1. i.e.: time data between Data1 and DataN are not concurrent.

It not only can cause incorrect results to all functions, indicators and signals but also put real trading at considerable risk.

Here is an example to review the problem. See a strategy performance report after about one year backtesting first:

Image
Fig 1: Equity Curve Close To Close

Image
Fig 2: Strategy Performance Summary

The strategy performance was incredible. You may have a try just simply refer the context with provided testing codes. The following statements are the settings of the backtesting:

Symbol: CL #F=1 (eSignal Crude Oil Futures)
Data Range: From 1/1/2014 to 5/5/2015
Resolution of Instrument Data 1: 5 Minutes
Resolution of Instrument Data 2: 5 Minutes

Image
Fig 3: Format Objects

Image
Fig 4: Instruments

Image
Fig 5: Backtesting Settings of Strategy Properties

The strategy codes are brief and described below. The signal is just used to zoom in the problem for a closer examination and nonsense for real trading. You could modify it and print data out for checking details.

Code: Select all

[IntrabarOrderGeneration = true]

var:StopLoss(50),StopGain(50);
var: price1(0), price2(0);

price1 = Close of data1;
price2 = Close of data2;

if marketposition = 0 AND (price2 - price1 ) >= StopLoss/bigpointvalue
then begin
buy("LE") next bar at market;
end;

if marketposition = 0 AND (price2 - price1 ) <= StopLoss/bigpointvalue * -1
then begin
sellshort("SE") next bar at market;
end;

setstopcontract;
setstoploss(StopLoss);

setstopcontract;
setpercenttrailing(StopGain,1);
Code 1: “Back to the Future” Strategy Codes

I could not find a way appropriate for solving the “Back to the Future” Problem so far.
Is it possible to have a good solution to deal with it and make backtesting more accurate?
Attachments
Fig5_BacktestingSettings_of_StrategyProperties.jpg
Fig 5: Backtesting Settings of Strategy Properties
(90.34 KiB) Downloaded 2798 times
Fig4_Instruments.jpg
Fig 4: Instruments
(258.43 KiB) Downloaded 2796 times
Fig3_FormatObject.jpg
Fig 3: Format Objects
(45.81 KiB) Downloaded 2797 times
Fig2_Strategy_Performance_Summary.jpg
Fig 2: Strategy Performance Summary
(255.59 KiB) Downloaded 2796 times
Fig1_Equity_Curve_Close_To_Close.jpg
Fig 1: Equity Curve Close To Close
(139.47 KiB) Downloaded 2799 times

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: The Trading Holy Grail of Time Traveler-“Back to the Fut

Postby TJ » 06 May 2015

see post #5
Data2
viewtopic.php?f=16&t=6929

tony
Posts: 420
Joined: 14 Jun 2013
Has thanked: 30 times
Been thanked: 81 times
Contact:

Re: The Trading Holy Grail of Time Traveler-“Back to the Fut

Postby tony » 06 May 2015

That's one long post and truthfully I didn't study everything but I did notice you have "real-time history matching checked" which I believe you should not have.

Amour
Posts: 13
Joined: 06 May 2015
Has thanked: 9 times

Re: The Trading Holy Grail of Time Traveler-“Back to the Fut

Postby Amour » 06 May 2015

Hi TJ:
Thanks for your suggestion. I'll try it again.
YL

Amour
Posts: 13
Joined: 06 May 2015
Has thanked: 9 times

Re: The Trading Holy Grail of Time Traveler-“Back to the Fut

Postby Amour » 06 May 2015

Hi Tony:
Thanks for the notice and I had tested the setting again.
However, the problem is still existent after performing backtesting without checking "real-time history matching".
YL.

Amour
Posts: 13
Joined: 06 May 2015
Has thanked: 9 times

Re: The Trading Holy Grail of Time Traveler-“Back to the Fut

Postby Amour » 06 May 2015

see post #5
Data2
viewtopic.php?f=16&t=6929
Hi TJ:

I changed data resolutions and let Data1 faster than Data2 (5 min as data1, 10 min as data2).
Nevertheless, It's still earn a lot from the time machine after backtesting...

If backtesting could not make sense to support real trade due to the problem, avoiding using DataN may be a temporary way to do so.

Thanks for your kind sharing,

YL
Attachments
Instruments_Try2.jpg
(269.06 KiB) Downloaded 2260 times
Strategy_Performance_Summary_Try2.jpg
(261.46 KiB) Downloaded 2254 times
Equity_Curve_Close_To_Close_Try2.jpg
(83.62 KiB) Downloaded 2256 times
FormatObject_Try2.jpg
(47.85 KiB) Downloaded 2243 times

tony
Posts: 420
Joined: 14 Jun 2013
Has thanked: 30 times
Been thanked: 81 times
Contact:

Re: The Trading Holy Grail of Time Traveler-“Back to the Fut

Postby tony » 07 May 2015

I don't fully understand the problem you are having but wanted throw out one other possible explanation. If you use multiple data series in backtesting, then tick resolution is only valid on data1. Calculations on data2, etc are done only on OHLC, not at every tick within the bar on that data series. I had found this to be the case on prior strategies that used multiple data series. The result is back tests that do not accurately fill.

evdl
Posts: 401
Joined: 19 Jan 2011
Location: Netherlands
Has thanked: 85 times
Been thanked: 124 times

Re: The Trading Holy Grail of Time Traveler-“Back to the Fut

Postby evdl » 07 May 2015

Hello Amour,

You have to reference all dataN code with dataN[1] and the appropriate barstatus (used functions too!). Otherwise you will get the barclose of the dataN before the close of the bar took place. And that is looking into the future.

MC is not taking the last known closed bar of dataN, but is looking at the close of the bar that is still in progress of dataN. When backtesting, this close is already in the database. In real life it will give the current price of dataN, depending on the realtime history matching (RTHM) setting. And there you have a major advantage in backtesting, which is not present in real life.

From what I understand (it is confusing to me), is that in real life you can use the RTHM feature and set it to off, to get the realtime intrabar price of dataN. When switched on, it will use the barclose of dataN. But this will delay your code, because it has to wait for the bar to close on dataN.

But in backtesting this can not be used, so you have to adapt all your signals and functions you use to be able to test and use this same code for trading.

More post on this, are on the forum.

Amour
Posts: 13
Joined: 06 May 2015
Has thanked: 9 times

Re: The Trading Holy Grail of Time Traveler-“Back to the Fut

Postby Amour » 07 May 2015

Hi Tony:

Yes, you pointed it out. Thanks for the good explanation which makes the problem much clear.
The reason is my strategies need multiple data series with different time resolutions to trade. Performing intra-bar back test in detail with ticks is highly demanded to evaluate performance of the strategies before trade in real life. Unfortunately, MC. seems not support.

Functions, indicators, and signals could have incorrect results via backtesting if they referred to the problem. It may impact some traders who believe the results are work and use multiple data series (DataN) to trade. Therefore, I would like to talk about the situation and expect it can be solved here.

Many thanks for your insight and kind reply,

YL
Last edited by Amour on 11 May 2015, edited 1 time in total.

Amour
Posts: 13
Joined: 06 May 2015
Has thanked: 9 times

Re: The Trading Holy Grail of Time Traveler-“Back to the Fut

Postby Amour » 08 May 2015

Hi Evdl:

Thanks for specifying the problem and providing suggestions.
As your mention, tick data from DataN are work correctly in real time but not from backtesting.

Some of my strategies require multiple indicators with different time resolutions to collaborate together, and they demand concurrent real time data.

For example, a signal includes an MA, moving average, of Data1(20 min resolution) and an MACD of Data2 (5 min resolution). Both of the two indicators are need to use the last close for calculating themselves, for instance, MA[0] and MACD[0].
However, only MA[0] can have current real time tick data during back test. The time of MACD[0] and MACD[1] are not concurrent with MA[0]. MACD[0] is often looking into the future.

According to the reason above, it means that all studies implemented by DataN and referred to multiple time resolutions are in question mark. If people use similar methods to code may have the same problem as I have. Those strategies cannot be used in real life trading without having proven performance from reliable back test.

I will be appreciated if MC can improve the problem and continually providing strong supports to a better trading environment.

Many thanks for your kind reply and suggestions

Amour

tony
Posts: 420
Joined: 14 Jun 2013
Has thanked: 30 times
Been thanked: 81 times
Contact:

Re: The Trading Holy Grail of Time Traveler-“Back to the Fut

Postby tony » 08 May 2015

Hi Tony:

Yes, you point it out. Thanks for the good explanation which makes the problem much clear.
The reason is my strategies need multiple data series with different time resolutions to trade. Performing intra-bar back test in detail with ticks is highly demanded to evaluate performance of the strategies before trade in real life. Unfortunately, MC. seems not support.

Functions, indicators, and signals could have incorrect results via backtesting if they referred to the problem. It may impact some traders who believe the results are work and use multiple data series (DataN) to trade. Therefore, I would like to talk about the situation and expect it can be solved here.

Many thanks for your insight and kind reply,

YL
I find a lot of value in trading with multiple data series using different time frames, but due to limitations with backtesting it made evaluating strategies impossible so I unfortunately have moved away from it. Now I only use one data series in my strategies. In replay and live mode multiple data series works fine, but it's hard to evaluate a strategy absent backtesting. One possible way around it is if you use a 1 minute candle on data(n) and if the instrument is slower moving like ZB versus ES. But that may be too short a candle duration for your goals. For me this was not an option.

Amour
Posts: 13
Joined: 06 May 2015
Has thanked: 9 times

Re: The Trading Holy Grail of Time Traveler-“Back to the Fut

Postby Amour » 11 May 2015

Hi Tony:

The situation you described is crystal clear.
Thanks for your suggestion, but it may not be a choice to my strategies implemented by some technical analysis theories with multiple time frames. I am still eager for solutions to solve the problem and keep trying to find other alternatives.

Many thanks for your kind reply,

YL

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: The Trading Holy Grail of Time Traveler-“Back to the Fut

Postby Henry MultiСharts » 12 May 2015

Hello Amour,

At the moment the Bar Magnifier feature works only for the first data series. If you want to have such functionality added in the future - please vote for the corresponding feature request: MC-1361

User avatar
ABC
Posts: 718
Joined: 16 Dec 2006
Location: www.abctradinggroup.com
Has thanked: 125 times
Been thanked: 408 times
Contact:

Re: The Trading Holy Grail of Time Traveler-“Back to the Fut

Postby ABC » 12 May 2015

Amour,

depending on your chart setup you might be able to build the higher timeframe bars within your code - like virtual bars. This way you'd only need one datastream and would have access to the bar magnifier. This obviously works best for time based bars, for non time based bars it will be a lot harder.

Regards,
ABC
Hi Tony:

The situation you described is crystal clear.
Thanks for your suggestion, but it may not be a choice to my strategies implemented by some technical analysis theories with multiple time frames. I am still eager for solutions to solve the problem and keep trying to find other alternatives.

Many thanks for your kind reply,

YL

Amour
Posts: 13
Joined: 06 May 2015
Has thanked: 9 times

Re: The Trading Holy Grail of Time Traveler-“Back to the Fut

Postby Amour » 13 May 2015

Hi Henry,
Thanks for the reply. It seemingly need another account to vote.
Regards,
Amour

Amour
Posts: 13
Joined: 06 May 2015
Has thanked: 9 times

Re: The Trading Holy Grail of Time Traveler-“Back to the Fut

Postby Amour » 13 May 2015

Hi ABC,
Thanks for providing the new hope. I am trying to find the way out and apply in my cases.
Many thanks for your help and kind reply.
Regards,
Amour

Fredi
Posts: 45
Joined: 01 Nov 2013
Been thanked: 2 times

Re: The Trading Holy Grail of Time Traveler-“Back to the Fut

Postby Fredi » 13 May 2015

Because I'm not a programmer I`m looking for a such a code / function (building a higher time / range frame), also. Even an example in another language would be helpful.

Does anybody know such an example / frame?

Another question: is there any description of the MC prebuild functions (like BarQuality)? May be one of this functions can be the base of our "virtual" bars.

Thank you,
Fredi

Amour
Posts: 13
Joined: 06 May 2015
Has thanked: 9 times

Re: The Trading Holy Grail of Time Traveler-“Back to the Fut

Postby Amour » 13 May 2015

Hi ABC:

I am totally agree with your suggestion and start to work on it. But, after long searching through the Internet, no any suitable example about "Virtual Bars" had been found. Do you know any built-in functions or components provided by MultiCharts can be used to build higher timeframes with one datastream in code? Or, I have to implement them by myself?

Many thanks for your help.

Regards,
Amour
Amour,
depending on your chart setup you might be able to build the higher timeframe bars within your code - like virtual bars. This way you'd only need one datastream and would have access to the bar magnifier. This obviously works best for time based bars, for non time based bars it will be a lot harder.

Regards,
ABC
Last edited by Amour on 14 May 2015, edited 2 times in total.

Amour
Posts: 13
Joined: 06 May 2015
Has thanked: 9 times

Re: The Trading Holy Grail of Time Traveler-“Back to the Fut

Postby Amour » 13 May 2015

Hi Fredi:

You may have the same questions as I am having.
The way is feasible and hopeful.

Regards,
Amour
Last edited by Amour on 14 May 2015, edited 1 time in total.

User avatar
ABC
Posts: 718
Joined: 16 Dec 2006
Location: www.abctradinggroup.com
Has thanked: 125 times
Been thanked: 408 times
Contact:

Re: The Trading Holy Grail of Time Traveler-“Back to the Fut

Postby ABC » 14 May 2015

Amour,

there are probably some commercial tools available, but I wouldn't rely on them as you'd likely need more flexibility and control.
One thing useful for you is the Mod reserved word that you can use in combining bars to the higher time frame. Other than that I don't think there are any build in functions really helpful.
Also don't underestimate this project, it will be quite time consuming and work intensive as for example you have to adapt every indicator you want to use to work with your higher timeframes.

Regards,
ABC

Hi ABC:

I am totally agree with your suggestion and start to work on it. But, after long searching through the Internet, no any suitable example about "Virtual Bars" had been found. Do you know any built-in functions or components provided by MultiCharts can be used to build higher timeframes with one datastream in code? Or, I have to implement them by myself?

Many thanks for your help.

Regards,
Amour

Amour
Posts: 13
Joined: 06 May 2015
Has thanked: 9 times

Re: The Trading Holy Grail of Time Traveler-“Back to the Fut

Postby Amour » 15 May 2015

Hi ABC,

Thank you for the useful information. I met more challenges when the problem is going deeper.
You are absolutely right. It's a hard work!

Regards,
Amour
Amour,
there are probably some commercial tools available, but I wouldn't rely on them as you'd likely need more flexibility and control.
One thing useful for you is the Mod reserved word that you can use in combining bars to the higher time frame. Other than that I don't think there are any build in functions really helpful.
Also don't underestimate this project, it will be quite time consuming and work intensive as for example you have to adapt every indicator you want to use to work with your higher timeframes.

Regards,
ABC

javamarket
Posts: 55
Joined: 10 Jul 2014
Has thanked: 10 times
Been thanked: 18 times

Re: The Trading Holy Grail of Time Traveler-“Back to the Fut

Postby javamarket » 15 May 2015

Granted this routine is for Matlab, but it is coded in C++ and may be of some utility for this discussion.

The referenced is a function which creates larger time series data from a smaller time series creating virtual OHLC data:

https://github.com/mtompkins/openAlgo/b ... tualBars.m

Amour
Posts: 13
Joined: 06 May 2015
Has thanked: 9 times

Re: The Trading Holy Grail of Time Traveler-“Back to the Fut

Postby Amour » 19 May 2015

Hi Javamarket,

The library in C++ you provided is pretty cool. It may be powerful to some cases in advance.
Nevertheless, I am trying to keep the thing as simple as possible and prefer to use native ways to build tools. The method I am use is making some functions in Power Language to do time translate. Those functions should able to bring data into real life from the future and past during back test with multiple time frames. I call the project "Wormhole"...

Many thanks for your introduce and kind reply.

Regards,
Amour


Return to “MultiCharts”