Techniques to match realtime with backtest

Questions about MultiCharts and user contributed studies.
Fredi
Posts: 45
Joined: 01 Nov 2013
Been thanked: 2 times

Techniques to match realtime with backtest

Postby Fredi » 09 Mar 2015

Yes, the question is perhaps naive: I want to reach realtime
results as closely as possible with the backtest (the opposite
situation - backtest results more closely to realtime seems not
possible).

The problem: in the lowest time frame (tick data), very often my
strategy isn't getting the fill in realtime, however in backtest,
based on the absence of volume.

Now I think about a solution to change my code from

Code: Select all

if marketposition = 1 then begin
Sell ( "LX Profit" ) next bar at target Limit;
Sell ( "LX SL" ) next bar at stopploss Stop;
end;
to

Code: Select all

if marketposition = 1 then begin
if (ConditionTouched) then
Sell ( "LX Touched" ) next bar at Close Limit
else
Sell ( "LX Profit" ) next bar at target Limit;
Sell ( "LX SL" ) next bar at stopploss Stop;
end;
in order to prevent a stopploss, after a touch of the target.

The question is now, what of the below conditions (or any other
one) I have to use

1. ConditionTouched: Close => target
2. ConditionTouched: High => target
3. ConditionTouched: insideask => target

to reach my goal. I'm quite aware: the strategy will become
another one as the origin. However: the origin is in realtime
another one as in the backtest, also.

Is there any improvement possible, at all? What are your experiences
and what approach/concept could be successful?

Thanks in advance,
Fredi

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

Re: Techniques to match realtime with backtest

Postby Henry MultiСharts » 20 Mar 2015

Hello Fredi,

In general case in order to ensure backtesting calculation is similar to realtime calculation you need to have the same sequence of ticks for strategy calculation (Bar Magnifier). Backetsting and Realtime calculations should also occur at the same time periods (IOG & RTHM).

As for the code - the fewer complicated conditions it has, the better. A condition that is triggered in backtesing can be not met in realtime and vice versa.
When historical calculation is compared to realtime broker trading that is even more complicated as the orders are managed by the broker.

Please study the following articles to get a better understanding of how backtesting and realtime trading are working:
Backtesting vs Live Trading, How Signals are Calculated, Why Identical Charts Are Showing Different Strategy Trading Results,
Why is Data Playback strategy performance different from Backtesting results%3F.

Please keep in mind that backtesting cannot simulate real market movement activity, order queue and latency. It is just a calculation on historical data where you always filled when fill conditions are met. That is it’s nature and that is expected. Backtesting, optimization, and forward testing (real-time simulation) provide an insight into potential performance of your strategy in “ideal world”. This information should be analyzed to get a range of possible scenarios.
It is up to trader to decide if this range is acceptable for live trading or not.

If you want to have real market activity simulation – you can use the sim/paper trading broker connection. But even brokers do not guarantee that it will be the same as the real live market trading.

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

Re: Techniques to match realtime with backtest

Postby Fredi » 03 Apr 2015

Henry, thank you.

Before I adjust my script to real-time (if it makes sense, at all), I think, first I have to verify my understanding, how future market is working.

The situation: I’m trading FDAX and Euro-Bund (CQG tick data; broker is AMP). I‘m using for both instruments the same MC-script / strategy with a Limit-order as entry.

My question: why I will get the trade in FDAX in about 95% of the cases, but only in about 50% in Euro-Bund? And this, even though the volume of the Euro-Bund is about 10 times higher than in FDAX.

My understanding: despite high volume, I‘m get my 1 contract in Euro-Bund too seldom, because I’m „sitting“ at the back of the queue, very often.

Do I understand this with Euro-Bund correctly? And why I will get realtively frequent the entry in FDAX, despite the low volume?

Thanks,
Fredi

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

Re: Techniques to match realtime with backtest

Postby tony » 03 Apr 2015

I have an ES scalping system, targets 4 ticks for a profit so it's truly scalping. I enter live via market and exit via limit (profit target hit) or market (stop hit). To simulate in back testing, I have it set to not fill limit orders until price flows through 2 ticks (says points in MC, should say ticks). And on my stop, I have it one tick tighter than in live trading. The reason being in live trading I am almost always filling one tick worse than in back testing so that way I know my exits are similar. In terms of my profit target I have a two tick trigger set because I know I will likely fill one tick worse (market order) than in backtesting and I won't fill (limit order) unless price flows through me.

So what this does is give me extremely accurate backtesting. To the point where I can run a live session, and then do a theoretical back test and have similar results. What doesn't work is the P&L on the backtest. But what I rely on is the win rate in backtesting. I then manually do a P&L based on win and loss amounts.

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

Re: Techniques to match realtime with backtest

Postby Fredi » 07 Apr 2015

Tony, thank you for your approach. Maybe a very helpful impuls for my next steps.

Does your backtesting script looking similar as this code?

Code: Select all

TV = MinMove/PriceScale; // Tick Value
profit = 4 * TV;
offset = 2 * TV; // Backtest-Offset

if marketposition = 0 then TargetPassed = false;

if marketposition = 1 then begin
if (Close >= EntryPrice + profit + offset) Or TargetPassed then begin
TargetPassed = true;
Sell ("Long Target") next bar at (EntryPrice + profit) Limit;
end;
Sell ("Long Stop") next bar at (EntryPrice - ( (EinR - 1) * TV )) Stop;
end;
Do you have already experience with a backtest method for a limit entry?

The question I ask myself is: is it possible to calculate beside the hit rate an accurate P&L, also?
Assuming the rough probability is known, how often i.e. the limit order is hitting the exact entry or target price.
Perhaps then it is possible to determine the entry / target with a random number in the backtest.

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

Re: Techniques to match realtime with backtest

Postby tony » 07 Apr 2015

HI Fredi -

Backtesting is important, no question, but it has limitations for sure. And it's not a knock on MC, it's a reality. Order flow is pretty much impossible to simulate in backtest mode. Surely it can be improved if using bid ask historical data, I truthfully have not done that.

When most of us design a system, we will also optimize to some extent. That in itself likely pushes the extremes in terms of finding conditionals where price just barely gets in and then becomes a winning trade. Use a bollinger band for example. We may optimize the band such that in historical testing, price just pierces the band and a trade is "filled." But in reality, unless our limit orders are sent well before price trades at that level, we likely will only fill if price trades through us. And that would then say when we optimize too much we are likely not taking into account the reality of order flow.

I trade ES and ZB, both I found I needed to use market orders on entry otherwise I was not getting the trade volume that I was getting in back testing. And trade volume can kill win rates if the set up is there and yet you can't get in. I was willing to risk another tick by entering via market and getting in the trade.

Another thing to be careful of when backtesting. I use IQ for data and they provide 6 months of tick data. Beyond that it's one minute data I believe for a year then daily. I have a scalping system I run, trades last 3-5 minutes on average. If I backtest for 6 months, I get very accurate trade history. But if I go back greater than 6 months, what I see if I fill in theory at the top or bottom of the candle, and I believe that is because I no longer have tick data for that period. The result is false (high) win rates. So I tend to just focus on a rolling 6 month look back for such a system.

I'm by no means an expert on back testing. I'm still learning. But have also learned to tempter my excitement when I develop a system and see the back test results. There is likely a few things I have either overlooked or are just not accurate thus producing abnormally high results. So now I make limit orders on exit fill with 2 ticks of price flowing through and tighten stops in backtesting by 1 tick versus what I run live.

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

Re: Techniques to match realtime with backtest

Postby Fredi » 08 Apr 2015

Tony, thank you again for sharing your experience.

I had similiar experiences, especially with backtests that produces unbelievable (good) results.
And therefore I would like to find tips / advices, if there are any proven techniques (best kind of entries/exits, backtests) in such environments as described. In order to get realistic backtesting (BT) results and (hopefully) still profit in real life (RT).

Is this a reasonable approach (same hit rate in BT / RT, poorer results in RT)?

Code: Select all

if marketposition = 0 and condition_long then begin
deviation = 0;
if (Close <= limit_long) or (Low <= limit_long) then Buy ("Market Long") next bar at market
else Buy ("Limit Long") next bar at limit_long Limit;
end;

if marketposition = 1 then begin
deviation = EntryPrice - limit_long;
Sell ("Long Target") next bar at (EntryPrice + profit - deviation) Limit;
Sell ("Long Stop") next bar at (EntryPrice - EinR + deviation) Stop;
end;
It would be great, if some other MC users / traders would share their experiences.


Return to “MultiCharts”