Let me begin by saying that I do not want to annoy anyone and so I have read all of the posts and documentation about programming the intra-bar granularity
I understand the way the bar series is determined is by the first parameter: 0 = primary bars,1 = secondary bars, 2 = tertiary bars, etc. */
However the examples on this forum for Multi-Instrument show functions which are no longer in the current version of NinjaTrader and so I'm confused.
Drawing from the experience of this past explanation let us revisit a EMA crossover example
IsFirstTickOfBar vs OnBarClose for backtest & live - NinjaTrader Support Forum​
AddDataSeries(Data.BarsPeriodType.Tick, 500);
AddDataSeries("ES 06-24",Data.BarsPeriodType.Tick, 500);
AddDataSeries(Data.BarsPeriodType.Tick, 1);
​
AND the last ES 500 tick Bar closes Above/Below the preceding ES 500 tick
Then lastly as is documented we must execute the orders on a the 1 tick Inter-Bar Granularity...
namespace NinjaTrader.NinjaScript.Strategies
{
public class SampleIntrabarBacktest : Strategy
{
private int fast;
private int slow;
protected override void OnStateChange()
{
if(State == State.SetDefaults)
{
Fast = 10;
Slow = 50;
Calculate = Calculate.OnEachTick;
Name = "SampleIntrabarBacktest";
}
else if(State == State.Configure)
{
AddDataSeries(Data.BarsPeriodType.Tick, 500);
AddDataSeries("ES 06-24",Data.BarsPeriodType.Tick, 500);
AddDataSeries(Data.BarsPeriodType.Tick, 1);
// Add two EMA indicators to be plotted on the primary bar series
AddChartIndicator(EMA(Fast));
AddChartIndicator(EMA(Slow));
EMA(Fast).Plots[0].Brush = Brushes.Yellow;
EMA(Slow).Plots[0].Brush = Brushes.Orange;
}
}
protected override void OnBarUpdate()
{
/*
When the OnBarUpdate() is called from the primary bar series, do the following
*/
if (BarsInProgress == 1)
{
/// When the fast EMA crosses above the slow EMA, AND the last ES 500 tick Bar closes Higher than preceding ES 500 tick GO long on the 1 tick InterBar bar series
if ( CrossAbove(EMA(Fast), EMA(Slow), 1) ) //&& Closes[?][1] >= Closes[?][2] ??? Suppose I also wish to see the ES 500 tick does that go here? I am being silly
{
EnterLong(3, 1, "Long: 1 tick InterBar");
}
/// When the fast EMA crosses below the slow EMA, AND the last ES 500 tick Bar closes Higher than preceding ES 500 tick GO short on the 1 tick InterBar bar series
else if ( CrossBelow(EMA(Fast), EMA(Slow), 1) ) //&& Closes[?][1] <= Closes[?][2] ??? Suppose I also wish to see the ES 500 tick does that go here? I am being silly
{
// The entry condition is triggered on the primary bar series, but the order is sent and filled on the 1 tick InterBar,
EnterShort(3, 1, "Short: 1 tick InterBar");
}
}
}​

Comment