PDA

View Full Version : BarsInProgress / Closes[0][0]


zeller4
07-29-2010, 10:00 AM
Hello,

I'm learning about multiple time frames in strategies.

Add(PeriodType.Minute, 1);

OnBarUpdate

//primary set on 3 min chart
if (BarsInProgress == 1)//set on 1 min chart
{
orderLimitPriceL = Instrument.MasterInstrument.Round2TickSize(Median[1]+2*TickSize);

}

OnBarUpdate, set bool.

if (Closes[0][0] > Opens[0][0]
)
{
Buy = true;
BackColor = Color.White;
}


OnBarUpdate, I want to draw some rays

if (BarsInProgress == 1)
{
if (Buy){ DrawRay("MyRayL", 1, orderLimitPriceL, 0, orderLimitPriceL, Color.Blue,DashStyle.DashDotDot,3);

}


My secondary limitprices don't line up with my drawrays on the primary.
Three questions.
Is the if (BarsInProgress == 1) needed to update the orderLimitPrices?
If I have if(BarsInProgress == 1 && Closes[0][0] > Opens[0][0])
is that going to update every time the secondary bar closes?
If I have if(BarsInProgress == 0 && Closes[0][0] > Opens[0][0]), is there a reduncancy in BarsInProgress with the [0]index of the "Closes"?

Please help with any suggestions.
Best Regards,
Kirk

NinjaTrader_Bertrand
07-29-2010, 10:16 AM
Kirk, correct checking for BIP 1 would filter for OnBarUpdate calls from the secondary series, your 1 min. Best option is to add prints to each BIP section in your code so you see how the sequence of calls unfolds in your script.

BIP just filters for the timing of the OnBarUpdate calls 'listenend' to, with the BarArray index you just point to which bars object data to use at this point in time.

Be also aware that your CalculateOnBarClose setting would apply to all involved series - so to access the 'unfinished' higher timeframe bar in realtime this needs to be set to false.

http://www.ninjatrader.com/support/forum/showthread.php?t=19387

anwar
03-31-2012, 10:35 AM
If bararray is not set for different time period then SMA() reference will always be in 1 minute, right, new here just trying to understand.
Hence bararray[0] is always for 1 minute if Add(PeriodType.Minute is not explicitly invoked.
If I have more than one time period set then BarsInProgress == 0; will process all the bars, right.
thanks in advance.

NinjaTrader_Bertrand
04-02-2012, 02:16 AM
anwar, welcome to our forums - BarsArray[0] is always the primary series, so what you select on your chart for example. The first Add()ed series would be BarsArray[1] then and so on for any other Add()s you do.

If you dont filter code for any BarsInProgress in your OnBarUpdate() > all bars objects would call it.

If you filter for BarsInProgress == 0 > it would always be the primary bars series only.

Easiest is to print the currently called BarsInProgress in your OnBarUpdate() code so you would see the event sequence your scripts runs through in the NT output window.

anwar
04-02-2012, 08:53 PM
Thanks Bertrand, now I understand that.
I had coded a script where I need to just wait for some time like 30 minutes and not do any trading to avoid certain market conditions base on some indicators. Is there any method provided for that I should code to keep a counter to do that.

NinjaTrader_Bertrand
04-03-2012, 02:28 AM
Hi anwar, ok great - do you would like to filter out certain time ranges per default from any script? Then a time filter would make most sense - http://www.ninjatrader.com/support/forum/showthread.php?t=3226

If you like to wait 30 mins after a trigger bar for example, there are several to do it, either run a counter as you indicated or store the Timestamp (Time[0]) / CurrentBar of the reference bar to compare later on.