I am trying to accomplish something very simple in NinjaScript. I'm simply trying to calculate two 5 minute EMAs and have them plotted on a 1 minute chart. For some reason, only the 1minute versions of the indicators are showing. The strategy only runs on a 1 minute chart, but I need the 5 minute ema values plotted.
Any idea what I'm doing wrong?
//This namespace holds Strategies in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Strategies
{
public class OverlayedIndicatorStategy : Strategy
{
private EMA emaFast;
private EMA emaSlow;
enum TradeDirection {
NONE, LONG, SHORT
}
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Overlayed Indicator Test Strategy";
Name = "Overlayed Indicators Test";
Calculate = Calculate.OnBarClose;
EntriesPerDirection = 1;
EntryHandling = EntryHandling.AllEntries;
IsExitOnSessionCloseStrategy = true;
ExitOnSessionCloseSeconds = 30;
IsFillLimitOnTouch = false;
MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
OrderFillResolution = OrderFillResolution.Standard;
Slippage = 0;
StartBehavior = StartBehavior.WaitUntilFlat;
TimeInForce = TimeInForce.Gtc;
TraceOrders = false;
RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
StopTargetHandling = StopTargetHandling.PerEntryExecution;
BarsRequiredToTrade = 20;
Fast = 72;
Slow = 89;
// Disable this property for performance gains in Strategy Analyzer optimizations
// See the Help Guide for additional information
IsInstantiatedOnEachOptimizationIteration = true;
}
else if (State == State.Configure)
{
AddDataSeries(null, BarsPeriodType.Tick, 1);
AddDataSeries(null, BarsPeriodType.Minute, 5);
// Make sure EMAs are calculated based on 5 minute data
emaFast = EMA(BarsArray[2], Fast);
emaSlow = EMA(BarsArray[2], Slow);
}
else if (State == State.DataLoaded)
{
emaFast.Plots[0].Brush = Brushes.White;
emaFast.Plots[0].PlotStyle = PlotStyle.TriangleUp;
emaSlow.Plots[0].Brush = Brushes.White;
emaSlow.Plots[0].PlotStyle = PlotStyle.TriangleDown;
AddChartIndicator(emaFast);
AddChartIndicator(emaSlow);
}
}
protected override void OnBarUpdate()
{
if (CurrentBars[0] < BarsRequiredToTrade)
/return;
// 5 minute bar logic
if(BarsInProgress == 2){
Draw.Region(this, "emaCloud", 0, CurrentBar, emaFast, emaSlow, Brushes.Transparent, Brushes.Purple, 75, 0);
}
// 1 minute bar logic
if(BarsInProgress == 0){
bool isNewDay = BarsArray[0].IsFirstBarOfSession;
if (isNewDay){
Print("NEW DAY: " + Time[0]);
numTradesTaken = 0;
}
}
}
}
}

Comment