Trying to Code an Indicator to Measure the time taken between bars formed on tick charts. Please help !
Trying to Code an Indicator to Measure the time taken between bars formed on tick charts. Please help !
11 Jun 2023, 14:43
Hi all,
I'm attempting to code up a simple indicator that can plot the time it takes for a bar to complete on tick charts. Whilst the code doesn't provide any errors, I keep getting a log error saying, "process was unexpectedly terminated". If anyone can assist, that would be appreciated.
using cAlgo.API;
using System;
namespace cAlgo
{
[Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class TickVolatilityMeasure : Indicator
{
public DateTime PreviousbarTime;
public DateTime CurrentbarTime;
public TimeSpan TimeDifference;
[Output("Time", LineColor = "Red", LineStyle = LineStyle.Solid, Thickness = 2)]
public IndicatorDataSeries TimeElapsed { get; set; }
/*
protected override void Initialize()
{
// Initialize and create nested indicators
}
*/
public override void Calculate(int index)
{
// Calculate value at specified index
if (index == 0)
{
TimeElapsed[index] = 0;
}
else
{
PreviousbarTime = Bars.OpenTimes[index - 1];
CurrentbarTime = Bars.OpenTimes[index];
TimeDifference = (CurrentbarTime - PreviousbarTime);
double secondsDifference = TimeDifference.TotalSeconds;
TimeElapsed[index] = secondsDifference;
}
}
}
}
Replies
aarongeorge380
13 Jun 2023, 02:39
RE:
huguh said:
I tried something similar a few days ago with chatgpt.You can try yourself with your own parameters. It could work if its not too complicated. It worked fine for me
In the links below are some examples of attemps I did
https://chat.openai.com/c/0cad7ace-bca0-438e-b149-5c34566995fc
https://chat.openai.com/c/b864df40-26f1-40ca-8c2b-967915866bfc
https://chat.openai.com/c/0725ec34-5b3a-4fc2-8d1e-a52e05287896
https://chat.openai.com/c/6ffd111e-e368-48c6-9c51-f1c12cd78789
Hi huguh,
Thanks for response, unfortunately the links you provided don't work for me.
Regards,
@aarongeorge380
PanagiotisChar
13 Jun 2023, 08:32
Hi there,
Which version of cTrader do you use?
Need help? Join us on Telegram
@PanagiotisChar
aarongeorge380
13 Jun 2023, 10:21
RE:
Hi - Have fixed it - the following code seems to work if built in the target framework .NET Framework 4x, but not under .NET 6.0 for some reason - I think maybe something to do with the BeginInvokeOnMainThread - But I haven't been able to quite figure that out to date? I've tried it on both cTrader Desktop versions 4.6.7 and 4.7.11
Cheers,
using cAlgo.API;
using System;
//using cAlgo.API.Internals;
//using cAlgo.API.Indicators;
//using cAlgo.Indicators;
//using System.Linq;
//using System.Threading;
namespace cAlgo
{
[Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
[Levels(60, 120, 180, 240, 300, 360)]
public class TickVolatilityMeasure : Indicator
{
// private IndicatorDataSeries _secondsPerBar;
private DateTime PreviousbarTime;
private DateTime CurrentbarTime;
private TimeSpan TimeDifference;
[Output("Time", LineColor = "Red", IsHistogram = true,LineStyle = LineStyle.Solid, Thickness = 2)]
public IndicatorDataSeries TimeElapsed { get; set; }
//protected override void Initialize()
//{
//}
public override void Calculate(int index)
{
// Calculate value at specified index
if (index == 0)
{
TimeElapsed[index] = 0;
return;
}
else
{
PreviousbarTime = Bars.OpenTimes[index - 1];
CurrentbarTime = Bars.OpenTimes[index];
TimeDifference = (CurrentbarTime - PreviousbarTime);
double secondsDifference = TimeDifference.TotalSeconds;
TimeElapsed[index] = secondsDifference;
RefreshData();
}
}
}
}
@aarongeorge380
huguh
13 Jun 2023, 11:49
( Updated at: 13 Jun 2023, 11:55 )
RE: RE:
aarongeorge380 said:
Hi huguh,
Thanks for response, unfortunately the links you provided don't work for me.
Regards,
Sorry, I forgot to make public links. Here are the new links
(just past the links below after this): https://chat.openai.com/share/
362339a6-a1b0-4fe3-9e2b-b7b9250d9891
a1b66ec5-6dfb-400e-b3df-1410fe0a2ceb
d16bc041-79ac-4399-8dc9-deece9bdbc58
5470b74f-4b92-4a8e-8707-5cd300f5a3b4
@huguh
huguh
12 Jun 2023, 21:13
I tried something similar a few days ago with chatgpt.You can try yourself with your own parameters. It could work if its not too complicated. It worked fine for me
In the links below are some examples of attemps I did
https://chat.openai.com/c/0cad7ace-bca0-438e-b149-5c34566995fc
https://chat.openai.com/c/b864df40-26f1-40ca-8c2b-967915866bfc
https://chat.openai.com/c/0725ec34-5b3a-4fc2-8d1e-a52e05287896
https://chat.openai.com/c/6ffd111e-e368-48c6-9c51-f1c12cd78789
@huguh