![]() |
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
|
|||||||
| Indicator Development Support for the development of custom indicators using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Junior Member
Join Date: Jan 2008
Posts: 9
Thanks: 0
Thanked 0 times in 0 posts
|
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). |
|
|
|
|
|
#2 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
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?
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Junior Member
Join Date: Jan 2008
Posts: 9
Thanks: 0
Thanked 0 times in 0 posts
|
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. .. |
|
|
|
|
|
#4 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
|
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.
Ray
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Junior Member
Join Date: Jan 2008
Posts: 9
Thanks: 0
Thanked 0 times in 0 posts
|
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. |
|
|
|
|
|
#6 |
|
Senior Member
Join Date: Oct 2008
Location: US&A
Posts: 115
Thanks: 0
Thanked 1 time in 1 post
|
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... |
|
|
|
|
|
#7 |
|
Senior Member
Join Date: Oct 2008
Location: US&A
Posts: 115
Thanks: 0
Thanked 1 time in 1 post
|
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] ??? |
|
|
|
|
|
#8 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
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
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#9 |
|
Senior Member
Join Date: Oct 2008
Location: US&A
Posts: 115
Thanks: 0
Thanked 1 time in 1 post
|
Josh,
perfect. Thanks.
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
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 |