Feel free to share the cBot code with us so that we can investigate further.
Best regards,
Panagiotis
Good day, thank you for your answer.
I can't share my full bot with you, I spent so many weeks/months to build my model…
But I can share a very simple piece of code that even doesn't work on Backtesting b ut works perfectly fine on a classic run.
I tried to run it on NSDQ and EURUSD on backtesting mode. the process starts but runs forever without any log
Thank you
using System; using System.Collections.Generic; using System.Linq; using System.Text; using cAlgo.API; using cAlgo.API.Collections; using cAlgo.API.Indicators; using cAlgo.API.Internals;
namespace cAlgo.Robots { [Robot(AccessRights = AccessRights.None)] public class EasyHistoLoad : Robot {
// Get m1 Bars Bars _OfTimeFrameBars = MarketData.GetBars(TimeFrame.Minute, SymbolName); var LastOpenTimeLoaded = _OfTimeFrameBars.OpenTimes[0]; Print("_OfTimeFrameBars.OpenTimes[0] "+ _OfTimeFrameBars.OpenTimes[0] + " time_to_test "+ time_to_test); while (_OfTimeFrameBars.OpenTimes[0] > time_to_test){ var numberOfLoadedBars = _OfTimeFrameBars.LoadMoreHistory();
Print("_OfTimeFrameBars.OpenTimes[0] "+ _OfTimeFrameBars.OpenTimes[0] + " time_to_test "+ time_to_test); if (LastOpenTimeLoaded==_OfTimeFrameBars.OpenTimes[0]){ Print( SymbolName + " Error could not load deeper historical data, last data is "+_OfTimeFrameBars.OpenTimes[0]);
The idea of my code/bot is to check some data in the past for the H4 to know if I am bullish or bearish and the to deep dive in the 1 minute chart.
Basically I have to go 60 bars on the timeframe and then go to the m1. Let s say I want to backtest from the 1st february, I check the H4 10 days before (60*4/24), that should be around mid of January and then I check some data on that date on the m1.
So most of the time I need to LoadMoreHistory on the m1.
The idea of my code/bot is to check some data in the past for the H4 to know if I am bullish or bearish and the to deep dive in the 1 minute chart.
Basically I have to go 60 bars on the timeframe and then go to the m1. Let s say I want to backtest from the 1st february, I check the H4 10 days before (60*4/24), that should be around mid of January and then I check some data on that date on the m1.
So most of the time I need to LoadMoreHistory on the m1.
while (_OfTimeFrameBars.OpenTimes[0] > time_to_test){ var numberOfLoadedBars = _OfTimeFrameBars.LoadMoreHistory();
LoadMoreHistory does not work in backtesting therefore your code enters an infinite loop.
Best regards,
Panagiotis
Hi Seb,
The workaround I use is to start the backtesting at earlier dates so that all the necessary information is loaded, while skipping all trading operations until a custom defined date. So I have a set of parameters like this
which replace the backtesting start date and I move my backtesting start date as far in the past as I want.
The idea of my code/bot is to check some data in the past for the H4 to know if I am bullish or bearish and the to deep dive in the 1 minute chart.
Basically I have to go 60 bars on the timeframe and then go to the m1. Let s say I want to backtest from the 1st february, I check the H4 10 days before (60*4/24), that should be around mid of January and then I check some data on that date on the m1.
So most of the time I need to LoadMoreHistory on the m1.
while (_OfTimeFrameBars.OpenTimes[0] > time_to_test){ var numberOfLoadedBars = _OfTimeFrameBars.LoadMoreHistory();
LoadMoreHistory does not work in backtesting therefore your code enters an infinite loop.
Best regards,
Panagiotis
Hi Seb,
The workaround I use is to start the backtesting at earlier dates so that all the necessary information is loaded, while skipping all trading operations until a custom defined date. So I have a set of parameters like this
which replace the backtesting start date and I move my backtesting start date as far in the past as I want.
I tried to use your workaround but it doesn't really work for 2 reasons :
1/ if I want to backtest the bot that I use on Live market I can't change a lot of code and so I have to keep using the same functions. It seems that even if the history date are loaded (I can see see it if I check the date with Bars[0]), I can't recall that data with the MarketData.GetBars
2/ To run the Backtest I have to choose 1 timeframe (let s say H1) but in my bot I need check the historical data of the H4 and the Daily. And so even if I start the backtest to beofre my “real” backtesting date to load the data, it loads only the data for H1 and not for H4/Daily.
Here is my code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
namespace cAlgo.Robots
{
[Robot(AccessRights = AccessRights.None)]
public class EasyHistoLoad : Robot
{
[Parameter("Backtest On/Off", Group = "BackTest", DefaultValue = false)]
public bool BackTest { get; set; }
[Parameter("Backtest Date", Group = "BackTest", DefaultValue = "2024/03/01 01:00:00")]
public string BackTestDate { get; set; }
protected override void OnStart()
{
// To learn more about cTrader Automate visit our Help Center:
The idea of my code/bot is to check some data in the past for the H4 to know if I am bullish or bearish and the to deep dive in the 1 minute chart.
Basically I have to go 60 bars on the timeframe and then go to the m1. Let s say I want to backtest from the 1st february, I check the H4 10 days before (60*4/24), that should be around mid of January and then I check some data on that date on the m1.
So most of the time I need to LoadMoreHistory on the m1.
while (_OfTimeFrameBars.OpenTimes[0] > time_to_test){ var numberOfLoadedBars = _OfTimeFrameBars.LoadMoreHistory();
LoadMoreHistory does not work in backtesting therefore your code enters an infinite loop.
Best regards,
Panagiotis
Hi Seb,
The workaround I use is to start the backtesting at earlier dates so that all the necessary information is loaded, while skipping all trading operations until a custom defined date. So I have a set of parameters like this
which replace the backtesting start date and I move my backtesting start date as far in the past as I want.
I tried to use your workaround but it doesn't really work for 2 reasons :
1/ if I want to backtest the bot that I use on Live market I can't change a lot of code and so I have to keep using the same functions. It seems that even if the history date are loaded (I can see see it if I check the date with Bars[0]), I can't recall that data with the MarketData.GetBars
2/ To run the Backtest I have to choose 1 timeframe (let s say H1) but in my bot I need check the historical data of the H4 and the Daily. And so even if I start the backtest to beofre my “real” backtesting date to load the data, it loads only the data for H1 and not for H4/Daily.
Here is my code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
namespace cAlgo.Robots
{
[Robot(AccessRights = AccessRights.None)]
public class EasyHistoLoad : Robot
{
[Parameter("Backtest On/Off", Group = "BackTest", DefaultValue = false)]
public bool BackTest { get; set; }
[Parameter("Backtest Date", Group = "BackTest", DefaultValue = "2024/03/01 01:00:00")]
public string BackTestDate { get; set; }
protected override void OnStart()
{
// To learn more about cTrader Automate visit our Help Center:
The idea of my code/bot is to check some data in the past for the H4 to know if I am bullish or bearish and the to deep dive in the 1 minute chart.
Basically I have to go 60 bars on the timeframe and then go to the m1. Let s say I want to backtest from the 1st february, I check the H4 10 days before (60*4/24), that should be around mid of January and then I check some data on that date on the m1.
So most of the time I need to LoadMoreHistory on the m1.
while (_OfTimeFrameBars.OpenTimes[0] > time_to_test){ var numberOfLoadedBars = _OfTimeFrameBars.LoadMoreHistory();
LoadMoreHistory does not work in backtesting therefore your code enters an infinite loop.
Best regards,
Panagiotis
Hi Seb,
The workaround I use is to start the backtesting at earlier dates so that all the necessary information is loaded, while skipping all trading operations until a custom defined date. So I have a set of parameters like this
which replace the backtesting start date and I move my backtesting start date as far in the past as I want.
Best regards,
Panagiotis
Hi Seb,
I did not understand what the problem is here, sorry
You should retrieve the data on start, before the if condition. That's the whole point of the workaround
protected override void OnStart()
{
// To learn more about cTrader Automate visit our Help Center:
// https://help.ctrader.com/ctrader-automate
// Print(Bars.Count());
DateTime time_to_test = Bars[Bars.Count() - 5].OpenTime.AddDays(-15);
Bars _OfTimeFrameBars = MarketData.GetBars(TimeFrame.Minute, SymbolName);
Print("Bars[0].OpenTime " + Bars[0].OpenTime + " _OfTimeFrameBars.OpenTimes[0] " + _OfTimeFrameBars.OpenTimes[0] + " time_to_test " + time_to_test);
// Print(time_to_test);
// Get m1 Bars
if (BackTest && Bars.Last().OpenTime > DateTime.Parse(BackTestDate))
{
var LastOpenTimeLoaded = _OfTimeFrameBars.OpenTimes[0];
if (_OfTimeFrameBars.OpenTimes[0] > time_to_test)
{
Print("_OfTimeFrameBars is not using Bars history already loaded");
}
}
}
I tried to use your workaround but it doesn't really work for 2 reasons :
1/ if I want to backtest the bot that I use on Live market I can't change a lot of code and so I have to keep using the same functions. It seems that even if the history date are loaded (I can see see it if I check the date with Bars[0]), I can't recall that data with the MarketData.GetBars
2/ To run the Backtest I have to choose 1 timeframe (let s say H1) but in my bot I need check the historical data of the H4 and the Daily. And so even if I start the backtest to beofre my “real” backtesting date to load the data, it loads only the data for H1 and not for H4/Daily.
Here is my code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
namespace cAlgo.Robots
{
[Robot(AccessRights = AccessRights.None)]
public class EasyHistoLoad : Robot
{
[Parameter("Backtest On/Off", Group = "BackTest", DefaultValue = false)]
public bool BackTest { get; set; }
[Parameter("Backtest Date", Group = "BackTest", DefaultValue = "2024/03/01 01:00:00")]
public string BackTestDate { get; set; }
protected override void OnStart()
{
// To learn more about cTrader Automate visit our Help Center:
The idea of my code/bot is to check some data in the past for the H4 to know if I am bullish or bearish and the to deep dive in the 1 minute chart.
Basically I have to go 60 bars on the timeframe and then go to the m1. Let s say I want to backtest from the 1st february, I check the H4 10 days before (60*4/24), that should be around mid of January and then I check some data on that date on the m1.
So most of the time I need to LoadMoreHistory on the m1.
while (_OfTimeFrameBars.OpenTimes[0] > time_to_test){ var numberOfLoadedBars = _OfTimeFrameBars.LoadMoreHistory();
LoadMoreHistory does not work in backtesting therefore your code enters an infinite loop.
Best regards,
Panagiotis
Hi Seb,
The workaround I use is to start the backtesting at earlier dates so that all the necessary information is loaded, while skipping all trading operations until a custom defined date. So I have a set of parameters like this
which replace the backtesting start date and I move my backtesting start date as far in the past as I want.
Best regards,
Panagiotis
Hi Seb,
I did not understand what the problem is here, sorry
You should retrieve the data on start, before the if condition. That's the whole point of the workaround
protected override void OnStart() { // To learn more about cTrader Automate visit our Help Center: // https://help.ctrader.com/ctrader-automate // Print(Bars.Count()); DateTime time_to_test = Bars[Bars.Count() - 5].OpenTime.AddDays(-15); Bars _OfTimeFrameBars = MarketData.GetBars(TimeFrame.Minute, SymbolName); Print("Bars[0].OpenTime " + Bars[0].OpenTime + " _OfTimeFrameBars.OpenTimes[0] " + _OfTimeFrameBars.OpenTimes[0] + " time_to_test " + time_to_test); // Print(time_to_test); // Get m1 Bars if (BackTest && Bars.Last().OpenTime > DateTime.Parse(BackTestDate)) { var LastOpenTimeLoaded = _OfTimeFrameBars.OpenTimes[0]; if (_OfTimeFrameBars.OpenTimes[0] > time_to_test) { Print("_OfTimeFrameBars is not using Bars history already loaded"); } } }
PanagiotisCharalampous
10 Apr 2024, 06:05
Hi there,
Feel free to share the cBot code with us so that we can investigate further.
Best regards,
Panagiotis
@PanagiotisCharalampous