PDA

View Full Version : BarsArray Intrabar Synchronization


whitmark
06-27-2007, 05:08 AM
I am looking to place orders on the primary bar series (5 min) yet take trading signals based on the most recent secondary higher timeframe bar series (30 min) values and indicator conditions. I also wanted to use an assigned dataseries to enable flexibility in selecting the moving average indicator I use as specified in a parameter setting. Please see the sample code and questions below:


private DataSeries ExitMAfast;
private DataSeries ExitMAslow;

protected override void Initialize()
{
ExitMAfast = new DataSeries(this);
ExitMAslow = new DataSeries(this)
}

protected override void OnBarUpdate()
{
if (BarsInProgress == 1)
{
If (MovingAverageType == 1)
{
ExitMAfast.Set(EMA(exitMAPeriodFast)[0]);
ExitMAslow.Set(EMA(exitMAPeriodSlow)[0]);
}
else
{
ExitMAfast.Set(HMA(exitMAPeriodFast)[0]);
ExitMAslow.Set(HMA(exitMAPeriodSlow)[0]);
}
}
if (BarsInProgress == 0)
{
...
if (Position.MarketPosition == MarketPosition.Long &&
CrossBelow(ExitMAfast, ExitMASlow, 1))
{
ExitLong();
}
...
}
}


While backtesting in OnBarClose mode, if there is a primary bar (5 min) close event and there is a secondary bar (30 min) intra-bar moving average crossover condition, I would like to initiate a exit trading signal. In other words, after three 5 minute primary bars have printed, can you also determine the intra-bar value halfway through the 30 minute secondary bar, as well as any indicator values that have been defined on that secondary bar (BarsArray[1])?
-

How does this answer differ for real-time vs backtesting and OnTickClose vs OnBarClose?
-

As you can see in the code, I am trying to use a dataseries to selectively assign the indicator values for the higher time frame indicators while BarsInProgress = 1 so that I can use these values to initiate a trading signal (Exit) when BarsInProgress = 0. This approach doesn't seem to work and its unclear whether a private dataseries cannot be used in this manner or its a limitation with the CrossAbove/Below functions. Any suggestions?


The true event based multiple-instrument/timeframe functionality is a very compelling and useful feature . . . thanks for being ahead of the curve on this.

Regards,

Whitmark

NinjaTrader_Ray
06-27-2007, 07:53 AM
1) No, since there is no concept of intrabar values in a backtest. The resolution is ALWAYS at the bar level thus, you will always see the last bar closed.

2) If you run with CalculateOnBarClose == false in real-time, you will always be pointing to the current bar in formation, thus you can see the intrabar value on the secondary series.

3) This approach is no different that accessing the indicator values directly since all you are doing is saving the value of the last bar close.

whitmark
06-27-2007, 08:10 AM
Thanks, Ray, for the timely response . . . it helps confirm what I was expecting.