namespace NinjaTrader.NinjaScript.Indicators
{
public class ATest : Indicator
{
private double YM;
private double NQ;
private double YMDay;
private double NQDay;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Indicator here.";
Name = "ATest";
Calculate = Calculate.OnBarClose;
IsOverlay = false;
DisplayInDataBox = true;
DrawOnPricePanel = true;
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 = true;
AddPlot(Brushes.Orange, "Plot");
YM = 1;
NQ = 1;
YMDay = 1;
NQDay = 1;
}
else if (State == State.Configure)
{
AddDataSeries("YM 09-22", Data.BarsPeriodType.Minute, 1, Data.MarketDataType.Last);
AddDataSeries("NQ 09-22", Data.BarsPeriodType.Minute, 1, Data.MarketDataType.Last);
AddDataSeries("YM 09-22", Data.BarsPeriodType.Day, 1, Data.MarketDataType.Last);
AddDataSeries("NQ 09-22", Data.BarsPeriodType.Day, 1, Data.MarketDataType.Last);
}
}
protected override void OnBarUpdate()
{
if (BarsInProgress != 0)
return;
if (CurrentBars[1] < 1
|| CurrentBars[2] < 1)
return;
// Set 1
if (Closes[1][0] > 0)
{
YM = Closes[1][0];
}
// Set 2
if (Closes[2][0] > 0)
{
NQ = Closes[2][0];
}
// Set 3
if (Closes[3][0] > 0)
{
YMDay = Closes[3][1];
}
// Set 4
if (Closes[4][0] > 0)
{
NQDay = Closes[4][1];
}
double average = (((NQ - NQDay)/NQDay)*100) - (((YM - YMDay)/YMDay) *100);
Plot[0] = average;
}
Comment