Side effects when calling functions?

Questions about MultiCharts .NET and user contributed studies.
Xyzzy
Posts: 162
Joined: 19 Mar 2011
Has thanked: 43 times
Been thanked: 79 times

Side effects when calling functions?

Postby Xyzzy » 21 Aug 2012

In EasyLanguage, series functions (e.g., AverageFC) are automatically recalculated once per bar. This means that the function will automatically calculate the correct value every bar, regardless of how many times you call it during each bar in your client code.

Should this still be the case with MC.Net? I've been playing around with the AverageFC function, and noticed some odd behavior.

Specifically, if the code calls "m_averagefc1[0]" just once per bar and caches the result in a variable, then the code gives the correct result:

Code: Select all

protected override void CalcBar(){
m_avg.Value = m_averagefc1[0];
Output.WriteLine("{0}, {1}", Bars.Time[0], m_avg.Value);
Plot1.Set(displace, m_avg.Value);
}
However, if the code calls "m_averagefc1[0]" more than once per bar, without caching the value, then it generates incorrect results:

Code: Select all

protected override void CalcBar(){
Output.WriteLine("{0}, {1}", Bars.Time[0], m_averagefc1[0]);
Plot1.Set(displace, m_averagefc1[0]);
}
I've attached the sample code, which is based on the Mov_Avg_1_Line indicator.

Is this expected behavior, or a bug? Either way, is it possible to get the results of a function (like AverageFC) multiple times in a bar, without it affecting the results? I'd prefer to avoid creating additional "cache" variables unless necessary, since it makes the code longer and more complex.
Attachments
AverageFCTest2.Indicator.zip
(739 Bytes) Downloaded 502 times

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Side effects when calling functions?

Postby Henry MultiСharts » 22 Aug 2012

Hello Xyzzy,

We are analyzing this behavior.

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Side effects when calling functions?

Postby Henry MultiСharts » 23 Aug 2012

Hello Xyzzy,

We were unable to reproduce this behavior in our environment. Please send us your workspace and the screenshot with description demonstrating the incorrect behavior.

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Side effects when calling functions?

Postby Henry MultiСharts » 27 Aug 2012

Hello Xyzzy,

Thank you for additional information.
We confirm that this behavior is incorrect. It will be fixed in MultiCharts .NET 8.1


Return to “MultiCharts .NET”