Indicator:
namespace NinjaTrader.NinjaScript.Indicators.Nic
{
public class IntradayLevels : Indicator
{
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Nic Intraday Levels";
Name = "Intraday Levels";
Calculate = Calculate.OnBarClose;
IsOverlay = true;
DisplayInDataBox = true;
DrawOnPricePanel = true;
}
else if (State == State.Configure)
{
}
}
protected override void OnBarUpdate()
{
base.OnBarUpdate();
if (Bars == null)
return;
Print("Have Bars");
}
}
}
namespace NinjaTrader.NinjaScript.Indicators
{
public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
{
IntradayLevels[] _IntradayLevels;
public IntradayLevels GetIntradayLevels(ISeries<double> input)
{
if (_IntradayLevels != null)
for (int idx = 0; idx < _IntradayLevels.Length; idx++)
if (_IntradayLevels[idx] != null && _IntradayLevels[idx].EqualsInput(Input))
return _IntradayLevels[idx];
return CacheIndicator<IntradayLevels>(new IntradayLevels(), input, ref _IntradayLevels);
}
}
}
namespace NinjaTrader.NinjaScript.Strategies
{
public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
{
IntradayLevels[] _IntradayLevels;
public IntradayLevels GetIntradayLevels()
{
return indicator.GetIntradayLevels(Input);
}
}
}
Strategy :
namespace NinjaTrader.NinjaScript.Strategies.Nic
{
public class IntradayLevelsStrat : Strategy
{
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Strategy here.";
Name = "Nic IntradayLevelsStrat";
Calculate = Calculate.OnBarClose;
EntriesPerDirection = 1;
EntryHandling = EntryHandling.AllEntries;
IsExitOnSessionCloseStrategy = true;
ExitOnSessionCloseSeconds = 30;
IsFillLimitOnTouch = false;
MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
OrderFillResolution = OrderFillResolution.Standard;
Slippage = 1;
StartBehavior = StartBehavior.WaitUntilFlat;
TimeInForce = TimeInForce.Gtd;
TraceOrders = false;
RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
StopTargetHandling = StopTargetHandling.PerEntryExecution;
BarsRequiredToTrade = 2;
// Disable this property for performance gains in Strategy Analyzer optimizations
// See the Help Guide for additional information
IsInstantiatedOnEachOptimizationIteration = true;
}
else if (State == State.Configure)
{
Levels = GetIntradayLevels();
}
else if (State == State.DataLoaded)
{
AddChartIndicator(Levels);
}
}
}
}
- Why is Indicator.Bars null when I load the strategy?
- Do I need to include the boilerplate "Get Indicator" caching code? Can I just new() an instance?
- What variables are available and not available ?
- Is there another way to get the bars property?


Comment