Backtest and optimization results different on single timeframe

Created at 26 Aug 2020, 19:35
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
VL

vldmarton

Joined 26.08.2020

Backtest and optimization results different on single timeframe
26 Aug 2020, 19:35


Hi,

I have a bot that works on single market and single timeframe, always 1h. When I run optimization, it shows me 20% profit. When I run backtesting using the same parameters, I'm suddenly 7% in loss. Can anyone help me?

Thanks.

 

Code was removed.

 


@vldmarton
Replies

PanagiotisCharalampous
27 Aug 2020, 07:44

Hi vldmarton,

Please provide us with the following

  1. Broker
  2. Optimization cBot parameters
  3. Dates
  4. Selected Backtesting parameters

So that we can reproduce the issue.

Best Regards,

Panagiotis 

Join us on Telegram

 


@PanagiotisCharalampous

vldmarton
27 Aug 2020, 09:05 ( Updated at: 21 Dec 2023, 09:22 )

Broker - Purple Trading

Optimization: Starting capital 1000, Commision 30, data m1 bars, spread 1 pip

Date range: 01/06/2020 - 25/08/2020

Backtesting parameters:

Results in optimization: +196 EUR
Results in backtesting: -85 EUR

PS: I tried with tick data as well, same story


@vldmarton

PanagiotisCharalampous
27 Aug 2020, 09:13

Hi vldmarton,

Can you tell me the symbol as well?

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

vldmarton
27 Aug 2020, 09:15

RE:

Sorry, my bad. Me and my brother tested this on 2 computers, EURUSD, DAX, GPBAUD, result is the same.

 


@vldmarton

vldmarton
29 Aug 2020, 17:31

Hello Panagiotis, any news?


@vldmarton

PanagiotisCharalampous
31 Aug 2020, 08:32

Hi vldmarton,

Please provide me with the symbol of the backtesting results for the case highlighted above so that I can produce the same results.

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

vldmarton
31 Aug 2020, 09:21

RE:

The symbol was EURUSD.

 

 


@vldmarton

PanagiotisCharalampous
31 Aug 2020, 10:15

Hi vldmarton,

The problem is with your code. You need to remove the static keyword from everywhere. Else the parameters are shared between instances and a mess is caused.

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

vldmarton
31 Aug 2020, 10:45

RE:

Alright, I removed the static keyword from all bots and the bot were talking about works fine. I have a copy of this bot that trades on ticks and not bars and that one is still a bit off. Will check code for any mistakes from my side. Thanks for your help.

If you have time, could you please explain to me why is it possible that two bots use the same variable? I thought that a class is like a capsule - even though it has some static variables, they are only available from that specific instance of the class. If I had two robots with the same classname then I'd understand the mixup but as far as the robots are named differently, they should only be able to work with their variables inside the instance. At least that's my understanding of OOP.

 

 


@vldmarton

PanagiotisCharalampous
31 Aug 2020, 10:51

Hi vldmarton,

Here is the explanation for static members

A non-static class can contain static methods, fields, properties, or events. The static member is callable on a class even when no instance of the class has been created. The static member is always accessed by the class name, not the instance name. Only one copy of a static member exists, regardless of how many instances of the class are created. Static methods and properties cannot access non-static fields and events in their containing type, and they cannot access an instance variable of any object unless it's explicitly passed in a method parameter.

from Microsoft

When the cBot is optimized then many instances of the same class are initialized, sharing eventually the one and only copy of the static members.

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

vldmarton
31 Aug 2020, 10:57

RE:

Okay it all makes sense now. I was under the impression that optimization uses one instance only. 

Thanks again.


@vldmarton