NinjaTrader Support Forum  
X

Attention!

This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com


Go Back   NinjaTrader Support Forum > NinjaScript Development Support > Indicator Development

Indicator Development Support for the development of custom indicators using NinjaScript.

Reply
 
Thread Tools Display Modes
Old 01-21-2008, 10:59 PM   #1
Don44
Junior Member
 
Join Date: Jan 2008
Posts: 9
Thanks: 0
Thanked 0 times in 0 posts
Default Centered moving average

I have a custom dataseries that is an SMA (of another indicator) with a period of say 9, loaded using the Set method at [0]. This works and plots fine.
How can I recalculate and offset the plot result so that each latest SMA value (calculated at the current bar) plots at the point of 5 bars ago.
Note: This isn't just shifting the standard SMA,9 graph line to the left by 5 bars. It should result in a totally different shape plot...often referred to as a "centered" moving average. (However, it will not have values plotted in the latest 5 bars due to the offset.)

Thanks for your help.
(BTW, some other platforms offer this as an included indicator).
Don44 is offline  
Reply With Quote
Old 01-21-2008, 11:48 PM   #2
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

I'm not sure I follow. What you sound like you want to do is place the latest calculated SMA(9) at five bars ago. How is this different from shifting the indicator back 5? Your calculated values aren't changing so how would the graph change?
NinjaTrader_Josh is offline  
Reply With Quote
Old 01-22-2008, 09:02 AM   #3
Don44
Junior Member
 
Join Date: Jan 2008
Posts: 9
Thanks: 0
Thanked 0 times in 0 posts
Default Centered moving avaerage

Josh,
Sorry...your'e correct...too many late nights at this end.

In order to shift the plot of my custom dataseries, I tried this:

mydataseries.Set(SMA(customseries,9)[0]);
Plot0.Set(mydataseries[5]);

(if I use [0], I get the standard SMA curve plotted to the current bar, but I want to see the latest value plotted 5 bars back and so forth)

Any help is appreciated.
BTW, this is also referred to as a displaced moving average per investopedia.
..
Don44 is offline  
Reply With Quote
Old 01-22-2008, 10:18 AM   #4
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

DataSeries.Set(int barsAgo, double value)
You can also set the value for historical bars by including a "barsAgo" value that represents the number of bars ago that you want the double value to be stored at.
NinjaTrader_Ray is offline  
Reply With Quote
Old 01-22-2008, 12:40 PM   #5
Don44
Junior Member
 
Join Date: Jan 2008
Posts: 9
Thanks: 0
Thanked 0 times in 0 posts
Default Another solution

Thanks for your help.

It looks like the "Displacement" function is what I was searching for. It's simple and appears to solve the problem.
Don44 is offline  
Reply With Quote
Old 10-13-2008, 11:29 AM   #6
Faspomy
Senior Member
 
Join Date: Oct 2008
Location: US&A
Posts: 115
Thanks: 0
Thanked 1 time in 1 post
Default

NOTE: Displacement does not work in strategies.

I also tried to add displacement manually to an indicator and use it in a strategy. It did not function.



DataSeries.Set(int barsAgo, double value)

This may work...
Faspomy is offline  
Reply With Quote
Old 10-13-2008, 02:44 PM   #7
Faspomy
Senior Member
 
Join Date: Oct 2008
Location: US&A
Posts: 115
Thanks: 0
Thanked 1 time in 1 post
Default

I tried something else...


I made another indicator to house two SMAs. (sMAl1 & sMAl2 are integers to control period).

SMAline1.Set(SMA(sMAl1)[0]);
SMAline2.Set(SMA(sMAl2)[1]);

This doesn't work for some reason.
No lines are plotted unless you change the above to: SMAline2.Set(SMA(sMAl2)[0]);


Is there a reason that you cannot do: SMA(sMAl2)[NumberBesidesZero] ???
Faspomy is offline  
Reply With Quote
Old 10-13-2008, 02:54 PM   #8
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

Please see your Control Center logs for errors. You are most likely running into this issue: http://www.ninjatrader-support.com/v...ead.php?t=3170
NinjaTrader_Josh is offline  
Reply With Quote
Old 10-13-2008, 03:01 PM   #9
Faspomy
Senior Member
 
Join Date: Oct 2008
Location: US&A
Posts: 115
Thanks: 0
Thanked 1 time in 1 post
Default

Josh,


perfect. Thanks.

Faspomy is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Moving Average calculation Shiva Swinger General Programming 6 11-26-2008 10:36 AM
Moving Average of a Indicator buderim Indicator Development 56 05-05-2008 12:05 AM
Jurik Moving Average dgregor5 Strategy Development 2 12-29-2007 04:55 PM
Moving Average Envelope fetus Charting 1 09-24-2007 03:58 PM
Hull Moving Average prostyle Indicator Development 1 08-30-2007 01:34 AM


All times are GMT -6. The time now is 02:41 PM.