cbot only working for a short history.
cbot only working for a short history.
20 Dec 2022, 15:15
When I try to run my CBot for backtesting larger past data sets, it crashes. Is there a problem with what I'm doing below? I am trying to close time after 2 min.
using cAlgo.API;
using System;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
namespace cAlgo
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class NewcBot : Robot
{
[Parameter("Quantity (Lots)", Group = "Volume", DefaultValue = 1, MinValue = 0.01, Step = 0.01)]
public double Quantity { get; set; }
[Parameter(DefaultValue = 14, MinValue = 2)]
public int Period { get; set; }
[Parameter(DefaultValue = 5)]
public int PeriodK { get; set; }
[Parameter(DefaultValue = 3)]
public int PeriodD { get; set; }
[Parameter(DefaultValue = 1)]
public int Timeru { get; set; }
private STOCHcciIndicator Stochcci;
protected override void OnStart()
{
Stochcci = Indicators.GetIndicator<STOCHcciIndicator>(Period,PeriodK,PeriodD);
}
protected override void OnBar()
{
var volumeInUnits = Symbol.QuantityToVolumeInUnits(Quantity);
if (((Stochcci.StochCCIv.Last(1) < 20 )&& (Stochcci.Trigger.Last(1) > 30)) && Positions.Count ==0)
{
ExecuteMarketOrder(TradeType.Buy, SymbolName, volumeInUnits, "Buy");
}
else if (((Stochcci.StochCCIv.Last(1) > 80 )&& (Stochcci.Trigger.Last(1) < 70)) && Positions.Count ==0)
{
ExecuteMarketOrder(TradeType.Sell, SymbolName, volumeInUnits, "Sell");
}
if(Bars.OpenTimes.Last(0) - LastResult.Position.EntryTime >= TimeSpan.FromMinutes( Timeru ))
{
foreach ( var position in Positions)
{
ClosePosition(position);
}
}
}
}
}
Replies
ashish.sah.np
21 Dec 2022, 17:32
( Updated at: 21 Dec 2023, 09:23 )
RE:
PanagiotisChar said:
Hi there,
You need to provide some more information
- Which symbol and dates do you backtest?
- What exception do you get in the log?
Need help? Join us on Telegram
Need premium support? Trade with us
Hello there, Thank you for responding and assisting. The attached link is the indicator that I am using.
It ran the following tests for less data successfully:
When I tried to increase the backtesting time, I got the following error:
Also, while running the backtest, the ctrader app began to display "Not Responding" as if it was consuming major app resources, but backtesting other cbots on my PC went smoothly. Is there anything in my code that causes this issue, and is there any solution to it?
https://ctrader.com/algos/indicators/show/3197
@ashish.sah.np
PanagiotisChar
22 Dec 2022, 08:59
Hi there,
The reason is written in the log. You seem to be calling an object which is null at the moment. You need to debug your code and check. From a first look it could be
LastResult.Position.EntryTime
Try checking if it is null before accessing it.
Need help? Join us on Telegram
Need premium support? Trade with us
@PanagiotisChar
PanagiotisChar
21 Dec 2022, 09:35
Hi there,
You need to provide some more information
Aieden Technologies
Need help? Join us on Telegram
Need premium support? Trade with us
@PanagiotisChar