I have tried over the last few days to review the existing code but don't have enough programming knowledge to understand what code to modify so that the PSAR calculates a different way that matches the PSAR indicator on Esignal.
As I understand it right now, Ninjatrader calculates the PSAR value different because it does not increase the acceleration value once a new extreme point is reached until the next bar. What I am wanting is for the acceleration factor to be increased when calculating the PSAR value for the current bar if the high of the current bar is also a new extreme point.
For example, with standard setting of (0.02, 0.2, 0.02) when a new trend is triggered by the PSAR, bar 1 of the new trend should have an acceleration factor (af) of 0.02 and every time a new extreme point (i.e. new high for the trend) is made, the acceleration factor should increase by 0.02 to a max of 0.2.
Right now, the way the indicator is calculating in Ninjatrader, bar 1 of the trend will have an af of 0.02. If bar 2 makes a new high, the high of bar 2 becomes the new extreme point and af increases by 0.02 to 0.04. But the calculated PSAR value for bar 2 still uses an af value of 0.02 and the new af value of 0.04 is only used for calculating the PSAR value for bar 3. In this way, the PSAR indicator is always lagging slightly because the new af factor is not used in the calculation of the current bar upon its close when calculate on bar close is set to true.
What I am trying to change in the code is for the increased af factor to be used in calculating the PSAR value for the current bar that makes a new high for the trend. In my example above, the calculation for the PSAR value for bar would use an af of 0.02 and bar 2 would use an af value of 0.04. Every bar thereafter would use an af of 0.04 until a new high is made at bar n. At that point, the PSAR value for bar n would use an af value of 0.06 etc.
Also, if you see the attached picture, when the trend changes it is my understanding that it changes when the previous bar PSAR value is crossed. In the screenshot, the long trend should switch to short when the low of the bar is lower than the previous PSAR value indicated by the cross. for some reason that is not the case and the trend changes from long to short without the low of the trend reversal bar being lower than the PSAR cross value.
It seems that a new PSAR value is calculated for the current bar and when it is crossed the switch is made and the PSAR value for the current bar is higher than the one shown on the chart. This can be seen if I run the indicator in real time and turn calculate on bar close to false. When a new bar is formed, a new PSAR value is plotted below or above the current bar. That value is different than the value of the previous bar and it is the one used in determining the trend change.
What I would like to see is for the trend change to only occur when the PSAR value of the previous bar is breached. On the attached chart, this would not have occurred until 1 or 2 bar later.
Thanks for reading this long message. I hope someone could shed some light on where I am having trouble with the indicator.
Thanks
Comment