increment  [SOLVED]

Questions about MultiCharts .NET and user contributed studies.
beggar
Posts: 27
Joined: 22 Sep 2016

increment

Postby beggar » 07 Mar 2017

I am trying to increment "i" when the current bar close is less than the previous bars close
I am only getting a value 1 for "i" even when I have more than one successive close that meets the condition.
in regular multicharts, it would count up. But in the C# version I just get a value of one. What am I missing?

Code: Select all

int i = 0;
if(Bars.Close[0] < Bars.Close[1]){i=i+1;}
else{i=0;}

plot1.Set(0, i);

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

Re: increment

Postby JoshM » 08 Mar 2017

What am I missing?
Your script probably resets the `i` variable every time back to zero when the code runs. For instance, if your code comes from the `CalcBar()` method, it looks like:

Code: Select all

protected override void CalcBar()
{
int i = 0;
if(Bars.Close[0] < Bars.Close[1]){i=i+1;}
else{i=0;}

plot1.Set(0, i);
}
With that you reset the `i` variable each time to 0 (first line of code in the method).

To fix that, you'll need to move the declaration and initial assignment of the variable outside of the `CalcBar()` method like so:

Code: Select all

int i = 0;

protected override void CalcBar()
{
if (Bars.Close[0] < Bars.Close[1])
i = i + 1;
else
i = 0;

plot1.Set(i);
}

beggar
Posts: 27
Joined: 22 Sep 2016

Re: increment

Postby beggar » 08 Mar 2017

Thanks that helped!!

My brain is slowing picking up the nuances of C#.

beggar
Posts: 27
Joined: 22 Sep 2016

Re: increment

Postby beggar » 08 Mar 2017

Is there a way to index a public function with an integer output? I am trying to reference a previous integer value of m_testup and m_testdown.
I tried to used a variable series but the _highestbar function is a simple integer





m_aroonup = _HighestBar.HighestBar(Bars.High, length +1);

m_aroondown = _LowestBar.LowestBar(Bars.Low, length +1 );

m_testup = 100* (length - m_aroonup)/length;

m_testdown = 100* (length - m_aroondown)/length;

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

Re: increment  [SOLVED]

Postby JoshM » 09 Mar 2017

Is there a way to index a public function with an integer output? I am trying to reference a previous integer value of m_testup and m_testdown.
I tried to used a variable series but the _highestbar function is a simple integer
You'll need to store those `HighestBar()` values in a `VariableSeries<T>`. Here is an example for that by Henry. Once you do, you can then access that variable series' previous values.

beggar
Posts: 27
Joined: 22 Sep 2016

Re: increment

Postby beggar » 13 Mar 2017

That worked thanks.


Return to “MultiCharts .NET”