PDA

View Full Version : CurrentBar and Multi Time Frame


maxpi
11-27-2007, 10:09 PM
Can I return a value for CurrentBar from an Added Bars object?

NinjaTrader_Josh
11-27-2007, 10:30 PM
Yes. Just do it under the bars context you want.
if (BarsInProgress == 1)
Print(CurrentBar);

xTrader1
07-31-2009, 12:02 PM
Yes. Just do it under the bars context you want.
if (BarsInProgress == 1)
Print(CurrentBar);

I hope you're looking at old threads.
Above doesn't solve my problem. I'm implementing a multi - frame strategy with the same instrument, where Closes[0] are time based, Closes[1] are range.

I have a code snippet in OnBarUpdate:
double d = (Close[0] - Closes[1][0]) / TickSize ;
// Print(TickSize) ;
if (d >= 0)
StrategyPlot(0).Value.Set(d);
else
StrategyPlot(1).Value.Set(d);

I don't see any data on plots. I assume that at the first bars of of series 0 , there is no Closes[1][0] available yet, an exception is thrown and the strategy stops to work.

I may try to use a brute force, at the first lines of OnBarUpdate like :
if ((BarsInProgress == 0) && (CurrentBar <100))
return ;

Assuming that after first 100 time based bars I have a range bar availble, but I really don't like it.

Please advice.

NinjaTrader_Josh
07-31-2009, 12:08 PM
If no bars exist yet you will not be able to access it. I suggest you first start off and just print from within the two BarsInProgress to see what kind of data you have when. Then after you get a feel for the bars then you should be able to access them after they exist.

Also note that StrategyPlot has limited functionality and NT7 will bring about multi-instrument/time frame indicators which will be able to handle plotting.

xTrader1
07-31-2009, 12:27 PM
If no bars exist yet you will not be able to access it. I suggest you first start off and just print from within the two BarsInProgress to see what kind of data you have when. Then after you get a feel for the bars then you should be able to access them after they exist.

Also note that StrategyPlot has limited functionality and NT7 will bring about multi-instrument/time frame indicators which will be able to handle plotting.

Thank a lot for a rocket-fast answer !!! You guessed properly I'm using a multiframe strategy instead of non-existent multiframe indicator.
I don't want to wait for NT7, I'm trying to implement a solution now.

The following doesn't work either, and I think it should :

bar1Ready = false ;
is set in Initialize()
and
.......................
protected override void OnBarUpdate()
{
string sDbg ;
Print("BP , cBar : " + BarsInProgress.ToString() + CurrentBar.ToString()) ;
if (!bar1Ready)
{
return ;
}
if (BarsInProgress == 1)
{
// Print(CurrentBar);
if (CurrentBar > 1)
{
if (!bar1Ready)
bar1Ready = true ;
}
}

double d = (Close[0] - Closes[1][0]) ;
// Print(TickSize) ;
if (d >= 0)
StrategyPlot(0).Value.Set(d);
else
StrategyPlot(1).Value.Set(d);

}
Surprisingly, nothing isn't printed in output window, it means OnBarUpdate fails at the beginning.

Should I implement my own exception mechanism as long as Closes[1][0] is not ready ?

NinjaTrader_Josh
07-31-2009, 12:38 PM
What errors are you receiving? Try using a try-catch block to figure out where you run into issues.
http://www.ninjatrader-support2.com/vb/showthread.php?t=9825

xTrader1
07-31-2009, 12:58 PM
What errors are you receiving? Try using a try-catch block to figure out where you run into issues.
http://www.ninjatrader-support2.com/vb/showthread.php?t=9825

I was an idiot enough to forget about it.

The log says:
31/07/2009 21:33:06,Strategy,The strategy 'SampleMultiInstrument' has called the Add() method with an invalid instrument. Either 'ES 12-08' does not exist in the Instrument Manager or the specified exchange has not been configured.,
31/07/2009 21:32:03,Strategy,The strategy 'SampleMultiInstrument' has called the Add() method with an invalid instrument. Either 'ES 12-08' does not exist in the Instrument Manager or the specified exchange has not been configured.,

Of course, because I'm using a strategy as a substitute to a multiframe indicator, i have no choice, but to use a simulated feed.

So another, may be less stupid question is how to configure a simulated feed to provide a data for my real instrument , $EURUSD instead of ES 12-08. I'm sure it appears somewhere in the help, but I cannot find it.

Above is needed for debugging only. During a real trading, I'm getting a data from MB Trading.
Thanks.

NinjaTrader_Josh
07-31-2009, 01:07 PM
SampleMultiInstrument error is a different error that can be safely ignored. The Simulated Data Feed provides a feed for any instrument setup for it in the Instrument Manager. What you need to do is setup a starting sim price for your instruments and then reconnect to the sim feed to get it flowing.