StrategyInfo is not returning anything from Function Object

Questions about MultiCharts .NET and user contributed studies.
sylfvdk
Posts: 57
Joined: 06 Dec 2005

StrategyInfo is not returning anything from Function Object

Postby sylfvdk » 06 May 2015

Hi,

In CalcBar() function of my Session_Equity : FunctionSimple<System.Double> class I am trying to out put:

Output.WriteLine("In CalcBar: {0}", StrategyInfo.OpenEquity);

Returning 0 for all StrategyInfo data when called from a function.

Question: is that true that we cannot get anything from StrategyInfo Interface from Function Object (FunctionSimple or FunctionSeries)?

IF I am wrong - can you get me hint.

(I can get StrategyInfo from Indicator as well as Signal)

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

Re: StrategyInfo is not returning anything from Function Obj

Postby Henry MultiСharts » 07 May 2015

Hello sylfvdk,

We have tested it on our end and it works as expected. Please find an example that demonstrates how to get StrategyInfo from a function attached.
Attachments
StrategyInfoFromFunctions.pln
(2.23 KiB) Downloaded 1771 times

sylfvdk
Posts: 57
Joined: 06 Dec 2005

Re: StrategyInfo is not returning anything from Function Obj

Postby sylfvdk » 07 May 2015

Hi, Henry.

I still cannot get StrategyInfo when calling you function from Indicator (not Signal).
Still gets all 0s

sylfvdk
Posts: 57
Joined: 06 Dec 2005

Re: StrategyInfo is not returning anything from Function Obj

Postby sylfvdk » 01 Jun 2015

Analyzing further issue with StrategyInfo, I figured out very dangerous thing.
It seems that code behavior depends on Comments we have in the code.
Looks like lazy initialization depends on keyword in the Text of the Indicator.

I really would like to ask MultiChart Support carefully look at my example and confirm / fix / reject the issue. We should be able to change comments without re-testing all the scenarios.

I tested the scenario on several my machines on both 32/64 bit systems and it is reproducible 100%.

Or I am doing something wrong?

1. I put any strategy on my Chart - that gives couple of trades every day.

2. I create very simple Function, that using StrategyInfo:

using System;
using System.Drawing;
using System.Linq;

namespace PowerLanguage
{
namespace Function
{
public sealed class Test_Functions : FunctionSimple<System.Double>
{
public Test_Functions(CStudyControl _master) : base(_master) { }
public Test_Functions(CStudyControl _master, int _ds) : base(_master, _ds) { }

protected override void Create()
{
}

protected override void StartCalc()
{
}

protected override System.Double CalcBar()
{
return StrategyInfo.ClosedEquity;
}
}
}
}

3. I created Indicator that calls my function - Returns all 0!!! (Which is wrong)
using System;
using System.Drawing;
using System.Linq;
using PowerLanguage.Function;

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

protected override void Create()
{
tf = new Test_Functions(this);
plot1 = AddPlot(new PlotAttributes("Open Equity", EPlotShapes.Line, Color.Red));
}
protected override void StartCalc()
{
}
protected override void CalcBar()
{
plot1.Set(tf.Call());
}
}
}

4. After that I added Comment line in my indicator like
//StrategyInfo
and it started working. New working Indicator is below:

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

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

protected override void Create()
{
tf = new Test_Functions(this);
plot1 = AddPlot(new PlotAttributes("Open Equity", EPlotShapes.Line, Color.Red));
}
protected override void StartCalc()
{
//StrategyInfo
}
protected override void CalcBar()
{
plot1.Set(tf.Call());
}
}
}
gives correct values ...

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: StrategyInfo is not returning anything from Function Obj

Postby JoshM » 02 Jun 2015

4. After that I added Comment line in my indicator like
//StrategyInfo
and it started working. New working Indicator is below:
I wouldn't be surprised if this is caused by saving and the subsequent recompiling of the script, after which the script object is re-created again on the chart. So it probably doesn't have to do with the comment being added, but merely the editing and saving of the script.

But I didn't replicate all your steps so I might be mistaken here.

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

Re: StrategyInfo is not returning anything from Function Obj

Postby Henry MultiСharts » 02 Jun 2015

Hello sylfvdk,

When changes have been done in the function code - you need to recompile all of the studies that utilize it. The easiest solution is to use the "Force recompile all studies" button in the PowerLanguage .NET Editor.

sylfvdk
Posts: 57
Joined: 06 Dec 2005

Re: StrategyInfo is not returning anything from Function Obj

Postby sylfvdk » 02 Jun 2015

Henry, this is not compilation issue. This is a bug.

I tried to put comments like below without 'o' at the end - it doesn't work
//StrategyInf

It works correctly ONLY if anywhere in Indicator code (including comments) we have met StrategyInfo syntax.

Henry - I almost spend a week with this problem, and really would like you to try to reproduce it.
This is very simple function and Indicator.

THE CASE WHERE CODE BEHAVOUR DEPENDS ON COMMENT LINE IS UNACEPTABLE.
Please, accept this as a bug and fix it or Please let me do what I am doing wrong.

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

Re: StrategyInfo is not returning anything from Function Obj

Postby Henry MultiСharts » 03 Jun 2015

Hello sylfvdk,

Our developers say that this behavior is an expected peculiarity of C#. There are different modes of study execution:
1. default, when the indicator execution is not dependent on other studies;
2. when indicator calls StrategyInfo information it should be calculated right after the strategy is calculated. It should be recalculated if the strategy is recalculated.
Therefore you need to use StrategyInfo in your code either directly or just in a comment to trigger the proper execution mode of your indicator.

sylfvdk
Posts: 57
Joined: 06 Dec 2005

Re: StrategyInfo is not returning anything from Function Obj

Postby sylfvdk » 04 Jun 2015

Hi, Henry.

1. Thanks for confirming this with the development team.

2. To summarize on where we are:
Indicator should have syntax 'StrategyInfo' anywhere in it's code (could be even within comments) to properly initialize StrategyInfo Object that could be accessible within Function that Indicator calls

3. This is NOT the way C# behaves, this is how it is coded in PowerLanguage .NET

4. I have very serious doubts about this implementation:
As being a software developer for over 20 years, I assume that I can change comments the way I want without full retesting of the solution. The way PowerLanguage is designed means: You change 1 letter in the comments - you should re-Test whole solution. This is VERY BAD PRACTICE.
The other way to say - Comments becomes part of coding now!!!

5. I really would suggest to have any other way of intelligent Initialization. I understand that it is not reasonable to Initialize whole huge structures if it is not used in the code, but let's have more intelligent way of initialization - Initialization on Demand, or some other, but not scanning through source text of Indicator.

I like MultuCharts very much, using it for over 7 years when you started in Easy Language, and want MC be solid reliable product. Please, let your developers accept this issue and if possible redesign that, even for now I have way around with Comment line!?

Thanks a lot!
Josh, if you are reading - what is your opinion?

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

Re: StrategyInfo is not returning anything from Function Obj

Postby Henry MultiСharts » 05 Jun 2015

Hello sylfvdk,

Thank you for your feedback. All suggestions are forwarded to the management of the company and are evaluated in a timely manner. Please note that even though we value your opinion not all requests can be implemented due to the fact that some features do not fit into our current roadmap.

mips4pips
Posts: 10
Joined: 27 Nov 2012
Has thanked: 10 times
Been thanked: 2 times

Re: StrategyInfo is not returning anything from Function Obj

Postby mips4pips » 18 Jun 2015

The behavior described described by poster sylfvdk and finally acknowledged by Henry uncovers a bad design decision made by the Multicharts .net designers. Unfortunately, there were several blunders in the implementation of this great product when the .net product was designed.

This particular issue deserves more than the standard "forwarded to management" and "fit into roadmap" answer. From a programmer's point of view, it is a serious bug and it should be fixed.

The first step is to clearly document the current status. Developers should not have to guess or find out the hard way about undocumented non-standard behavior.

The second step is to provide an alternative solution that does not depend on adding a comment to the code for the system to work right.

Thirdly, after some time with both solutions implemented, inform the developer community and remove the faulty one.

I wanted to give my humble opinion on how to deal with this issue, with the goal of continuing to improve a great product, Multicharts .net.

Thanks.

sylfvdk
Posts: 57
Joined: 06 Dec 2005

Re: StrategyInfo is not returning anything from Function Obj

Postby sylfvdk » 25 Jun 2015

Thanks for supporting my point, poster mips4pips.

Henry, I would like to make additional strength to this point. In my opinion, being your life time customer, I would expect all of the following:

1. Immediate acknowledgement of the management to accept this issue as 'critical' (at least);
2. Immediate prioritization of the issue as dangerous for the customers;
3. Publishing what actions are taken;

Henry, we really love the product, and those kind of decisions of its leads - are disappointing.
Hope, you understand and Thanks for your help.

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

Re: StrategyInfo is not returning anything from Function Obj

Postby Henry MultiСharts » 02 Jul 2015

Dear users,

We appreciate your comments. Let me reassure you that we acknowledge this design limitation.
We will have it documented in the support materials in due time.


Return to “MultiCharts .NET”