I'm mainly doing this to implement on a strategy since i can't figure out how to call the lowest RSi value from the past 50 bars in my strategey. If you know how to do it and what is the lines of code for that i would appreciate the help.
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.Gui.Tools;
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
{
public class RSIExtremes1 : Indicator
{
private Series<double> DataSeries;
private Series<double> lowestRSI;
private Series<double> highestRSI;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Indicator here.";
Name = "RSIExtremes1";
Calculate = Calculate.OnBarClose;
IsOverlay = false;
DisplayInDataBox = true;
DrawOnPricePanel = false;
DrawHorizontalGridLines = true;
DrawVerticalGridLines = true;
PaintPriceMarkers = true;
ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
//Disable this property if your indicator requires custom values that cumulate with each new market data event.
//See Help Guide for additional information.
IsSuspendedWhileInactive = false;
Period = 10;
Period_RSI = 10;
AddPlot(Brushes.Red, "Lowest");
AddPlot(Brushes.DarkGreen, "Highest");
}
else if (State == State.DataLoaded)
{
DataSeries = new Series<double>(this);
lowestRSI = new Series<double>(this);
highestRSI = new Series<double>(this);
}
}
protected override void OnBarUpdate()
{
Print("Lowest RSI: " + lowestRSI[0]); // Print RSI value
//Add your custom indicator logic here.
if (CurrentBar < Period)
return;
double lowest = double.MaxValue;
double highest = double.MinValue;
lowest = 100;
highest = 0;
for (int i = 0; i < Period; i++)
{
double rsiValue = RSI(Period_RSI,1)[i];
if (rsiValue < lowest)
{
lowest = rsiValue;
}
if (rsiValue > highest)
{
highest = rsiValue;
}
}
lowestRSI[0] = lowest;
highestRSI[0] = highest;
}
region Properties
[NinjaScriptProperty]
[Range(1, int.MaxValue)]
[Display(Name="Period", Order=1, GroupName="Parameters")]
public int Period
{ get; set; }
[NinjaScriptProperty]
[Range(1, int.MaxValue)]
[Display(Name="Period_RSI", Order=2, GroupName="Parameters")]
public int Period_RSI
{ get; set; }
[Browsable(false)]
[XmlIgnore]
public Series<double> lowest
{
get { return Values[0]; }
}
[Browsable(false)]
[XmlIgnore]
public Series<double> highest
{
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 RSIExtremes1[] cacheRSIExtremes1;
public RSIExtremes1 RSIExtremes1(int period, int period_RSI)
{
return RSIExtremes1(Input, period, period_RSI);
}
public RSIExtremes1 RSIExtremes1(ISeries<double> input, int period, int period_RSI)
{
if (cacheRSIExtremes1 != null)
for (int idx = 0; idx < cacheRSIExtremes1.Length; idx++)
if (cacheRSIExtremes1[idx] != null && cacheRSIExtremes1[idx].Period == period && cacheRSIExtremes1[idx].Period_RSI == period_RSI && cacheRSIExtremes1[idx].EqualsInput(input))
return cacheRSIExtremes1[idx];
return CacheIndicator<RSIExtremes1>(new RSIExtremes1(){ Period = period, Period_RSI = period_RSI }, input, ref cacheRSIExtremes1);
}
}
}
namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
{
public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
{
public Indicators.RSIExtremes1 RSIExtremes1(int period, int period_RSI)
{
return indicator.RSIExtremes1(Input, period, period_RSI);
}
public Indicators.RSIExtremes1 RSIExtremes1(ISeries<double> input , int period, int period_RSI)
{
return indicator.RSIExtremes1(input, period, period_RSI);
}
}
}
namespace NinjaTrader.NinjaScript.Strategies
{
public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
{
public Indicators.RSIExtremes1 RSIExtremes1(int period, int period_RSI)
{
return indicator.RSIExtremes1(Input, period, period_RSI);
}
public Indicators.RSIExtremes1 RSIExtremes1(ISeries<double> input , int period, int period_RSI)
{
return indicator.RSIExtremes1(input, period, period_RSI);
}
}
}
#endregion
Comment