VariableSeries with multiple data streams

Questions about MultiCharts .NET and user contributed studies.
Fabrice
Posts: 182
Joined: 14 Jun 2011
Has thanked: 44 times
Been thanked: 30 times

VariableSeries with multiple data streams

Postby Fabrice » 20 Feb 2014

Hello,
I want to store the close of the 1st 5 min bar in a daily VariableSeries, first5MClose :
first5MClose[0] = the close of the 1st 5-min bar of today
first5MClose[1] = the close of the 1st 5-min var of yesterday
etc.
But this does not work. first5MClose[0] should not change of value during the session but it does. Strange (see snapshot). Something is wrong, but what ?

The main data stream is a tick chart. The 2nd data stream is the 5 min bar. The 3rd is the daily bar.

Thanks.

Here is the code

Code: Select all

private VariableSeries<double> first5MClose;

protected override void Create() {
DataStream5M = 2;
DataStreamDaily = 3;
first5MClose = new VariableSeries<double>(this, 0, 3);
plot3 = AddPlot(new PlotAttributes("First5MClose", EPlotShapes.Cross, Color.Blue));
}

protected override void StartCalc() {
dailyDS = BarsOfData(DataStreamDaily);
fiveMinDS = BarsOfData(DataStream5M);
}

protected override void CalcBar(){
Boolean cond1 = fiveMinDS.TimeValue.Hour == fiveMinDS.Sessions.First().StartTime.Hours;
Boolean cond2 = fiveMinDS.TimeValue.Minute == 5;
Boolean cond = cond1 && cond2;
if (cond)
first5MClose.Value = fiveMinDS.CloseValue;
plot3.Set(first5MClose[0]);
}
Attachments
Screen Shot 2014-02-20 at 12.53.50 PM.png
(76.68 KiB) Downloaded 729 times

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

Re: VariableSeries with multiple data streams

Postby JoshM » 20 Feb 2014

Session start time is retrieved by 'Bars.Sessions[index].StartTime', not 'fiveMinDS.Sessions.First().StartTime'.

You seem to want to use 'fiveMinDS.TimeValue.Minute' to retrieve the chart resolution, if I read that correctly? Chart resolution is returned by 'Bars.Info.Resolution.Size'.

I would also change your 'Boolean' class declarations to 'bool' variables (since that seems to be what you intend to do).
I want to store the close of the 1st 5 min bar in a daily VariableSeries, first5MClose :
Why do you want to use a variable series? To store the open price for the day, you could also use a double variable that is reset once per day (for calculation purposes), since it is already stored in a plot object (for which you can also reference historical values). That would make your programming task easier. (See example here)

Do you want to use multiple data series, or have you added them for the indicator? Since they are not needed for the indicator, you could also make your life somewhat easier by not including/referencing them.

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

Re: VariableSeries with multiple data stream

Postby Henry MultiСharts » 20 Feb 2014

Fabrice, VariableSeries and VariableObject will always have a value on the current bar - either user assigned or a default value. I would recommend you creating an array of C# types and filling it with the values you need.

Fabrice
Posts: 182
Joined: 14 Jun 2011
Has thanked: 44 times
Been thanked: 30 times

Re: VariableSeries with multiple data streams

Postby Fabrice » 20 Feb 2014

Thank you for your answers.

The purpose of this indicator is to understand how to use VariableSeries to :
1) calculate something from a 5-min datastream - here the close of the 1st bar of the session
2) be able to get this value from any bar in the main chart (a tick chart in this example).
3) "link" this value to a daily chart because this value will not change during all the day once it has been calculated.

For example :
- today : close of the 1st 5-min bar is 4295.5.
- yesterday : close of the 1st 5-min bar is 4330.
Then today, on the tick chart, I would like that first5MClose[0] gives 4295.5, right after the close of this 1st 5-min bar, and during all the session. And I would like that, today, on the tick chart, first5MClose[1] gives 4330. Because first5MClose is attached to the daily datastream (first5MClose = new VariableSeries<double>(this, 0, 3) ), I expect that first5MClose[0] has the same value all day long, and first5MClose[1] has the same value (the value of 1 day before) all day long.

In the snapshot, what is very strange for me, is that first5MClose[0] changes suddenly from the correct value to another one. Because, as first5MClose is "attached" to a daily bar, how can it change of value "by itself" during the session ?...

I hope I have better explained what I try to do.

Thanks.

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

Re: VariableSeries with multiple data streams

Postby JoshM » 21 Feb 2014

(...)
In the snapshot, what is very strange for me, is that first5MClose[0] changes suddenly from the correct value to another one. Because, as first5MClose is "attached" to a daily bar, how can it change of value "by itself" during the session ?...
Because the code only assigns it a value on the first bar of the session:

Code: Select all

Boolean cond1 = fiveMinDS.TimeValue.Hour == fiveMinDS.Sessions.First().StartTime.Hours;
Boolean cond2 = fiveMinDS.TimeValue.Minute == 5;
Boolean cond = cond1 && cond2;
if (cond)
first5MClose.Value = fiveMinDS.CloseValue;
In other words, by default all values of 'first5MClose' are 0, unless you specify a value for them.
Fabrice, VariableSeries and VariableObject will always have a value on the current bar - either user assigned or a default value.

Fabrice
Posts: 182
Joined: 14 Jun 2011
Has thanked: 44 times
Been thanked: 30 times

Re: VariableSeries with multiple data streams

Postby Fabrice » 03 Mar 2014

Hello JoshM,
Thank you for your answer. It seems a little bit more subtle than that since first5MClose never returns 0. Anyway, I need to further test all of this.
Regards.


Return to “MultiCharts .NET”