Return multiple VariableSeries from function  [SOLVED]

Questions about MultiCharts .NET and user contributed studies.
Louis88
Posts: 24
Joined: 11 May 2013
Has thanked: 28 times
Been thanked: 1 time

Return multiple VariableSeries from function

Postby Louis88 » 13 Sep 2015

Hello,
as an absolute beginner in c#, I have the following question to ask.
Is it possible to export multiple VariableSeries from a function to an indicator?

Let's say I have this function:

Code: Select all

using System;

namespace PowerLanguage
{
namespace Function
{
public sealed class SomeVolumeCalculations : FunctionSeries<System.Int32>
{
public SomeVolumeCalculations(CStudyControl _master) : base(_master) { }
public SomeVolumeCalculations(CStudyControl _master, int _ds) : base(_master, _ds) { }

public VariableSeries<int> myVolumeUp;
public VariableSeries<int> myVolumeDn;


protected override void Create()
{
myVolumeUp = (VariableSeries<int>)CreateSeriesVar<int>();
myVolumeDn = (VariableSeries<int>)CreateSeriesVar<int>();
}

protected override void StartCalc()
{
myVolumeUp.Value = 0;
myVolumeDn.Value = 0;
}

protected override System.Int32 CalcBar()
{
//Some calculations here, maybe:
myVolumeUp.Value = (int)Bars.UpTicks[0];
myVolumeDn.Value = (int)Bars.DownTicks[0]*-1;

return default(System.Int32);

// return ????
}
}
}
}


and I want to return both myVolumeUp and myVolumeDn to the indicator.

Is it possible to find an example?
If not, can someone help me to complete this function code and to write the indicator code?
Thank you very much.

gztanwei
Posts: 32
Joined: 15 Aug 2015
Has thanked: 6 times
Been thanked: 5 times

Re: Return multiple VariableSeries from function  [SOLVED]

Postby gztanwei » 14 Sep 2015

Look at this indicator I wrote, if you have access to BMT.


https://www.bigmiketrading.com/download ... .html?view

Louis88
Posts: 24
Joined: 11 May 2013
Has thanked: 28 times
Been thanked: 1 time

Re: Return multiple VariableSeries from function

Postby Louis88 » 15 Sep 2015

I've modified the code this way:

Code: Select all

using System;
using System.Collections.Generic;

namespace PowerLanguage
{
namespace Function
{
public sealed class SomeVolumeCalculations : FunctionSeries<VariableSeries<int>>
{
public SomeVolumeCalculations(CStudyControl _master) : base(_master) { }
public SomeVolumeCalculations(CStudyControl _master, int _ds) : base(_master, _ds) { }

public VariableSeries<int> myVolumeUp;
public VariableSeries<int> myVolumeDn;


protected override void Create()
{
myVolumeUp = (VariableSeries<int>)CreateSeriesVar<int>();
myVolumeDn = (VariableSeries<int>)CreateSeriesVar<int>();
}

protected override void StartCalc()
{
myVolumeUp.Value = 0;
myVolumeDn.Value = 0;
}

protected override List<VariableSeries<int>> CalcBar()
{
//Some calculations here, maybe:
myVolumeUp.Value = (int)Bars.UpTicks[0];
myVolumeDn.Value = (int)Bars.DownTicks[0]*-1;

List<VariableSeries<int>> myVolumes = new List<VariableSeries<int>>();
myVolumes.Add(myVolumeUp);
myVolumes.Add(myVolumeDn);
return myVolumes;
}
}
}
}
but the compiler says:

'SomeVolumeCalculations.CalcBar()': return type must be 'VariableSeries<int>' to match overridden member 'FunctionObject<VariableSeries<int>>.CalcBar()'

Any help really appreciated.

christephan
Posts: 17
Joined: 04 Dec 2014
Has thanked: 2 times
Been thanked: 3 times

Re: Return multiple VariableSeries from function

Postby christephan » 15 Sep 2015

I remember FunctionSeries only support native type such as int/double/bool. not sure.

Your myVolumeUp/Down are public. So you could refer to them after you instantiate your SomeVolumeCalculations class.

For example,

Code: Select all

public class someClass : SignalObject {
..........
SomeVolumeCalculations myVolume;

protected override void Create () {
myVolume = new SomeVolumeCalculations (this);
}

protected override void CalcBar() {
myVolume.Call();

int lastUp = myVolume.myVolumeUp[1];
int lastDn = myVolume.myVolumeDown[1];
}
}

Louis88
Posts: 24
Joined: 11 May 2013
Has thanked: 28 times
Been thanked: 1 time

Re: Return multiple VariableSeries from function

Postby Louis88 » 17 Sep 2015

Hello gztanwei,
yes, that's the hint I was looking for.
Many Thanks


Return to “MultiCharts .NET”