OnStop() not execute on close of Ctrader
OnStop() not execute on close of Ctrader
03 Oct 2021, 10:51
Hi
I create a csv file at the start OnStart(), then at the stop OnStop() the file is deleted. This works fine when the cbot is started or stopped.
When Cbot is running and the ctrader app is closed OnStop() is not executed, in this case the csv is not deleted. Please refer to the code.
using System;
using System.IO;
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.FullAccess)]
public class OnStopV1 : Robot
{
[Parameter(DefaultValue = 0.0)]
public double Parameter { get; set; }
string filename;
protected override void OnStart()
{
filename = @"C:\temp\" + Symbol.Name + ".csv";
File.WriteAllText(filename, Symbol.Name + "," + Symbol.PipValue);
}
protected override void OnTick()
{
// Put your core logic here
}
protected override void OnStop()
{
if (File.Exists(filename)) File.Delete(filename);
// Put your deinitialization logic here
}
}
}
Please refer to the code.
Replies
m4trader4
09 Oct 2021, 12:07
RE:
Hi Ahmad
if it is only 1-3 charts with CBot running the OnStop() is executed. If there more than 15 charts with Bot running OnStop() doesnt get executed, when CTrader is closed.
Regards
Ahmed
@m4trader4
m4trader4
11 Oct 2021, 16:16
RE:
Hi
Its deleting, due to logic in OnStop() its not deleting, my mistake
@m4trader4
amusleh
04 Oct 2021, 10:11
Hi,
I tested your code and the file is deleted when I close cTrader while cBot was running, so the OnStop is getting called.
@amusleh