Different trades in live vs backtest

Questions about MultiCharts and user contributed studies.
Marco75
Posts: 4
Joined: 15 Dec 2023

Different trades in live vs backtest

Postby Marco75 » 16 Dec 2023

Hi, I have a strategy live on MGC, 60' bar chart.
The 7th and 8th of December the strategy was flat with no trades, but during the following week end I reloaded the same strategy and both the 7th and the 8th two short trades appeared but they were not done in live.
No orders were generated in live and no sign of cancelled or rejected orders in the Order and Position Tracker window.
I have checked the market data and the short entry conditions should have triggered the trades as correctly displayed in the reloaded chart.
I don't see this situation similar to any other known situations that may lead to differences of live trading vs backtesting.
Any clue on how this could happen?

I'm using TS as datafeed and IB as broker.
Multichart version is 14.0 Release (Build 23013)

I attach the screen shot of the live chart and the reloaded one.
Attachments
MGC.pdf
(485.43 KiB) Downloaded 49 times

User avatar
Polly MultiCharts
Posts: 203
Joined: 20 Jul 2022
Has thanked: 1 time
Been thanked: 56 times

Re: Different trades in live vs backtest

Postby Polly MultiCharts » 20 Dec 2023

Hello Marco75

It is expected to have a certain discrepancy between test and live trading results. When you reloaded the charts, the strategy was recalculated on historical data and you saw the backtesting results.

Backtesting is a great analysis tool, but it has certain limitations as any other simulation, some of the real trading factors simply cannot be replicated on historical data. Backtesting cannot simulate real market movement activity, order queue and latency. Backtesting, optimization, and forward testing (real-time simulation) provide an insight into potential performance of your strategy in an “ideal world”. This information should be analyzed to get a range of possible scenarios.

For more info please refer to these pages:

Marco75
Posts: 4
Joined: 15 Dec 2023

Re: Different trades in live vs backtest

Postby Marco75 » 22 Dec 2023

Hi, thanks for the reply.
In reality I understood why the system is not working in live.
It is because the system allows to open a trade only on specific bars of the session (timeframe 60m) and this is done with a counter that restarts from 1 at every session start.
The lines of code to do that are the following:
Input: MyEntryBar(8);
variables: mycount(0),slb(false) ;
slb=sessionlastbar;
if slb[1] then mycount = 0;
mycount= mycount+1;
If mycount = MyEntryBar then buy ....

I have noticed that in backtest this works perfectly but in live the counter "mycount" doesn't go to zero at the beginning of the session but keeps counting (24, 25, ...).
It looks like the keyword "Sessionlastbar" doesnìt work in live. Am I correct?

User avatar
Polly MultiCharts
Posts: 203
Joined: 20 Jul 2022
Has thanked: 1 time
Been thanked: 56 times

Re: Different trades in live vs backtest

Postby Polly MultiCharts » 22 Dec 2023

Marco75,

SessionLastBar might not work on tick-based charts and it does not work if the last bar closes before the end of the session and the symbol no longer ticks. It also works with a delay of 5 minutes, but you can change this value in the registry. Please note that we do not recommend changing any values in the registry as it might influence the overall performance.
For more info about SessionLastBar behavior in real-time trading please refer to this forum thread.

Marco75
Posts: 4
Joined: 15 Dec 2023

Re: Different trades in live vs backtest

Postby Marco75 » 23 Dec 2023

Thanks for the reply but I still don't understand if my case falls into one where Sessionlastbar doesn't work.

I am using it on MGC future on a 60m bar chart with regular session set (1800 - 1700 exchange time).
The last bar closes exactly at the end of the session (1700 exchange time).
The symbol no longer ticks after 1700 as the session is closed.

The code verifies if the previous bar was the last with the condition posted above (so the 5 minute delay should not be a problem).

In this situation why is it not working live?
Let me know if you need further details to detect the problem.

User avatar
Polly MultiCharts
Posts: 203
Joined: 20 Jul 2022
Has thanked: 1 time
Been thanked: 56 times

Re: Different trades in live vs backtest

Postby Polly MultiCharts » 26 Dec 2023

Marco75,

The signal is calculated when the bar closes. When you have time based resolution on the chart, the bar closes when the next bar opens or by timeout.
As far as we could see in your code slb[1] = true only when the first bar of the next session closes. For more info please see this page.
During backtesting on historical data, this happens instantly, because all the bars are already on the chart, and there is no need to wait.
In real time, you need to wait for the first bar from the next session to close.

You might try removing referring to the previous value, leave only one data series on the chart and check how it works.
We also recommend using Print to monitor the values of the variables and conditions of interest. For example, add print (symbol_currentbar, slb) at the end.

If it doesn’t help, please send the following files to our support email so that we would be able to investigate the issue:
  1. The workspace where the issue is reproduced.
  2. Export of used symbols (with data) from QuoteManager in .qmd archive.
  3. The exported scripts with all dependent functions that are used on the workspace.
  4. The screenshots demonstrating the issue.
  5. Step-by-step instruction on how to reproduce the issue.
  6. MultiCharts Logs, collected via Feedback application, when the issue is reproduced.

Marco75
Posts: 4
Joined: 15 Dec 2023

Re: Different trades in live vs backtest

Postby Marco75 » 09 Jan 2024

Hi,

in my further investigations on this issue I have noticed that on other instruments (e.g. @GC, MGCG24, @MCLG24) it looks to work correctly in live so maybe the problem is related to the Custom Future on MGC that I am using.
Do you have any suggestion on what settings or other parameters of the custom future may cause this problem so that I may check and solve?

User avatar
Polly MultiCharts
Posts: 203
Joined: 20 Jul 2022
Has thanked: 1 time
Been thanked: 56 times

Re: Different trades in live vs backtest

Postby Polly MultiCharts » 10 Jan 2024

Marco75,

Custom Futures data series may differ from other symbols as it may have different rollover settings. The data may change if you change the settings or reload the data via View → Reload. The data might also stop downloading if the rollover happens.
All of that might influence the behavior of your script, but if you’d like us to investigate the issue in detail, please send us the files as described above.

User avatar
Mark Brown
Posts: 183
Joined: 29 Nov 2016
Has thanked: 119 times
Been thanked: 18 times

Re: Different trades in live vs backtest

Postby Mark Brown » 10 Feb 2024

this will never be solved this problem has existed from day 1.

it is impossible to trade what you see as in an indicator.

the solution is to send the order from a indicator to a file and have a custom order entry system execute the trades for you.


Return to “MultiCharts”