• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Changing the way PSAR is calcuated

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Changing the way PSAR is calcuated

    I am hoping someone could lend a hand with a problem I am having trying to modify the way the standard PSAR indicator in Ninjatrader calculates it's value on each bar.

    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
    Attached Files

    #2
    Please also read discussion here:

    https://www.bigmiketrading.com/ninja...olic-code.html

    As far as it is my understanding, the NinjaTrader PSAR is similar to the PSAR as described by Welles Wilder in his book "New Concepts in Technical Trading Systems".

    There are a few issues that can be debated.

    (a) When price touches the value of the PSAR, but does not penetrate it, does this trigger a reversal? The NinjaTrader indicator reverses, I have coded a version that does not reverse the trend in that case.

    (b) The NinjaTrader default PSAR has a little bug. If there is a wide ranging bar that hits both the original stop and then the new stop, NinjaTrader does not change the trend.

    (c) There are also other issues as the question whether to round the PSAR value to the full tick or not. The pip setting for currencies is also an issue, if you decide to round to the full tick,

    I have also coded a variation of the PSAR which uses a small deceleration factor during a consolidation.

    Comment


      #3
      Thanks Harry, I noticed some of those same issues when reviewing the indicator values.

      I particularly noticed the issue when price hits both the original and new stop.

      But I think the biggest issue I have is that the trend change is not happening with a break of the previous PSAR value but on a value that is being calculated for the current bar. You can see from the screen shot I attached to my original post. Price never hit the previous PSAR value and yet a trend change was made.

      This is not consistent with the original Welles version as far as I know.

      Comment


        #4
        Originally posted by wcmaria View Post
        Thanks Harry, I noticed some of those same issues when reviewing the indicator values.

        I particularly noticed the issue when price hits both the original and new stop.

        But I think the biggest issue I have is that the trend change is not happening with a break of the previous PSAR value but on a value that is being calculated for the current bar. You can see from the screen shot I attached to my original post. Price never hit the previous PSAR value and yet a trend change was made.

        This is not consistent with the original Welles version as far as I know.

        I think that the NinjaTrader indicator is consistent with the original Welles Wilder version. Your chart shows a different indicator, which may or may not be identical with the NinjaTrader version.

        Please post a chart for ES or YM (any instrument traded on CME, as I have not subscribed TF data) with the NinjaTrader default PSAR, and tell me where the problem lies. I own the original book by Welles Wilder and will reproduce his rules on your chart.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by epitoma, Today, 05:21 PM
        1 response
        10 views
        0 likes
        Last Post NinjaTrader_ShawnB  
        Started by BatBart, Today, 01:24 PM
        1 response
        22 views
        0 likes
        Last Post NinjaTrader_Melissa  
        Started by ezrakoper, Today, 03:05 PM
        1 response
        7 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by asmmbillah, Today, 02:23 PM
        1 response
        17 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by steveg, Today, 02:44 PM
        1 response
        9 views
        0 likes
        Last Post NinjaTrader_Heath  
        Working...
        X