NexusFi: Find Your Edge


Home Menu

 





Bugs in NT Parabolic code


Discussion in NinjaTrader

Updated
    1. trending_up 11,111 views
    2. thumb_up 23 thanks given
    3. group 3 followers
    1. forum 23 posts
    2. attach_file 15 attachments




 
Search this Thread

Bugs in NT Parabolic code

  #11 (permalink)
cprtrader
Adelaide Australia
 
Posts: 18 since Jun 2012
Thanks Given: 7
Thanks Received: 3

@Fat Tails,

Referring to bug #2 (that we agreed was not a bug), Wilders's rule states ... "If short, never move the SAR for tomorrow below the previous days high or today's high ...".

Looking at the attached chart, as soon as bar #2 was complete, the SAR for bar #3 (today) would be calculated, and based in the above rule, should not be below the high of bar #1 or bar#2. But bar #3 triggered the stop somewhere below the high of bar #1, thus breaching wilders rule, resulting the next 13 SAR plots all being incorrect.

I'd appreciate your thoughts. Perhaps I have missed something.

Cheers

CPR

Attached Thumbnails
Click image for larger version

Name:	NT Parabolic bug 006.jpg
Views:	210
Size:	178.1 KB
ID:	147534  
Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Are there any eval firms that allow you to sink to your …
Traders Hideout
New Micros: Ultra 10-Year & Ultra T-Bond -- Live Now
Treasury Notes and Bonds
My NT8 Volume Profile Split by Asian/Euro/Open
NinjaTrader
NexusFi Journal Challenge - April 2024
Feedback and Announcements
Better Renko Gaps
The Elite Circle
 

  #12 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,102


cprtrader View Post
@Fat Tails,

Referring to bug #2 (that we agreed was not a bug), Wilders's rule states ... "If short, never move the SAR for tomorrow below the previous days high or today's high ...".

Looking at the attached chart, as soon as bar #2 was complete, the SAR for bar #3 (today) would be calculated, and based in the above rule, should not be below the high of bar #1 or bar#2. But bar #3 triggered the stop somewhere below the high of bar #1, thus breaching wilders rule, resulting the next 13 SAR plots all being incorrect.

I'd appreciate your thoughts. Perhaps I have missed something.

Cheers

CPR

Yes, looks strange. My chart is different. As I do not have the same data provider for FOREX. If you wish exact comparisons, please do not use FOREX data, as there are too many ECNs around. An instrument traded at one exchange only would be better to do comparisons.


Reply With Quote
Thanked by:
  #13 (permalink)
cprtrader
Adelaide Australia
 
Posts: 18 since Jun 2012
Thanks Given: 7
Thanks Received: 3


@Fat Tails,

Thanks for checking. So we are back to 2 bugs in NT's Parabolic code.

Regarding bug #1 (raising or lowering the SAR), further investigation indicates it is an intermittent bug, which could explain why NinjaTrader's programmers missed it.

Examination of lower timeframe data shows there are times when raising (or lowering) the SAR is correct. One example is when price (in a downtrend) rallies and breaches the upper SAR (which immediately creates a new lower SAR), but then quickly crashes through the newly created lower SAR. The only option is to print a higher SAR. But unfortunately there are cases with NinjaTrader raises or lowers the SAR for no apparent reason. On example is the attached chart. Examination of tick data shows NinjaTrader's plot (circled) is incorrect.

Cheers

CPR

Attached Thumbnails
Click image for larger version

Name:	NT Parabolic bug 005.jpg
Views:	196
Size:	162.2 KB
ID:	147537  
Reply With Quote
  #14 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,102


cprtrader View Post
@Fat Tails,

Thanks for checking. So we are back to 2 bugs in NT's Parabolic code.

Regarding bug #1 (raising or lowering the SAR), further investigation indicates it is an intermittent bug, which could explain why NinjaTrader's programmers missed it.

Examination of lower timeframe data shows there are times when raising (or lowering) the SAR is correct. One example is when price (in a downtrend) rallies and breaches the upper SAR (which immediately creates a new lower SAR), but then quickly crashes through the newly created lower SAR. The only option is to print a higher SAR. But unfortunately there are cases with NinjaTrader raises or lowers the SAR for no apparent reason. On example is the attached chart. Examination of tick data shows NinjaTrader's plot (circled) is incorrect.

Cheers

CPR

This is what I can offer:





I will send you the indicator via private message so that you can test it.

Reply With Quote
  #15 (permalink)
cprtrader
Adelaide Australia
 
Posts: 18 since Jun 2012
Thanks Given: 7
Thanks Received: 3

@Fat Tails,

Your PSAR looks good. I like the way you identify on the chart the exact level at which the SAR was triggered.

The two attached charts compare your PSAR with NinjaTrader's (large blue plots). Generally, NT's plots are correct, but there are times when NT's plots are a complete mess, as seen on chart #1.

I also compared your PSAR with mine, and mostly our plots match perfectly. There are some instances of minor deviation, and I suspect this is due to different approaches we took to rounding. In developing my PSAR I used the prices in Wilder's book as test data, and I ensured that my program perfectly matched all calculations in the book, including partial calculations. The only way I could do this was by careful use of the rounding function. I have marked on chart #1 an example where our plots deviated by up to 3 pips, which is pretty good compared with NT's plots which at times is incorrect by up to 50 pips or more.

Chart #2 (NDX) shows examples of your SAR being triggered within price gaps. Obviously this would not occur in real trading. Another approach might be to move the SAR to the opening price to indicate the "fill" if the SAR is triggered within a gap.

My knowledge of C# is limited, so I can't see any obvious issues with your PSAR code. However it seems to assume that the initial high and low will occur within the first 10 bars. This is unlikely to be a problem with liquid instruments, however it may cause problems with less liquid markets. Another approach is to initially locate the first high and low irrespective of where they occur, and then set a variable to indicate they have been located.

Hope this helps.

Cheers

CPR

Attached Thumbnails
Click image for larger version

Name:	Fat Tails SAR 001.jpg
Views:	215
Size:	281.1 KB
ID:	147664   Click image for larger version

Name:	Fat Tails SAR 002.jpg
Views:	198
Size:	288.5 KB
ID:	147665  
Reply With Quote
Thanked by:
  #16 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,102


cprtrader View Post
@Fat Tails,

Your PSAR looks good. I like the way you identify on the chart the exact level at which the SAR was triggered.

The two attached charts compare your PSAR with NinjaTrader's (large blue plots). Generally, NT's plots are correct, but there are times when NT's plots are a complete mess, as seen on chart #1.

I also compared your PSAR with mine, and mostly our plots match perfectly. There are some instances of minor deviation, and I suspect this is due to different approaches we took to rounding. In developing my PSAR I used the prices in Wilder's book as test data, and I ensured that my program perfectly matched all calculations in the book, including partial calculations. The only way I could do this was by careful use of the rounding function. I have marked on chart #1 an example where our plots deviated by up to 3 pips, which is pretty good compared with NT's plots which at times is incorrect by up to 50 pips or more.

Of course I do not know your exact coding logic. The rules I have used are as follows

-> The first value for the stop is the extreme point (in this case low point) of the prior downtrend (Wilder does not show this stop on his charts, but I have decided to show both old and new stop for the reversal bar).
-> The second value is calculated by applying the minimum acceleration of 0.02 (no new high) or the increased acceleration of 0.04 (case new high > prior high) to the difference between the new extreme point and the previous value for the PSAR.

Afterwards the usual rules for the PSAR are followed.

If there are discrepancies, they might be data related, as not all data feeds show the same values.


cprtrader View Post
Chart #2 (NDX) shows examples of your SAR being triggered within price gaps. Obviously this would not occur in real trading. Another approach might be to move the SAR to the opening price to indicate the "fill" if the SAR is triggered within a gap.

My knowledge of C# is limited, so I can't see any obvious issues with your PSAR code. However it seems to assume that the initial high and low will occur within the first 10 bars. This is unlikely to be a problem with liquid instruments, however it may cause problems with less liquid markets. Another approach is to initially locate the first high and low irrespective of where they occur, and then set a variable to indicate they have been located.

Hope this helps.

Cheers

CPR

The price gaps are no problem. The PSAR is calculated from the prior bar, so it is available prior to the start of the trading day. If price gaps beyond the stop line, the position will be reversed with the opening of the session.

Reply With Quote
  #17 (permalink)
cprtrader
Adelaide Australia
 
Posts: 18 since Jun 2012
Thanks Given: 7
Thanks Received: 3

My logic was to initially locate the first high and the first low, and then use whichever came first to begin calculating subsequent plots as early as possible.

I am not saying this is better. It's just the logic I chose to locate the earliest plot, and to prevent problems with less liquid instruments.

Your assumption that data is the cause of plot differences is not correct. I used precisely the same data to compare our PSARs.

The biggest discrepancy I found was 3 pips, so it may not be an issue, depending of course on what you intend to do with your PSAR.

Reply With Quote
  #18 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,102


cprtrader View Post
My logic was to initially locate the first high and the first low, and then use whichever came first to begin calculating subsequent plots as early as possible.

I am not saying this is better. It's just the logic I chose to locate the earliest plot, and to prevent problems with less liquid instruments.

Your assumption that data is the cause of plot differences is not correct. I used precisely the same data to compare our PSARs.

The biggest discrepancy I found was 3 pips, so it may not be an issue, depending of course on what you intend to do with your PSAR.

Could you show me your chart with the 3 pip difference and expose the formulae that you used for calculating the stops?

Reply With Quote
  #19 (permalink)
cprtrader
Adelaide Australia
 
Posts: 18 since Jun 2012
Thanks Given: 7
Thanks Received: 3

The relevant formulae are as follows,

NextSAR = Round(NextSAR + AccFactor * (CurrSIP - NextSAR), DecimalDigits)
SARDiff = Round(Abs(CurrSIP - NextSAR), DecimalDigits)
AFxDiff = Round(SARDiff * AccFactor, DecimalDigits)

SARDiff and AFxDiff aren't needed in the calculation, however I coded them anyway to cross check against Wilder's partial numbers.
DecimalDigits is a variable that contains the number of decimal values in the price of the instrument. This could account for the differences in our SAR plots. However, if I didn't round NextSAR the results often failed to match Wilder's numbers.

I can' recall where I saw the 3 pip variance, however the attached chart (AUDJPY) shows an example of 2 pip variances which occurred on 24/11/06 and 27/11/06 (Aussie time).

I also have attached two data files (AUDJPY and NDX) which include my PSAR values for each day. If you extract your PSAR values into Excel, you can run a comparison to locate all the differences. The data originates from Kinetick, if needed.

Attached Thumbnails
Click image for larger version

Name:	Fat Tails SAR 001.jpg
Views:	193
Size:	281.1 KB
ID:	147691  
Attached Files
Elite Membership required to download: FOREX AUDJPY.txt
Elite Membership required to download: INDEX ^NDX.txt
Reply With Quote
Thanked by:
  #20 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,102



cprtrader View Post
The relevant formulae are as follows,

NextSAR = Round(NextSAR + AccFactor * (CurrSIP - NextSAR), DecimalDigits)
SARDiff = Round(Abs(CurrSIP - NextSAR), DecimalDigits)
AFxDiff = Round(SARDiff * AccFactor, DecimalDigits)

SARDiff and AFxDiff aren't needed in the calculation, however I coded them anyway to cross check against Wilder's partial numbers.
DecimalDigits is a variable that contains the number of decimal values in the price of the instrument. This could account for the differences in our SAR plots. However, if I didn't round NextSAR the results often failed to match Wilder's numbers.

I can' recall where I saw the 3 pip variance, however the attached chart (AUDJPY) shows an example of 2 pip variances which occurred on 24/11/06 and 27/11/06 (Aussie time).

I also have attached two data files (AUDJPY and NDX) which include my PSAR values for each day. If you extract your PSAR values into Excel, you can run a comparison to locate all the differences. The data originates from Kinetick, if needed.

I had hoped for a visual comparaison. Extracting that data and building an excel table is too much work for me.

Reply With Quote





Last Updated on May 27, 2014


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts