Counting Bars on Chart

Questions about MultiCharts and user contributed studies.
Eric1704
Posts: 21
Joined: 29 Nov 2022
Has thanked: 9 times

Counting Bars on Chart

Postby Eric1704 » 26 Mar 2024

Hi. Does anyone have an example of how to count bars since an event like a MA crossover?
Thanks.

User avatar
TJ
Posts: 7743
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: Counting Bars on Chart

Postby TJ » 26 Mar 2024

First, you need to create a VARIABLE to store the count value.

As soon as the event is triggered (eg crossover), you can add 1 to the variable for every new bar.

Try this:

Code: Select all

Var: Bar.Count(0); Bar.Count = BarCount +; if (MA1 > MA2 and MA1[1] <= to MA2[1]) or (MA1 < MA2 and MA1[1] >= to MA2[1]) then Bar.Count = 0;

Eric1704
Posts: 21
Joined: 29 Nov 2022
Has thanked: 9 times

Re: Counting Bars on Chart

Postby Eric1704 » 26 Mar 2024

Thank you vey much TJ. Will give it a try.

Eric1704
Posts: 21
Joined: 29 Nov 2022
Has thanked: 9 times

Re: Counting Bars on Chart

Postby Eric1704 » 08 Apr 2024

First, you need to create a VARIABLE to store the count value.

As soon as the event is triggered (eg crossover), you can add 1 to the variable for every new bar.

Try this:

Code: Select all

Var: Bar.Count(0); Bar.Count = BarCount +; if (MA1 > MA2 and MA1[1] <= to MA2[1]) or (MA1 < MA2 and MA1[1] >= to MA2[1]) then Bar.Count = 0;
Thanks TJ. And Bar.Count is automatically updated in MC when a new bar forms, correct?


Return to “MultiCharts”