I'm trying to emulate an ATR-based trailing stop in a NinjaTrade black box indicator (I can't see the code). The basic issue appears to be that NT's and MultiChart's ATR calculation produce quite different results.
Any ideas why this might be? ATR should be a really straight-forward calculation and the NT ATR code looks like it does what I'd expect it to do.
MultiCharts ATR vs. NT ATR [SOLVED]
-
- Posts: 191
- Joined: 27 Apr 2010
- Location: San Jose
- Has thanked: 67 times
- Been thanked: 10 times
MultiCharts ATR vs. NT ATR
- Attachments
-
- NinjaTrade_ATR_code.png
- (13.57 KiB) Downloaded 713 times
-
- NinjaTrader_5R_chart.png
- (67.25 KiB) Downloaded 711 times
-
- MultiCharts_5R_chart.png
- (42.2 KiB) Downloaded 710 times
- furytrader
- Posts: 354
- Joined: 30 Jul 2010
- Location: Chicago, IL
- Has thanked: 155 times
- Been thanked: 217 times
Re: MultiCharts ATR vs. NT ATR
I'm not sure if this is your reason for concern, but one reason why the indicator on the charts may look different is (I'm guessing) that the axis on MultiCharts is set to some minimal incremental value - so it isn't plotting the indicator at the level of precision that NT is. This does not mean, however, that it is necessarily calculating it incorrectly (although it could be).
If you want to check to make sure when MultiCharts is calculating the average true range correctly, I would do the following:
1) Use a Print command to show the TrueRange for the last bar on the chart and manually verify that it is correct. That is, use:
2) If you pass test #1, I would then print out the TrueRange for each bar as follows ...
PRINT(DATE,",",TIME,",",NumToStr(TrueRange,5);
... and then copy and paste the results into Excel or some other spreadsheet program and average them for the last bar (going back as far as you want). Compare this to the final ATR value calculated by MultiCharts to confirm whether it is correct.
If you want to check to make sure when MultiCharts is calculating the average true range correctly, I would do the following:
1) Use a Print command to show the TrueRange for the last bar on the chart and manually verify that it is correct. That is, use:
Code: Select all
IF LASTBARONCHART = TRUE THEN BEGIN
Print(NumToStr(TrueRange,5); // The second number here is the precision to be displayed
End;
PRINT(DATE,",",TIME,",",NumToStr(TrueRange,5);
... and then copy and paste the results into Excel or some other spreadsheet program and average them for the last bar (going back as far as you want). Compare this to the final ATR value calculated by MultiCharts to confirm whether it is correct.
Re: MultiCharts ATR vs. NT ATR [SOLVED]
The Summation of the True Range is a bit different in NJ and MC/TS.
This gives the NT ATR in MC:
This gives the NT ATR in MC:
Code: Select all
inputs:
ATRLength( 14 );
variables:
NinjaTrueRange ( 0 ),
NinjaAtr ( 0 ) ;
NinjaTrueRange = MaxList ( Absvalue(Low[0] - Close[1]) , MaxList ( High[0] - Low[0] , Absvalue ( High [0] - Close[1] ) ) );
NinjaAtr = (((( MinList(CurrentBar + 1, ATRLength) - 1) * NinjaAtr [1]) + NinjaTrueRange ) / ( MinList ( CurrentBar + 1, ATRLength )));
plot1(NinjaAtr );
-
- Posts: 191
- Joined: 27 Apr 2010
- Location: San Jose
- Has thanked: 67 times
- Been thanked: 10 times
Re: MultiCharts ATR vs. NT ATR
Results. Thanks again, SP.
- Attachments
-
- NinjaTrader_ATR_vs_MultiCharts_ATR.png
- (49.04 KiB) Downloaded 730 times