Variable reset one time per bar  [SOLVED]

Questions about MultiCharts .NET and user contributed studies.
mirek
Posts: 24
Joined: 08 Jan 2013
Has thanked: 3 times
Been thanked: 3 times

Variable reset one time per bar

Postby mirek » 02 Dec 2013

Hi all,

I need to reset 4 variables 1 time per bar, but the bar is updated by tick.Is it possible in MC.NET?

I have found something similar in MC forum:

Code: Select all

var:
Intrabarpersist playonce(0);

if condition = true
and playonce <> currentbar then
begin
playonce = currentbar;

{-- put your alert here --}

end;
Is there an example where I can see similar implementation in MC.NET?

Thank you a lot
mirek

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

Re: Variable reset one time per bar  [SOLVED]

Postby JoshM » 02 Dec 2013

I need to reset 4 variables 1 time per bar, but the bar is updated by tick.Is it possible in MC.NET?

(...)

Is there an example where I can see similar implementation in MC.NET?
You could try using the close per bar (or the open) since this happens once per bar:

Code: Select all

protected override CalcBar()
{
// ....

if (Bars.Status == EBarState.Close)
{
// Reset variables once per bar, on bar close
myCounter = 0;
}
}
Or something that's more similar to the code example you posted:

Code: Select all

int playOnce = 0;

protected override CalcBar()
{
if (Bars.CurrentBar != playOnce)
{
// Do something once per bar

playOnce = Bars.CurrentBar;
}
}

mirek
Posts: 24
Joined: 08 Jan 2013
Has thanked: 3 times
Been thanked: 3 times

Re: Variable reset one time per bar

Postby mirek » 03 Dec 2013

Hi JoshM,

the solution with EBarState is excellent. I would wish to see it somewhere in the doc:-)

Thx a lot.

mirek


Return to “MultiCharts .NET”