Hi. Does anyone have an example of how to count bars since an event like a MA crossover?
Thanks.
Counting Bars on Chart
- TJ
- Posts: 7744
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2223 times
Re: Counting Bars on Chart
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:
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;
Re: Counting Bars on Chart
Thanks TJ. And Bar.Count is automatically updated in MC when a new bar forms, correct?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;