Get the BarNumber of Bars.High.Highest  [SOLVED]

Questions about MultiCharts .NET and user contributed studies.
Ram
Posts: 90
Joined: 25 Nov 2014
Has thanked: 17 times
Been thanked: 5 times

Get the BarNumber of Bars.High.Highest

Postby Ram » 23 Jan 2015

Hi,

My goal is to return the BarNumber of Bars.High.Highest(100) for ex.

Is there anything like:

Code: Select all

MyBarNumber = Bars.High.Highest(100).BarNumber
Thx much in advance!
Cheers,
R.

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

Re: Get the BarNumber of Bars.High.Highest

Postby JoshM » 24 Jan 2015

My goal is to return the BarNumber of Bars.High.Highest(100) for ex.

Is there anything like:

Code: Select all

MyBarNumber = Bars.High.Highest(100).BarNumber
I don't know of such a feature. But you can code this with a loop yourself. For example:

Code: Select all

int highestBar = 0;
double highestHigh = 0;

protected override void CalcBar()
{
if (Bars.LastBarOnChart)
{
HighestHighCalculation(100, ref highestBar, ref highestHigh);

Output.WriteLine("Highest high is: {0}, this happened on bar #{1}",
highestHigh, highestBar);
}
}

private void HighestHighCalculation(int barsBack, ref int highestBar, ref double highestHigh)
{
for (int i = 0; i < barsBack; i++)
{
if (Bars.FullSymbolData.High[i] > highestHigh)
{
highestHigh = Bars.FullSymbolData.High[i];
highestBar = Bars.FullSymbolData.Count - i;
}
}
}
With an output of:

Code: Select all

Highest high is: 3412, this happened on bar #405
(Sorry that it's no VB, but hopefully it can steer in the direction of the answer).

Ram
Posts: 90
Joined: 25 Nov 2014
Has thanked: 17 times
Been thanked: 5 times

Re: Get the BarNumber of Bars.High.Highest

Postby Ram » 24 Jan 2015

Hi Josh,

Thank you very much for your reply.

I did that kind of loop in my tests earlier just to realize that it slows down the study calculation with the input sizes i use.. i hoped there's some build in function that does it more efficiently than my loop but from your reply i get that this is probably the only way..

once again, thank you for your quick reply and code!
Cheers,
R.

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

Re: Get the BarNumber of Bars.High.Highest

Postby Henry MultiСharts » 26 Jan 2015

Here is how to get the BarNumber of Bars.High.Highest(100):

Code: Select all

int _hh = 0;
Bars.High.Highest(100, out _hh, 0);

Ram
Posts: 90
Joined: 25 Nov 2014
Has thanked: 17 times
Been thanked: 5 times

Re: Get the BarNumber of Bars.High.Highest  [SOLVED]

Postby Ram » 26 Jan 2015

Works Perfectly!!!

and for all you VB.Net out there:

Code: Select all

Dim BarBack As Integer = 0
Bars.High.Highest(100, BarBack , 0)

Best,
R.


Return to “MultiCharts .NET”