NexusFi: Find Your Edge


Home Menu

 





How do you code a detrended oscillator?


Discussion in NinjaTrader

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




 
Search this Thread

How do you code a detrended oscillator?

  #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?
Exit Strategy
NinjaTrader
New Micros: Ultra 10-Year & Ultra T-Bond -- Live Now
Treasury Notes and Bonds
My NT8 Volume Profile Split by Asian/Euro/Open
NinjaTrader
ZombieSqueeze
Platforms and Indicators
Deepmoney LLM
Elite Quantitative GenAI/LLM
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Get funded firms 2023/2024 - Any recommendations or word …
61 thanks
Funded Trader platforms
38 thanks
NexusFi site changelog and issues/problem reporting
26 thanks
GFIs1 1 DAX trade per day journal
19 thanks
The Program
18 thanks
  #3 (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



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, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,102


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



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, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,102


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


© 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