M1 bars from Server (open prices) with actual spreads for Optimization and Backtesting

Created at 03 Jul 2024, 09:47
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!
Algo_robot's avatar

Algo_robot

Joined 06.12.2020

M1 bars from Server (open prices) with actual spreads for Optimization and Backtesting
03 Jul 2024, 09:47


Hello cTrader team. 

Please consider incorporating M1 bars from Server (open prices) with actual spreads for backtesting and optimization in cTrader. 

This feature would greatly enhance both the precision and efficiency of optimizations, particularly when employing the OnBar method in my cBots source code. At present, for backtesting or optimizing cBots on cTrader with M1 bars from Server (open prices), the options are limited to: 1. Fixed Spread 2. Random Spread.

I believe there are others who would also greatly appreciate having M1 bars from Server (open prices) with actual spreads.

I recognize that for bots using the OnTick method in their source code, optimization should be done with tick data from the server. However, for those utilizing the OnBar method, access to M1 bars from Server (open prices) with actual spreads would be invaluable for achieving reasonably accurate results in initial optimizations. This would provide a solid starting point for parameter values (approximate parameter values) before conducting further optimizations with tick data from the server for precise outcomes.

 

Thank you,

Mark


cTrader Automate
@Algo_robot
Replies

PanagiotisCharalampous
04 Jul 2024, 04:25

Hi there,

There is actual spread in bar information. The concept of spread makes sense only in the contect of tick data and bid and ask prices.

Best regards,

Panagiotis


@PanagiotisCharalampous

Quantrosoft
14 Jul 2024, 12:14 ( Updated at: 14 Jul 2024, 13:03 )

RE: M1 bars from Server (open prices) with actual spreads for Optimization and Backtesting

PanagiotisCharalampous said: 

Hi there,

There is actual spread in bar information. The concept of spread makes sense only in the contect of tick data and bid and ask prices.

Best regards,

Panagiotis

Hi Panagiotis

I think your statement “There is actual spread in bar information” is wrong when we look at history .zbars file format. The current format of history .zbars files looks like this:
- Opening time of the bar in milliseconds since 1.1.1970
- Opening BID price of the bar
- Highest bid price during the bar
- Lowest bid price during the bar
- Closing bid price of the bar
- Volume of trades during the bar

There is no information about the spread in .zbar files !
Instead when using bars and not ticks as the data rate for back testing and optimization, the spread must be a) set as a constant or b) is randomly generated as it can be seen here:

Because of this behavior, bars as data rates cannot be used for accurate back testing or optimization when accurate spreads are needed. Instead, the much slower tick data rates must be used if someone needs accurate spread behavior. Especially over midnight or rapid changing prices the spread can dramatically change. 

A solution to this issue is very simple! Just add spread information to the .zbars files like this:
To the already existing 6 entries per bar
- Opening time of the bar in milliseconds since 1.1.1970
- Opening BID price of the bar
- Highest bid price during the bar
- Lowest bid price during the bar
- Closing bid price of the bar
- Volume of trades during the bar
just add
- Opening ASK price of the bar
OR
- Spread of the opening price (ask - bid)

and add a 3rd option to the selection window box above: “Take spread info from history file”.
Of course because the format of the .zbars file have been changed, a complete reload of all .zbars files is necessary after the change.


@Quantrosoft

Quantrosoft
14 Jul 2024, 12:14

RE: M1 bars from Server (open prices) with actual spreads for Optimization and Backtesting

PanagiotisCharalampous said: 

Hi there,

There is actual spread in bar information. The concept of spread makes sense only in the contect of tick data and bid and ask prices.

Best regards,

Panagiotis

Hi Panagiotis

I think your statement “There is actual spread in bar information” is wrong when we look at history .zbars file format. The current format of history .zbars files looks like this:
- Opening time of the bar in milliseconds since 1.1.1970
- Opening BID price of the bar
- Highest bid price during the bar
- Lowest bid price during the bar
- Closing bid price of the bar
- Volume of trades during the bar

There is no information about the spread in .zbar files !
Instead when using bars and not ticks as the data rate for back testing and optimization, the spread must be a) set as a constant or b) is randomly generated as it can be seen here:

Because of this behavior, bars as data rates cannot be used for accurate back testing or optimization when accurate spreads are needed. Instead, the much slower tick data rates must be used if someone needs accurate spread behavior. Especially over midnight or rapid changing prices the spread can dramatically change. 

A solution to this issue is very simple! Just add spread information to the .zbars files like this:
- Opening time of the bar in milliseconds since 1.1.1970
- Opening BID price of the bar
- Highest bid price during the bar
- Lowest bid price during the bar
- Closing bid price of the bar
- Volume of trades during the bar

- Opening ASK price of the bar
OR
- Spread of the opening price (ask - bid)

and add a 3rd option to the selection window box above: “Take spread info from history file”


@Quantrosoft