Use of VariableSeries<double> vars inside class?

Questions about MultiCharts .NET and user contributed studies.
RonS
Posts: 21
Joined: 16 Sep 2018
Has thanked: 7 times
Been thanked: 3 times

Use of VariableSeries<double> vars inside class?

Postby RonS » 16 Jan 2020

Newbie in C# here. Hope someone can help. It will be appreciated!

I would like to make a class with a VariableSeries<double> inside it. For example:

class MyClass
{
public VariableSeries<double> MyVar;

public MyClass()
{
MyVar = new VariableSeries<double>(); //please see error returned next line
//..constructor needs more than 0 arguments.

MyVar = new VariableSeries<double>(this); //please see error returned next line
//Argument 1. cannot convert from PowerLanguage.Strategy.MyClass to Powerlanguage.IStudyControl
}
}//Want to reuse this class many times...

Maybe I could resort to using the C# "List" instruction. But I would like to use the MC PublicFunctions to reuse existing code.
Can someone help?

Ron

RonS
Posts: 21
Joined: 16 Sep 2018
Has thanked: 7 times
Been thanked: 3 times

Tried. Re: Use of VariableSeries<double> vars inside class?

Postby RonS » 17 Jan 2020

I tried removing MyVar = new …. from the class. Was thinking when instanciating the class everything would work. E.G.:

private MyClass MyClass1;
MyClass1 = new MyClass(); //Compiled okay

//When I created a class member function that utilized the MyVar VariableSeries<double>.
//It had an error. e.g. could not create an instance ….

I previously had spent some time on this, forgot, and then started the above.
There must be some way to include an array inside of a class. I want to use the MC.net PublicFunctions though.
Any solutions?

RonS
Posts: 21
Joined: 16 Sep 2018
Has thanked: 7 times
Been thanked: 3 times

Re: Use of VariableSeries<double> vars inside class?

Postby RonS » 17 Jan 2020

Looks like this is being done in MC.net Functions. This would serve my purpose.

Emmanuel
Posts: 355
Joined: 21 May 2009
Has thanked: 109 times
Been thanked: 28 times

Re: Use of VariableSeries<double> vars inside class?

Postby Emmanuel » 28 Jan 2020

Hi RonS

You have existing example : look at Mov_Avg_1_Line indicator

1/ at the initialisation you have

Code: Select all

public class Mov_Avg_1_Line : IndicatorObject { private VariableSeries<Double> m_avg;


2/ inside protected override void Create(){ you have
m_avg = new VariableSeries<Double>(this);

3/ inside protected override void CalcBar(){ you have :
m_avg.Value = ..........
you can name m_avg anyway you want

to create a VariableSeries in Multicharts, you just need to use this format : Initialisation , Create, SartCalc, Calcbar

RonS
Posts: 21
Joined: 16 Sep 2018
Has thanked: 7 times
Been thanked: 3 times

Re: Use of VariableSeries<double> vars inside class?

Postby RonS » 28 Jan 2020

Hi Emmanuel,

Thank-you for your response. My upper level C# is a bit rocky and so you are a big help. When looking at the MC64.net Indicator "Mov_Avg_1_Line Indicator I see they have instantiated a Function.

I also created a function having many VariableSeries<double> variables inside it. Was able to use "new" inside the function. Everything worked inside my Strategy except the double value the Function returned would always lag the local code by 1 Bar. Any idea what is wrong?

Ron

Emmanuel
Posts: 355
Joined: 21 May 2009
Has thanked: 109 times
Been thanked: 28 times

Re: Use of VariableSeries<double> vars inside class?

Postby Emmanuel » 29 Jan 2020

Hi RonS,

Normally, it is the other way around :

inside your strategy and inside your function :

if you put a breakpoint on each :
protected override void CalcBar(){
and if you check the Bars.CurrentBar value in debug mode

You will see the function is always called first , then the signal.


it is difficult to see what is happening without seeing the code.

if the problem persist, you can create an empty shell of your code , without your strategy, just enough to produce the error and share it on this blog.

like that , it is possible to see the problem and correct it.


Return to “MultiCharts .NET”