protected override void OnBarUpdate()
{
if (CurrentBars[0] < 55 || CurrentBars[1] < 4) return;
NinjaTrader.Gui.Tools.SimpleFont myFont = new NinjaTrader.Gui.Tools.SimpleFont("Courier New", 12) { Size = 12, Bold = true };
if (BarsInProgress == 0)
{
// Draw.TextFixed(this, "tag1", "The current expiry is " + Bars.Instrument.MasterInstrument.GetNextExpiry(Dat eTime.Now).ToString("MM-yy"), TextPosition.BottomRight);
Instrument Gold = Instrument.GetInstrument("GC");
string goldExpiry = Gold.MasterInstrument.GetNextExpiry(DateTime.Now). ToString("MM-yy");
Draw.TextFixed(this, "tag1", "The current expiry is1 " + goldExpiry, TextPosition.BottomLeft);
in
#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 DailyRanges : Indicator
{
private Series<double> CLSeries;
private Series<double> ESSeries;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Indicator here.";
Name = "DailyRanges";
Calculate = Calculate.OnBarClose;
IsOverlay = true;
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;
}
else if (State == State.Configure)
{
// Instrument Gold = Instrument.GetInstrument("GC");
// AddDataSeries("GC "+Gold.MasterInstrument.GetNextExpiry(DateTime.Now ).ToString("MM-yy"), BarsPeriodType.Day, 1);
AddDataSeries("CL 05-22", BarsPeriodType.Day, 1);
AddDataSeries("ES 06-22", BarsPeriodType.Day, 1);
}
else if (State == State.DataLoaded)
{
CLSeries = new Series<double>(this, MaximumBarsLookBack.Infinite);
ESSeries = new Series<double>(this, MaximumBarsLookBack.Infinite);
}
}
protected override void OnBarUpdate()
{
if (CurrentBars[0] < 55 || CurrentBars[1] < 4) return;
NinjaTrader.Gui.Tools.SimpleFont myFont = new NinjaTrader.Gui.Tools.SimpleFont("Courier New", 12) { Size = 12, Bold = true };
if (BarsInProgress == 0)
{
// Draw.TextFixed(this, "tag1", "The current expiry is " + Bars.Instrument.MasterInstrument.GetNextExpiry(Dat eTime.Now).ToString("MM-yy"), TextPosition.BottomRight);
Instrument Gold = Instrument.GetInstrument("GC");
string goldExpiry = Gold.MasterInstrument.GetNextExpiry(DateTime.Now). ToString("MM-yy");
Draw.TextFixed(this, "tag1", "The current expiry is1 " + goldExpiry, TextPosition.BottomLeft);
CLSeries[0] = Highs[1][0]-Lows[1][0];
Draw.TextFixed(
this,
"GCSeries",
"GC DRange: "+CLSeries[0],
TextPosition.TopRight,
Brushes.White,
myFont,
Brushes.Transparent,
Brushes.Transparent,
0);
ESSeries[0] = Highs[2][0]-Lows[2][0];
Draw.TextFixed(
this,
"ESSeries",
new String('\n', 1)+"ES DRange: "+Instrument.MasterInstrument.RoundToTickSize(ESSe ries[0] / TickSize),
TextPosition.TopRight,
Brushes.White,
myFont,
Brushes.Transparent,
Brushes.Transparent,
0);
}
}
}
}
#region NinjaScript generated code. Neither change nor remove.
namespace NinjaTrader.NinjaScript.Indicators
{
public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
{
private DailyRanges[] cacheDailyRanges;
public DailyRanges DailyRanges()
{
return DailyRanges(Input);
}
public DailyRanges DailyRanges(ISeries<double> input)
{
if (cacheDailyRanges != null)
for (int idx = 0; idx < cacheDailyRanges.Length; idx++)
if (cacheDailyRanges[idx] != null && cacheDailyRanges[idx].EqualsInput(input))
return cacheDailyRanges[idx];
return CacheIndicator<DailyRanges>(new DailyRanges(), input, ref cacheDailyRanges);
}
}
}
namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
{
public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
{
public Indicators.DailyRanges DailyRanges()
{
return indicator.DailyRanges(Input);
}
public Indicators.DailyRanges DailyRanges(ISeries<double> input )
{
return indicator.DailyRanges(input);
}
}
}
namespace NinjaTrader.NinjaScript.Strategies
{
public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
{
public Indicators.DailyRanges DailyRanges()
{
return indicator.DailyRanges(Input);
}
public Indicators.DailyRanges DailyRanges(ISeries<double> input )
{
return indicator.DailyRanges(input);
}
}
}
#endregion
and it still return 03-22 instead of 04-22 (on GC 04-22 1 min chart) on the BottomLeft Chart corner.
How to make it return the correct 04-22 value? Thanks!
Comment