Optimization Backtesting Settings Data
Optimization Backtesting Settings Data
24 Apr 2019, 14:20
Hello,
following scenario:
- Optimization Backtesting Settings Data -> h1 (or m1 - does not matter) bars from Server (open prices)
- Optimization is running and a position with a stop loss and a take profit is generated
- Further h1 (or m1) bar open price is processed (e.g. bar index 100). Now the open price of that bar (100) would not trigger the stop loss or take profit
- Next h1 (or m1) bar open price is processed (bar index 101). Now the open price of that bar (101) would also not trigger the stop loss or take profit. But the High / Low or Close of the previous bar 100 would trigger the stop loss or take profit.
Now my question is:
would the stop loss or take profit be triggered at bar index 101 (because of the high, low or close of bar 100)?
Or in other words:
will stop loss or take profit only be triggered by an open price in all other modes than tick data (but not because of a high, low or close of a previous bar)?
Thanks in advance for your help.
Best regards,
andi21
Replies
PanagiotisCharalampous
24 Apr 2019, 16:04
Hi andi21,
Based on your image, I would expect the SL to trigger on the opening of the third yellow bar. Is this what you expect as well?
Best Regards,
Panagiotis
@PanagiotisCharalampous
PanagiotisCharalampous
24 Apr 2019, 16:27
( Updated at: 21 Dec 2023, 09:21 )
Hi andi21,
The cBot will honor the SL and TP prices regardless the fact that only m1 bar data is used. See the example below
using System; using System.Linq; using cAlgo.API; using cAlgo.API.Indicators; using cAlgo.API.Internals; using cAlgo.Indicators; namespace cAlgo.Robots { [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class NewcBot : Robot { [Parameter(DefaultValue = 0.0)] public double Parameter { get; set; } protected override void OnStart() { ExecuteMarketOrder(TradeType.Buy, Symbol.Name, 1000, "", 2, 100); } protected override void OnTick() { Print("Test"); } protected override void OnStop() { // Put your deinitialization logic here } } }
and see where the SL is triggered
The difference with the tick data execution is that the OnTick() function is called only when the bar changes (hence the print statement in OnTick() for demonstration). So if you have logic in OnTick() method, backtesting on bars is not recommended.
Best Regards,
Panagiots
@PanagiotisCharalampous
andi21
24 Apr 2019, 16:41
Hi Panagiots,
ah, i see.
Ok, that is good like i would expect it.
In my cBot i use the OnTick-override though, but within the method i execute code only if a new bar is processed (bar index has changed). So my bot processes something only once per new bar.
I know that i could use the OnBar-override instead, but i prefer the OnTick-override.
So the conclusion is, that - also in my case (using OnTick-override, but internal processing within my method is done only once per new bar) - SL and TP are triggered correctly so not depending only on open prices if using "only open prices"-mode.
Thank you for your fast and purposeful help.
Best regards,
andi21
@andi21
PanagiotisCharalampous
24 Apr 2019, 16:45
Hi andi21,
Please note that this applies only for built in SL and TP. If you have a custom made logic, like below, then your execution will not be accurate
using System; using System.Linq; using cAlgo.API; using cAlgo.API.Indicators; using cAlgo.API.Internals; using cAlgo.Indicators; namespace cAlgo.Robots { [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class NewcBot : Robot { [Parameter(DefaultValue = 0.0)] public double Parameter { get; set; } protected override void OnStart() { ExecuteMarketOrder(TradeType.Buy, Symbol.Name, 1000); } protected override void OnTick() { if (Positions.Count > 0 && Positions[0].Pips < -2) Positions[0].Close(); } protected override void OnStop() { // Put your deinitialization logic here } } }
Best Regards,
Panagiotis
@PanagiotisCharalampous
PanagiotisCharalampous
24 Apr 2019, 14:29
Hi andi21,
Do you have a scenario where we can see this behavior (cBot, cBot parameters, backtesting dates)?
Best Regards,
Panagiotis
@PanagiotisCharalampous