I just want the indicator to give an arrow up or down as RSI crosses the 50 midline.
It plots OK, but no arrows.
I got the arrow conditions piece from strategy wizard.
The only code difference in the RSI indicator itself is I eliminated plotting the Avg line and overbot/oversold lines. so all I draw is RSI and the 50 midline.
#region Using declarations
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Gui.Chart;
#endregion
// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
/// <summary>
/// The RSI (Relative Strength Index) is a price-following oscillator that ranges between 0 and 100. Input period=14 and a midline=50 and no Avg
/// </summary>
[Description("The RSI (Relative Strength Index) is a price-following oscillator that ranges between 0 and 100. Input period=14 and a midline=50 and no Avg ")]
public class RSImine1 : Indicator
{
#region Variables
// Wizard generated variables
private int RSI = 14; // Default setting for MyInput0
private DataSeries avgUp;
private DataSeries avgDown;
private DataSeries down;
private int period = 14;
private int smooth = 3;
private DataSeries up;
#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.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "RSI"));
Add(new Line(System.Drawing.Color.DarkViolet, 50, "Mid"));
CalculateOnBarClose = false;
avgUp = new DataSeries(this);
avgDown = new DataSeries(this);
down = new DataSeries(this);
up = new DataSeries(this);
PriceTypeSupported = true;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
if (CurrentBar == 0)
{
down.Set(0);
up.Set(0);
return;
}
down.Set(Math.Max(Input[1] - Input[0], 0));
up.Set(Math.Max(Input[0] - Input[1], 0));
if ((CurrentBar + 1) < RSI)
{
if ((CurrentBar + 1) == (RSI - 1))
// Avg.Set(50);
return;
}
if ((CurrentBar + 1) == RSI)
{
// First averages
avgDown.Set(SMA(down, RSI)[0]);
avgUp.Set(SMA(up, RSI)[0]);
}
else
{
// Rest of averages are smoothed
avgDown.Set((avgDown[1] * (RSI - 1) + down[0]) / RSI);
avgUp.Set((avgUp[1] * (RSI - 1) + up[0]) /RSI);
}
double rs = avgUp[0] / (avgDown[0] == 0 ? 1 : avgDown[0]);
double rsi = 100 - (100 / (1 + rs));
//double rsiAvg = (2.0 / (1 + Smooth)) * rsi + (1 - (2.0 / (1 + Smooth))) * Avg[1];
//Avg.Set(rsiAvg);
Value.Set(rsi);
//**********************
// Condition set 1
if (CrossAbove(RSImine(14).Plot0, 50, 1))
{
DrawArrowUp("My up arrow" + CurrentBar, false, 0, 0, Color.Lime);
}
// Condition set 2
if (CrossBelow(RSImine(14).Plot0, 50, 1))
{
DrawArrowDown("My down arrow" + CurrentBar, false, 0, 0, Color.Red);
}
//*************************************
}
#region Properties
[Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
[XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
public DataSeries Plot0
{
get { return Values[0]; }
}
[Description("")]
[Category("Parameters")]
public int MyInput0
{
get { return RSI; }
set { RSI = Math.Max(1, value); }
}
#endregion
}
}
#region NinjaScript generated code. Neither change nor remove.
// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
public partial class Indicator : IndicatorBase
{
private RSImine1[] cacheRSImine1 = null;
private static RSImine1 checkRSImine1 = new RSImine1();
/// <summary>
/// The RSI (Relative Strength Index) is a price-following oscillator that ranges between 0 and 100. Input period=14 and a midline=50 and no Avg
/// </summary>
/// <returns></returns>
public RSImine1 RSImine1(int myInput0)
{
return RSImine1(Input, myInput0);
}
/// <summary>
/// The RSI (Relative Strength Index) is a price-following oscillator that ranges between 0 and 100. Input period=14 and a midline=50 and no Avg
/// </summary>
/// <returns></returns>
public RSImine1 RSImine1(Data.IDataSeries input, int myInput0)
{
checkRSImine1.MyInput0 = myInput0;
myInput0 = checkRSImine1.MyInput0;
if (cacheRSImine1 != null)
for (int idx = 0; idx < cacheRSImine1.Length; idx++)
if (cacheRSImine1[idx].MyInput0 == myInput0 && cacheRSImine1[idx].EqualsInput(input))
return cacheRSImine1[idx];
RSImine1 indicator = new RSImine1();
indicator.BarsRequired = BarsRequired;
indicator.CalculateOnBarClose = CalculateOnBarClose;
indicator.Input = input;
indicator.MyInput0 = myInput0;
indicator.SetUp();
RSImine1[] tmp = new RSImine1[cacheRSImine1 == null ? 1 : cacheRSImine1.Length + 1];
if (cacheRSImine1 != null)
cacheRSImine1.CopyTo(tmp, 0);
tmp[tmp.Length - 1] = indicator;
cacheRSImine1 = tmp;
Indicators.Add(indicator);
return indicator;
}
}
}
// This namespace holds all market analyzer column definitions and is required. Do not change it.
namespace NinjaTrader.MarketAnalyzer
{
public partial class Column : ColumnBase
{
/// <summary>
/// The RSI (Relative Strength Index) is a price-following oscillator that ranges between 0 and 100. Input period=14 and a midline=50 and no Avg
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.RSImine1 RSImine1(int myInput0)
{
return _indicator.RSImine1(Input, myInput0);
}
/// <summary>
/// The RSI (Relative Strength Index) is a price-following oscillator that ranges between 0 and 100. Input period=14 and a midline=50 and no Avg
/// </summary>
/// <returns></returns>
public Indicator.RSImine1 RSImine1(Data.IDataSeries input, int myInput0)
{
return _indicator.RSImine1(input, myInput0);
}
}
}
// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
public partial class Strategy : StrategyBase
{
/// <summary>
/// The RSI (Relative Strength Index) is a price-following oscillator that ranges between 0 and 100. Input period=14 and a midline=50 and no Avg
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.RSImine1 RSImine1(int myInput0)
{
return _indicator.RSImine1(Input, myInput0);
}
/// <summary>
/// The RSI (Relative Strength Index) is a price-following oscillator that ranges between 0 and 100. Input period=14 and a midline=50 and no Avg
/// </summary>
/// <returns></returns>
public Indicator.RSImine1 RSImine1(Data.IDataSeries input, int myInput0)
{
if (InInitialize && input == null)
throw new ArgumentException("You only can access an indicator with the default input/bar series from within the 'Initialize()' method");
return _indicator.RSImine1(input, myInput0);
}
}
}
#endregion

Comment