NexusFi: Find Your Edge


Home Menu

 





How do you code a detrended oscillator?


Discussion in NinjaTrader

Updated
    1. trending_up 4,268 views
    2. thumb_up 3 thanks given
    3. group 2 followers
    1. forum 6 posts
    2. attach_file 0 attachments




 
Search this Thread
  #1 (permalink)
StephenAndersen
Wilton, CT U.S.A.
 
Posts: 6 since Mar 2013
Thanks Given: 1
Thanks Received: 0

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?


Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Orban Crashes to 21pct on Record Turnout -- McIlroy Drop …
Prediction Markets & Event Contracts
Double Deadlock: Rubio Calls Hormuz Tolls "Unfeasib …
Traders Hideout
Topstep Slashes XFA Payout Caps by Up to 60% -- Flagship …
Funded Trading Evaluation Firms
400 Million Barrels to Address Middle East Supply Disruption
Commodities
February Derivatives Boom -- Every Futures Asset Class S …
Traders Hideout
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Sober Journey With S&P
21 thanks
2026 Jlab journal
10 thanks
Trying to learn Volume and price action correlation
8 thanks
Algo automated / semi-automated trading anyone?
6 thanks
Hello Im new here
5 thanks
  #3 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader
Broker: Interactive Brokers
Trading: Futures & Stocks
Posts: 9,887 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,114



StephenAndersen View Post
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?


Reply With Quote
Thanked by:
  #4 (permalink)
StephenAndersen
Wilton, CT U.S.A.
 
Posts: 6 since Mar 2013
Thanks Given: 1
Thanks Received: 0

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.


Reply With Quote
  #5 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader
Broker: Interactive Brokers
Trading: Futures & Stocks
Posts: 9,887 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,114


StephenAndersen View 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.

In this case you have two options:

(1) You can use the Awesome Oscillator

https://nexusfi.com/download/ninjatrader-7/indicators/857-download.html?view

and set the fast period to 1 (the close is identical with the 1-period SMA).


(2) If you want to try out other moving average types, you can also use the MACDUniversalX3



and set the fast moving average period to 1.


Reply With Quote
Thanked by:
  #6 (permalink)
StephenAndersen
Wilton, CT U.S.A.
 
Posts: 6 since Mar 2013
Thanks Given: 1
Thanks Received: 0

Thanks Fat Tails,


fastSMA = SMA(Close, fastPeriod);
slowSMA = SMA(Close, slowPeriod);

oscillatorValue = fastSMA[0]-slowSMA[0]

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.

Thanks,

Stephen


Reply With Quote
  #7 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader
Broker: Interactive Brokers
Trading: Futures & Stocks
Posts: 9,887 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,114


StephenAndersen View Post
Thanks Fat Tails,


fastSMA = SMA(Close, fastPeriod);
slowSMA = SMA(Close, slowPeriod);

oscillatorValue = fastSMA[0]-slowSMA[0]

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.

Thanks,

Stephen


You just need to comment out everything related to Plots[1] an Plots[2]. 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.


Reply With Quote




Last Updated on September 24, 2013


© 2026 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 - Downloads - Top
no new posts