![]() |
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 |
|
Member
Join Date: Mar 2009
Posts: 56
Thanks: 0
Thanked 0 times in 0 posts
|
Hi… and Happy New Year to all.
I have a question. I want to build an indicator composed of two equals moving averages, namely: SMA1 (28) [0] and SMA2 (28) [0]. But the second moving average has moved forward by 7 periods. My code move forward both moving averages, not just one. Someone can tell me where is the error? Thank you for your help. Germano The code: publicclass TwoEqualsSMA : Indicator { #region Variables privateint period = 28; // Default setting for Period privateint displace = 7; // Default setting for Displace #endregion protectedoverridevoid Initialize() { // 1° Moving average Add(new Plot(Color.FromKnownColor(KnownColor.Red), PlotStyle.Line, "Value_SMA1")); // 2° Moving average Add(new Plot(Color.FromKnownColor(KnownColor.Blue), PlotStyle.Line, "Value_SMA2")); Displacement = displace; CalculateOnBarClose = true; Overlay = true; } protectedoverridevoid OnBarUpdate() { Value_SMA1.Set(SMA(period )[0]); Value_SMA2.Set(SMA(period )[0]); } |
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,404
Thanks: 252
Thanked 972 times in 955 posts
|
Germano, the displacement would be used for both plots in your indicator.
Try for example this for more control on it - Code:
protected override void Initialize()
{
// 1° Moving average
Add(new Plot(Color.FromKnownColor(KnownColor.Red), PlotStyle.Line, "Value_SMA1"));
// 2° Moving average
Add(new Plot(Color.FromKnownColor(KnownColor.Blue), PlotStyle.Line, "Value_SMA2"));
//Displacement = displace;
CalculateOnBarClose = true;
Overlay = true;
}
protected override void OnBarUpdate()
{
if (CurrentBar < displace) return;
Value_SMA1.Set(SMA(period )[0]);
Value_SMA2.Set(SMA(period )[displace]);
}
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Member
Join Date: Mar 2009
Posts: 56
Thanks: 0
Thanked 0 times in 0 posts
|
Bertrand, thank you for your help.
Now, the indicator works perfectly. Thank you again. Germano |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Syntax for two moving averages | germano | Indicator Development | 4 | 11-04-2009 07:38 AM |
| Displaced moving averages | ggloor | Charting | 6 | 10-11-2009 02:11 AM |
| Three moving averages | germano | Indicator Development | 2 | 07-24-2009 12:39 PM |
| Displaced moving averages | T2020 | Charting | 2 | 01-20-2009 09:13 AM |
| Nested moving averages? | Burga1 | Indicator Development | 2 | 11-16-2007 08:51 AM |