......
// 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
No announcement yet.
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
-
Wait a sec! [0] should be "UpperStdDev", because it is first in "protected override void OnBarUpdate()"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:
In order to current this, please add the following to the beginning of OnBarUpdate1/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.
This will ensure you can calculate your highest index value (Value[3]).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
-
Can you comment everything here? I mean what row for what etc.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 Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
574 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
333 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
101 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
553 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
551 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment