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
Use of VariableSeries<double> vars inside class?
Tried. Re: Use of VariableSeries<double> vars inside class?
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?
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?
Re: Use of VariableSeries<double> vars inside class?
Hi RonS
You have existing example : look at Mov_Avg_1_Line indicator
1/ at the initialisation you have
2/ inside protected override void Create(){ you have
3/ inside protected override void CalcBar(){ you have :
to create a VariableSeries in Multicharts, you just need to use this format : Initialisation , Create, SartCalc, Calcbar
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 :
you can name m_avg anyway you wantm_avg.Value = ..........
to create a VariableSeries in Multicharts, you just need to use this format : Initialisation , Create, SartCalc, Calcbar
Re: Use of VariableSeries<double> vars inside class?
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
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
Re: Use of VariableSeries<double> vars inside class?
Hi RonS,
Normally, it is the other way around :
inside your strategy and inside your function :
if you put a breakpoint on each :
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.
Normally, it is the other way around :
inside your strategy and inside your function :
if you put a breakpoint on each :
and if you check the Bars.CurrentBar value in debug modeprotected override void CalcBar(){
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.