I'm having trouble coding the difference between a shorter-period simple moving average and a longer-period simple moving average as an oscillator in NinjaTrader. The result is a de-trended oscillator that can help getting into a strong trend. Would anyone mind helping write this?
If you calculate the difference between a shorter SMA and a longer SMA, the result will be a MACD type indicator. The Awesome Oscillator and Linda Bradford-Raschke's 3/10 Oscillator are both calculated as the difference between two SMAs. They are momentum oscillators and can be used to enter or exit positions based on momentum.
If you talk about the detrended oscillator, it is completely different. For the detrended oscillator you do not compare two moving average, but you compare a moving average to the close in the center of the lookback period of that moving average. If you select a SMA with the lookback period of N, then the detrended oscillator compares the price N/2 bars ago to the current value of the SMA. This information is not "up-to-date" and cannot be used for momentum trading, but is a tool in cycle analysis.
What do you intend to do with the oscillator?
The following user says Thank You to Fat Tails for this post:
My mistake. I was actually just looking for the difference between closing prices and a simple short-period moving average on price plotted as an indicator. On a short horizon intraday chart, it can be used to help enter a position once the most recent bar has closed via divergence or other interpretations.
These lines of code from the awesome oscillator are the only ones I need plotted. I tried to edit out the rest but couldn't make a functioning indicator when I tried to do so. Does anyone know how to code this formula into NinjaTrader? Any help would be greatly appreciated.
You just need to comment out everything related to Plots an Plots. Also remove all lines referring to "SignalLine" and "Oscillator", and just keep those related to "OscillatorLine". You also need to modify the properties accordingly.
Alternatively you can use the indicator as it is and just set the plots that you do not need to transparent.