ExecControl.RecalcLastBarAfter Issue

Questions about MultiCharts .NET and user contributed studies.
TrTrading
Posts: 6
Joined: 17 May 2019
Been thanked: 1 time

ExecControl.RecalcLastBarAfter Issue

Postby TrTrading » 30 May 2019

In Multicharts 12.0.18187.400:

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();
}
}
}
From: https://www.tradingcode.net/multicharts ... indicator/

But the output only iterated twice and does not continue to recalc:
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
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.

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();
}
So, why won't OnRecalcLastBarAfterEvent() in the first example work with calling this.CalcBar()?

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?

TrTrading
Posts: 6
Joined: 17 May 2019
Been thanked: 1 time

Re: ExecControl.RecalcLastBarAfter Issue

Postby TrTrading » 30 May 2019

I want to also give another repeatable example.

This example is given in the forums by a forum staff member as an example for MC .NET:

Code: Select all

using System;
using System.Drawing;
using System.Linq;
using PowerLanguage.Function;

namespace PowerLanguage.Indicator
{
public class Test_RecalcLastbarAfterExample : IndicatorObject
{
public Test_RecalcLastbarAfterExample( object _ctx ) : base(_ctx) { }
private IPlotObject plot1;

object m_locker;

protected override void Create()
{
plot1 = AddPlot(new PlotAttributes("", EPlotShapes.Line, Color.Red));
m_locker = new object();
}

protected override void StartCalc()
{
Output.WriteLine("StartCalc");
}

protected override void CalcBar()
{
if (Bars.LastBarOnChart)
{
ExecControl.RecalcLastBarAfter(new TimeSpan(0, 0, 10));
Output.WriteLine("CalcBar on last bar");
}

MyCalc();
}

protected override void OnRecalcLastBarAfterEvent()
{
Output.WriteLine("OnRecalcLastBarAfterEvent");
MyCalc();
this.CalcBar();
}

int idx = 0;
protected void MyCalc()
{
lock (m_locker)
{
plot1.Set(idx++);

/*if (Bars.LastBarOnChart)
ExecControl.RecalcLastBarAfter(new TimeSpan(0, 0, 10));*/
}
}
}
}
When this code is run, the same thing happens. The code only recalculates once.

The output looks like this:
StartCalc
CalcBar on last bar
OnRecalcLastBarAfterEvent
CalcBar on last bar
Let's say we uncomment the commented code:

Code: Select all

if (Bars.LastBarOnChart)
ExecControl.RecalcLastBarAfter(new TimeSpan(0, 0, 10));
This still only recalculates one more time, then it does not continue again.

I find the behavior is the same across all the tests I've done.

Only ExecControl.Recalculate method will continuously recalc, but it recalculates all methods.

User avatar
Svetlana MultiCharts
Posts: 645
Joined: 19 Oct 2017
Has thanked: 3 times
Been thanked: 163 times

Re: ExecControl.RecalcLastBarAfter Issue

Postby Svetlana MultiCharts » 03 Jun 2019

Hello, TrTrading,

We have tested it on our end and no issues have been revealed.

Please send us a test case to support@multicharts.com so that we would be able to reproduce the issue on our end:

1. The workspace where the issue is reproduced.
2. Export of used symbols (with data) from QuoteManager in .qmd archive: http://www.multicharts.com/trading-soft ... rting_Data
3. The exported scripts with all dependent functions that are used on the workspace: http://www.multicharts.com/trading-soft ... ng_Studies
4. The video demonstrating the issue.

TrTrading
Posts: 6
Joined: 17 May 2019
Been thanked: 1 time

Re: ExecControl.RecalcLastBarAfter Issue

Postby TrTrading » 03 Jun 2019

Hello, TrTrading,

Please send us a test case to support@multicharts.com so that we would be able to reproduce the issue on our end:

1. The workspace where the issue is reproduced.
2. Export of used symbols (with data) from QuoteManager in .qmd archive: http://www.multicharts.com/trading-soft ... rting_Data
3. The exported scripts with all dependent functions that are used on the workspace: http://www.multicharts.com/trading-soft ... ng_Studies
4. The video demonstrating the issue.
Here are requested details shown below:

1. Workspace is the demo workspace that is supplied with MultiCharts .NET install: Indices Demo Workspace.wsp
2. ^XAX data enclosed here as: Export.qmd
3. Exported script enclosed here as: Test_Recalc.pln
4. Images showing the issue as detailed below.

1. The Test_Recalc indicator is inserted into the chart is shown to be running:
Test1.png
(241.48 KiB) Downloaded 302 times
2. If the script is edited to use ExecControl.Recalculate(), then it works to keep recalculating every two seconds:
Test2.png
(250.1 KiB) Downloaded 302 times
However, in this situation, ExecControl.Recalculate() executes all Calc methods. I only want the CalcBar() method recalculated.

3. So, when calling the CalcBar() method within OnRecalcLastBarAfterEvent instead of ExecControl.Recalculate(), instead of continuously recalculating CalcBar(), it stops at only a single recalc as shown below:
Test3.png
(277.93 KiB) Downloaded 302 times
I put code in to test if after a recalc event if the chart is Bars.LastBarOnChart status is still true, and it is. I even tried this code to make sure:

Code: Select all

protected override void CalcBar(){
// indicator logic
if (Bars.LastBarOnChart)
{
lastbarreached = true;
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 2 seconds
ExecControl.RecalcLastBarAfter(new TimeSpan(0, 0, 2));
}
else if (lastbarreached)
{
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);
ExecControl.RecalcLastBarAfter(new TimeSpan(0, 0, 2));
}
plot1.Set(Bars.Close[0]);
}
Regardless of what type of symbol or chart (or even the settings of the chart or properties of the study), I think it wouldn't matter at all. The recalc event should take precedence.
Indices Demo Workspace.wsp
(577.64 KiB) Downloaded 332 times
Export.qmd
(12.64 KiB) Downloaded 233 times

TrTrading
Posts: 6
Joined: 17 May 2019
Been thanked: 1 time

Re: ExecControl.RecalcLastBarAfter Issue

Postby TrTrading » 04 Jun 2019

Sorry, there was a limit of attachments. Here is the .pln file.
Test_Recalc.pln
(1.33 KiB) Downloaded 247 times
I have also sent these files to the support email.

Thank you.

User avatar
Svetlana MultiCharts
Posts: 645
Joined: 19 Oct 2017
Has thanked: 3 times
Been thanked: 163 times

Re: ExecControl.RecalcLastBarAfter Issue

Postby Svetlana MultiCharts » 05 Jun 2019

TrTrading,

We have reproduced the issue you’ve reported on our side. Sorry for inconvenience. Our engineers will work on improving this behaviour to include the fix in one of the future MultiCharts versions.


Return to “MultiCharts .NET”