Backtesting multi-symbol cBot gives inconsistent results depending on base chart (in 3.7)
Backtesting multi-symbol cBot gives inconsistent results depending on base chart (in 3.7)
04 Jan 2020, 19:00
I'm in the process of converting a cBot to be multi-symbol, but I get inconsistent results when backtesting on different charts. Below is a minimal sample that shows the issue. It is a very simple bot that sells when RSI for a symbol crosses above 70. The bot runs on two uncorrelated symbols, EURUSD and CHFJPY. If I run the bot with the same backtesting settings, over the same period (say over December 2019), the results are different depending on if I ran it on a 1h EURUSD chart instance, or on a 1h CHFJPY chart instance. I'd expect to get the exact same trades regardless of which base chart the bot was attached to. Here is the minimal sample code:
using System;
using System.Linq;
using System.Collections.Generic;
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 Test : Robot
{
// Multi symbol bot test
string[] symbols = { "EURUSD", "CHFJPY" };
List< RSI_Strategy > strategies = new List< RSI_Strategy >();
protected override void OnStart()
{
foreach ( var sym in symbols )
{
var rsiStrategy = new RSI_Strategy();
rsiStrategy.init( this, sym );
strategies.Add( rsiStrategy );
}
}
}
// Sell when RSI crosses above 70
public class RSI_Strategy
{
RelativeStrengthIndex rsi;
Robot bot;
string symbol;
public void init( Robot bot, string symbol )
{
this.symbol = symbol;
this.bot = bot;
Bars bars = bot.MarketData.GetBars( bot.TimeFrame, symbol );
rsi = bot.Indicators.RelativeStrengthIndex( bars.ClosePrices, 14 );
bars.BarOpened += OnBarOpened;
}
void OnBarOpened(BarOpenedEventArgs obj)
{
if ( rsi.Result.Last(1) > 70 && rsi.Result.Last(2) <= 70 )
{
bot.ExecuteMarketOrder( TradeType.Sell, symbol, 10000, symbol, 10.0, 10.0 );
}
}
}
}
Replies
mpistorius
07 Jan 2020, 10:35
RE:
PanagiotisCharalampous said:
Hi mpistorius,
I just tried this and I get identical results
Ugh, you're right, I tested the same thing again and also now get identical results. I wouldn't have debugged this and tried to come up with a minimal example to post just for fun, but I have no idea what changed between last week and now. If I run into the issue again I'll try and find more reliable steps to reproduce. Thanks for looking anyway!
@mpistorius
PanagiotisCharalampous
07 Jan 2020, 09:57 ( Updated at: 21 Dec 2023, 09:21 )
Hi mpistorius,
I just tried this and I get identical results
Best Regards,
Panagiotis
Join us on Telegram
@PanagiotisCharalampous