...... // This namespace holds all indicators and is required. Do not change it. namespace NinjaTrader.Indicator { /// <summary> /// LWMPind is plotted at standard deviation levels and average true range levels above and below a open (close) price. /// </summary> [Description("LWMPind is plotted at standard deviation levels and average true range levels above and below a open (close) price.")] public class LWMPind : Indicator { #region Variables private double numStdDev = 1; private int period = 360; #endregion /// <summary> /// This method is used to configure the indicator and is called once before any bar data is loaded. /// </summary> protected override void Initialize() { Add(new Plot(Color.Green, "Upper ATR")); Add(new Plot(Color.Orange, "Upper band")); Add(new Plot(Color.Orange, "Lower band")); Add(new Plot(Color.Red, "Lower ATR")); Overlay = true; } /// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { double stdDevValue = StdDev(Period)[0]; UpperStdDev.Set(Open[0] + NumStdDev * stdDevValue); LowerStdDev.Set(Open[0] - NumStdDev * stdDevValue); if (CurrentBar == 0) Value.Set(High[0] - Low[0]); else { double trueRange = High[0] - Low[0]; trueRange = Math.Max(Math.Abs(Low[0] - Close[1]), Math.Max(trueRange, Math.Abs(High[0] - Close[1]))); Value.Set(((Math.Min(CurrentBar + 1, Period) - 1 ) * Value[1] + trueRange) / Math.Min(CurrentBar + 1, Period)); } [COLOR="Red"][B] UpperATR.Set(Open[0]+Value.Set); LowerATR.Set(Open[0]-Value.Set);[/B][/COLOR] } #region Properties /// <summary> /// Gets the upperStdDev value. /// </summary> [Browsable(false)] [XmlIgnore()] public DataSeries UpperStdDev { get { return Values[0]; } } /// <summary> /// Get the lowerStdDev value. /// </summary> [Browsable(false)] [XmlIgnore()] public DataSeries LowerStdDev { get { return Values[1]; } } /// <summary> /// </summary> [Description("Number of standard deviations")] [GridCategory("Parameters")] [Gui.Design.DisplayNameAttribute("# of std. dev.")] public double NumStdDev { get { return numStdDev; } set { numStdDev = Math.Max(0, value); } } /// <summary> /// </summary> [Description("Numbers of bars used for calculations")] [GridCategory("Parameters")] public int Period { get { return period; } set { period = Math.Max(1, value); } } /// <summary> /// Get the upperATR value. /// </summary> [Browsable(false)] [XmlIgnore()] public DataSeries UpperATR { get { return Values[3]; } } /// <summary> /// Get the lowerATR value. /// </summary> [Browsable(false)] [XmlIgnore()] public DataSeries LowerATR { get { return Values[4]; } } #endregion } }
Announcement
Collapse
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
Partner 728x90
Collapse
NinjaTrader
ATR and StdDev upper and lower
Collapse
X
-
ATR and StdDev upper and lower
Hello. Please look at script for indicator. Errors said that "+" and "-" can't be used in bold red area.
Code:Tags: None
-
Originally posted by NinjaTrader_Joydeep View PostHello alexstox,
Value[0] will return you the current value of the first plot ("Upper ATR").
OR it first because of "protected override void Initialize()" first place?
Oh my God! If second is true, there are many mistakes in "#region Properties":
for example
/// <summary>
/// Gets the upperStdDev value.
/// </summary>
[Browsable(false)]
[XmlIgnore()]
public DataSeries UpperStdDev
{
get { return Values[0]; }
}
should be "return Values[1]".
Comment
-
Hello alexstox,
The Values are referred as per the plot values
Code:Add(new Plot(Color.Green, "Upper ATR")); //Values[0] Add(new Plot(Color.Orange, "Upper band")); //values[1] Add(new Plot(Color.Orange, "Lower band")); //Values[2] Add(new Plot(Color.Red, "Lower ATR")); //Values[3]
JoydeepNinjaTrader Customer Service
Comment
-
So, right version will be
Code:...... // This namespace holds all indicators and is required. Do not change it. namespace NinjaTrader.Indicator { /// <summary> /// LWMPind is plotted at standard deviation levels and average true range levels above and below a open (close) price. /// </summary> [Description("LWMPind is plotted at standard deviation levels and average true range levels above and below a open (close) price.")] public class LWMPind : Indicator { #region Variables private double numStdDev = 1; private int period = 360; #endregion /// <summary> /// This method is used to configure the indicator and is called once before any bar data is loaded. /// </summary> protected override void Initialize() { Add(new Plot(Color.Green, "Upper ATR")); Add(new Plot(Color.Orange, "Upper band")); Add(new Plot(Color.Orange, "Lower band")); Add(new Plot(Color.Red, "Lower ATR")); Overlay = true; } /// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { double stdDevValue = StdDev(Period)[0]; UpperStdDev.Set(Open[0] + NumStdDev * stdDevValue); LowerStdDev.Set(Open[0] - NumStdDev * stdDevValue); if (CurrentBar == 0) Value.Set(High[0] - Low[0]); else { double trueRange = High[0] - Low[0]; trueRange = Math.Max(Math.Abs(Low[0] - Close[1]), Math.Max(trueRange, Math.Abs(High[0] - Close[1]))); Value.Set(((Math.Min(CurrentBar + 1, Period) - 1 ) * Value[1] + trueRange) / Math.Min(CurrentBar + 1, Period)); } UpperATR.Set(Open[0]+Value[B][COLOR="SeaGreen"][0][/COLOR][/B]); LowerATR.Set(Open[0]-Value[B][COLOR="seagreen"][3][/COLOR][/B]); } #region Properties /// <summary> /// Gets the upperStdDev value. /// </summary> [Browsable(false)] [XmlIgnore()] public DataSeries UpperStdDev { get { return Values[B][COLOR="seagreen"][1][/COLOR][/B]; } } /// <summary> /// Get the lowerStdDev value. /// </summary> [Browsable(false)] [XmlIgnore()] public DataSeries LowerStdDev { get { return Values[B][COLOR="seagreen"][2][/COLOR][/B]; } } /// <summary> /// </summary> [Description("Number of standard deviations")] [GridCategory("Parameters")] [Gui.Design.DisplayNameAttribute("# of std. dev.")] public double NumStdDev { get { return numStdDev; } set { numStdDev = Math.Max(0, value); } } /// <summary> /// </summary> [Description("Numbers of bars used for calculations")] [GridCategory("Parameters")] public int Period { get { return period; } set { period = Math.Max(1, value); } } /// <summary> /// Get the upperATR value. /// </summary> [Browsable(false)] [XmlIgnore()] public DataSeries UpperATR { get { return Values[B][COLOR="seagreen"][0][/COLOR][/B]; } } /// <summary> /// Get the lowerATR value. /// </summary> [Browsable(false)] [XmlIgnore()] public DataSeries LowerATR { get { return Values[B][COLOR="seagreen"][3][/COLOR][/B]; } } #endregion } }
Comment
-
There was a run time error which was preventing this from loading. You can check for these on the Log tab of the Control Center:
1/29/2013 2:06:09 PM|3|4|Error on calling 'OnBarUpdate' method for indicator 'LWMPind' on bar 0: You are accessing an index with a value that is invalid since its out of range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.
Code:protected override void OnBarUpdate() { [B] if(CurrentBar < 3) return;[/B]
MatthewNinjaTrader Product Management
Comment
-
Comment
-
Let me explain: as result I need 2 lines above chart bars (price) and 2 lines under price: 2 upper lines should be ATR and Standard Deviation, 2 lower lines the same. So, it should look like Bollinger ind, but this lines should be built not from moving average but from bar Open price. For example, today's bar Open=80, StdDev=5, ATR=7, so upper ATR line = Open+ATR, upper StdDev line = Open + StdDev, lower ATR line = Open - ATR, lower StdDev line = Open - StdDev.
Comment
-
Originally posted by NinjaTrader_Joydeep View PostHello alexstox,
Please refer to this indicator which draws a line based on the ATR above the price bar.
http://ninjatrader.com/support/forum...tid=-1&lpage=1
Of course you can't, because support is really busy here.
But do you have some example of big indicator (big is with many rows,values,variables), where a lot of comments "for dummies"?
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by lorem, Yesterday, 09:18 AM
|
4 responses
13 views
0 likes
|
Last Post
by lorem
Today, 12:17 PM
|
||
Started by Spiderbird, Today, 12:15 PM
|
0 responses
5 views
0 likes
|
Last Post
by Spiderbird
Today, 12:15 PM
|
||
Started by cmtjoancolmenero, Yesterday, 03:58 PM
|
12 responses
42 views
0 likes
|
Last Post Today, 12:09 PM | ||
Started by FrazMann, Today, 11:21 AM
|
0 responses
6 views
0 likes
|
Last Post
by FrazMann
Today, 11:21 AM
|
||
Started by geddyisodin, Yesterday, 05:20 AM
|
8 responses
52 views
0 likes
|
Last Post Today, 10:45 AM |
Comment