I want to scan a instrument list and see if any instrument closed outside the bollinger band, meaning close price is>upper band or <lower band. How can I do that? Or do I need some programming work to achieve that? Thanks.
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
Question about Market analyzer
Collapse
X
-
Question about Market analyzer
NT team,
I want to scan a instrument list and see if any instrument closed outside the bollinger band, meaning close price is>upper band or <lower band. How can I do that? Or do I need some programming work to achieve that? Thanks.Tags: None
-
Hello ljiangd,
Thanks for your post.
Yes, this would be possible however it would require custom programming of an indicator to detect the condition and then for the indicator to provide an output that the market analyzer can utilize.
You then add the indicator to the market analyzer by using the indicator column and setting the cell conditions in the market analyzer for that column that reflect the output of the indicator.
You may want to observe this thread for an example: http://ninjatrader.com/support/forum...762#post453762Paul H.NinjaTrader Customer Service
-
Hi Paul,
Based on your video, I made this indicator. But got errors when try to compile. Can you please take a look? Thanks.
//
// Copyright (C) 2016, NinjaTrader LLC <www.ninjatrader.com>.
// NinjaTrader reserves the right to modify or overwrite this NinjaScript component with each release.
//
#region Using declarations
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Gui;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Gui.SuperDom;
using NinjaTrader.Data;
using NinjaTrader.NinjaScript;
using NinjaTrader.Core.FloatingPoint;
using NinjaTrader.NinjaScript.DrawingTools;
#endregion
// This namespace holds indicators in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Indicators
{
/// <summary>
/// Bollinger Bands are plotted at standard deviation levels above and below a moving average.
/// Since standard deviation is a measure of volatility, the bands are self-adjusting:
/// widening during volatile markets and contracting during calmer periods.
/// </summary>
public class BBtest : Indicator
{
private SMA sma;
private StdDev stdDev;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = NinjaTrader.Custom.Resource.NinjaScriptIndicatorDe scriptionBollinger;
Name = BBtest;
IsOverlay = true;
IsSuspendedWhileInactive = true;
NumStdDev = 2;
Period = 14;
AddPlot(Brushes.Goldenrod, "Upper band");
AddPlot(Brushes.Goldenrod, "Middle band");
AddPlot(Brushes.Goldenrod, "Lower band");
AddPlot(Brushes.Transparent, "MAout");
}
else if (State == State.Configure)
{
sma = SMA(Period);
stdDev = StdDev(Period);
}
}
protected override void OnBarUpdate()
{
double sma0 = sma[0];
double stdDev0 = stdDev[0];
Upper[0] = sma0 + NumStdDev * stdDev0;
Middle[0] = sma0;
Lower[0] = sma0 - NumStdDev * stdDev0;
if (Close[0]>Upper[0])
{
MAout[0]=1;
}
else if (Close[0]<lower[0])
{
MAout[0]=-1;
}
else
MAout[0]=0;
}
}
#region Properties
[Browsable(false)]
[XmlIgnore()]
public Series<double> MAout
{
get { return Values[3]; }
}
public Series<double> Lower
{
get { return Values[2]; }
}
[Browsable(false)]
[XmlIgnore()]
public Series<double> Middle
{
get { return Values[1]; }
}
[Range(0, int.MaxValue), NinjaScriptProperty]
[Display(ResourceType = typeof(Custom.Resource), Name = "NumStdDev", GroupName = "NinjaScriptParameters", Order = 0)]
public double NumStdDev
{ get; set; }
[Range(1, int.MaxValue), NinjaScriptProperty]
[Display(ResourceType = typeof(Custom.Resource), Name = "Period", GroupName = "NinjaScriptParameters", Order = 1)]
public int Period
{ get; set; }
[Browsable(false)]
[XmlIgnore()]
public Series<double> Upper
{
get { return Values[0]; }
}
#endregion
}
}
#region NinjaScript generated code. Neither change nor remove.
namespace NinjaTrader.NinjaScript.Indicators
{
public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
{
private BBtest[] cacheBBtest;
public BBtest BBtest(double numStdDev, int period)
{
return BBtest(Input, numStdDev, period);
}
public BBtest BBtest(ISeries<double> input, double numStdDev, int period)
{
if (cacheBBtest != null)
for (int idx = 0; idx < cacheBBtest.Length; idx++)
if (cacheBBtest[idx] != null && cacheBBtest[idx].NumStdDev == numStdDev && cacheBBtest[idx].Period == period && cacheBBtest[idx].EqualsInput(input))
return cacheBBtest[idx];
return CacheIndicator<BBtest>(new BBtest(){ NumStdDev = numStdDev, Period = period }, input, ref cacheBBtest);
}
}
}
namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
{
public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
{
public Indicators.BBtest BBtest(double numStdDev, int period)
{
return indicator.BBtest(Input, numStdDev, period);
}
public Indicators.BBtest BBtest(ISeries<double> input , double numStdDev, int period)
{
return indicator.BBtest(input, numStdDev, period);
}
}
}
namespace NinjaTrader.NinjaScript.Strategies
{
public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
{
public Indicators.BBtest BBtest(double numStdDev, int period)
{
return indicator.BBtest(Input, numStdDev, period);
}
public Indicators.BBtest BBtest(ISeries<double> input , double numStdDev, int period)
{
return indicator.BBtest(input, numStdDev, period);
}
}
}
#endregion
Comment
-
Hello ljiangd,
Thanks for your post.
I've attached your code which compiles and runs here. I did observe that I needed to add [Browsable(false)] & [XmlIgnore()] to the Lower plot in the regions properties. This did not prevent compilation on my end but did expose the property in the UI which was not needed. I commented the lines I added.Attached FilesPaul H.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by stalt, 12-28-2015, 01:36 PM
|
6 responses
1,536 views
0 likes
|
Last Post
by giulyko00
Today, 09:16 AM
|
||
Started by Tburg1073, Today, 08:36 AM
|
0 responses
5 views
0 likes
|
Last Post
by Tburg1073
Today, 08:36 AM
|
||
Started by alexstox, 10-16-2018, 03:29 PM
|
10 responses
333 views
0 likes
|
Last Post
by Tburg1073
Today, 08:32 AM
|
||
Started by smartromain, 03-13-2024, 01:42 AM
|
6 responses
98 views
0 likes
|
Last Post
by smartromain
Today, 08:30 AM
|
||
Started by Jonker, 04-27-2024, 01:19 PM
|
4 responses
29 views
0 likes
|
Last Post
by Jonker
Today, 08:26 AM
|
Comment