Counting number of ticks in parabolic SAR

[Deleted]  
Hi, I'm fairly new to mql4, so please forgive me if this question is blatantly obvious.. I'm wondering whether or not it is possible to count the number of ticks in a parabolic SAR (i.e. if the SAR is > price and previousSAR < currentSAR then it is a 'downtrend' with 2 ticks [at least], but I would like to count them all). My ultimate goal is to take an average of the number of ticks in an uptrend and the number of ticks in a downtrend. I tried using a loop that keeps going while (for instance) previousSAR < currentSAR (changing the period from 0,1,2,....) until previousSAR > currentSAR and thus that is the number of ticks. However, when I print this, it keeps printing repeatedly so the data is practically useless. Any help would be greatly appreciated. Thanks!
[Deleted]  

If by ticks you mean the dots that get plotted at each bar, then I would look to take a time when the Psar signal swaps and then use https://docs.mql4.com/series/iBarShift to count the bars back to your reference time. There is only 1 dot per bar. so it's the same thing. If you do mean ticks as per volume... then that's a different ball game.

Anyway, hope that helps

V

[Deleted]  

Yes! That's exactly what I'm talking about (the number of dots). I'll give that a shot and will post back if I have trouble.

Thanks!

[Deleted]  
Viffer:

If by ticks you mean the dots that get plotted at each bar, then I would look to take a time when the Psar signal swaps and then use https://docs.mql4.com/series/iBarShift to count the bars back to your reference time. There is only 1 dot per bar. so it's the same thing. If you do mean ticks as per volume... then that's a different ball game.

Anyway, hope that helps

V


Ok, could you please provide a suggestion how I could incorporate the iBarShift function to count the 'dots'.. I'm not sure how to combine it with the other functions. Thanks
[Deleted]  

I haven't tested it, but something like this should do it. There may be a cleaner way and I'm sure if there are better methods, people will chime in.

Anyway, hope this helps

V

  int    uptrend_length,downtrend_length;    
  static datetime uptrend_time,downtrend_time;      
  double psar=iSAR(NULL,0,0.02,0.2,0);
  
if (psar<Bid)           // take the time that bid is above psar. Variable will stop updating when condition swaps
   {
   uptrend_time=Time[0];
   }
  
if (psar>Bid)           // take the time that bid is below psar. Variable will stop updating when condition swaps
   {
   downtrend_time=Time[0];
   }
  
if (uptrend_time >downtrend_time) // we are on an up trend which started at the last downtrend time
   {
   uptrend_length=iBarShift(NULL,0,downtrend_time);
   }
   
if (uptrend_time <downtrend_time) // we are on a down trend which started at the last uptrend time
   {
   downtrend_length=iBarShift(NULL,0,uptrend_time);
   }  
[Deleted]  
Awesome. Thanks a lot!