I am running this code:
Code: Select all
using System;
using System.Drawing;
using System.Linq;
using PowerLanguage.Function;
namespace PowerLanguage.Indicator{
public class Test_Recalc : IndicatorObject {
public Test_Recalc(object _ctx):base(_ctx){}
private IPlotObject plot1;
protected override void Create() {
// create variable objects, function objects, plot objects etc.
plot1 = AddPlot(new PlotAttributes("", EPlotShapes.Line, Color.Red));
}
protected override void StartCalc() {
// assign inputs
Output.Clear();
}
protected override void CalcBar(){
// indicator logic
if (Bars.LastBarOnChart)
{
Output.WriteLine("Computer time: {0} - Bar time: {1}; BarVolume: {2}",
DateTime.Now.ToString("dd-MM-yy HH:mm:ss"),
Bars.TimeValue.ToString("dd-MM-yy HH:mm:ss"),
Bars.TrueVolume().Value);
// Call the recalculation every 10 seconds
ExecControl.RecalcLastBarAfter(new TimeSpan(0, 0, 2));
}
plot1.Set(Bars.Close[0]);
}
// Implementation of the recalculation
protected override void OnRecalcLastBarAfterEvent()
{
this.CalcBar();
}
}
}
But the output only iterated twice and does not continue to recalc:
I've tried different settings, such as skip identical ticks (which shouldn't affect recalc), but nothing appears to work for continuing to recalc an indicator on a fixed interval.Computer time: 30-05-19 18:24:06 - Bar time: 29-05-19 23:59:00; BarVolume: 0
Computer time: 30-05-19 18:24:08 - Bar time: 29-05-19 23:59:00; BarVolume: 0
Is this a bug or do I have to set some properties in a chart or in the study?
However, it appears that using ExecControl.Recalculate() instead will run CalcBar() continuously.
Code: Select all
// Implementation of the recalculation
protected override void OnRecalcLastBarAfterEvent()
{
// this.CalcBar();
ExecControl.Recalculate();
}
The problem with using ExecControl.Recalculate() is that it runs StartCalc(), StopCalc() and other methods. I would like to just run the CalcBar method on the last bar only.
Has the behavior of ExecControl.RecalcLastBarAfter method changed in recent MultiCharts versions?