PDA

View Full Version : Access to historical price in multi instrumets strategy


Czarek
08-07-2009, 02:04 PM
Hello.
Do we have an access to historical prices in to BarsInProgress == 1 instrument??
I would like to GetCurrentBid(); few minutes ago prezent time and I can't get it.
The same code works in BarsInProgress == 0
Rgds
Czarek

NinjaTrader_Austin
08-07-2009, 02:28 PM
Hi Czarek, you sure can access historical prices. Closes[] is an array that holds all close prices, and there are similar arrays for Highs and Lows and everything else. Please see this help guide entry for Closes (http://www.ninjatrader-support.com/HelpGuideV6/Closes.html) to get an idea for how it works.

Keep in mind that GetCurrentBid() is a real-time only function. If you call GetCurrentBid for historical data, it will just return the close price for that bar.

Czarek
08-07-2009, 02:39 PM
I use the wrong word. I do not mean historical data on the back test.
I mean the price in the past durring the open session.
For exaple now is 150000 but i want to get the price 145000 on BarsInProgress == 1 instrument.
Code:
if (BarsInProgress == 0)
{
if (ToTime(Time[0]) <= 145900 && (ToDay(Time[0]) >= 20090807)
{
formerBidNQ = GetCurrentBid();
formerAskNQ = GetCurrentAsk();
}
Does not work, but in BarsInProgress == 0 works
Where the problem could be???
Czarek

NinjaTrader_Austin
08-07-2009, 02:44 PM
Does the code not execute? Is there an error? The code you posted doesn't have anything to do with getting the price at 145000.. I'm not sure I understand what your question is.

Czarek
08-07-2009, 02:51 PM
Sorry, anotherm my mistake.
Code is:
Code:
if (BarsInProgress == 1)
{
if (ToTime(Time[0]) <= 145000 && (ToDay(Time[0]) >= 20090807)
{
formerBidNQ = GetCurrentBid();
formerAskNQ = GetCurrentAsk();
}
Variable formerBidNQ and formerAskNQ = 0; and shows 0 in output window.
The same code, but BarsInProgress == 0 works at the same time.
Czarek

NinjaTrader_Austin
08-07-2009, 02:58 PM
Sorry for not responding with this earlier, but there is an overload for GetCurrentBid (http://www.ninjatrader-support.com/HelpGuideV6/GetCurrentBid.html)/Ask() that includes the BarsInProgress index:

GetCurrentAsk(int barSeriesIndex)


So for your situation, maybe this will work:

formerBidNQ = GetCurrentBid(1);
formerAskNQ = GetCurrentAsk(1);

Czarek
08-07-2009, 03:12 PM
Hi.
Unfortunately GetCurrentBid(1); does not work too. I changed all strategy code under BarsInProgress == 1 with BarsInProgress == 0 and BarsInProgress == 0 works , BarsInProgress == 1 does not.
Czarek.

NinjaTrader_Austin
08-07-2009, 03:23 PM
Czarek, I can't reproduce this on my end. I just whipped up a quick test and everything performs as expected. This is the code I ran:

protected override void Initialize()
{
Add("YM 09-09", PeriodType.Minute, 10);
CalculateOnBarClose = true;
}
protected override void OnBarUpdate()
{
if (BarsInProgress == 1)
{
double bid = GetCurrentBid();
double bid1 = GetCurrentBid(1);
Print("bid:\t" + bid);
Print("bid1:\t" + bid1);
}
}
The output was closing prices, just like it should be:

bid: 9215
bid1: 9215
bid: 9218
bid1: 9218
bid: 9221
bid1: 9221
bid: 9223
bid1: 9223
bid: 9225
...

Czarek
08-08-2009, 12:50 AM
Austin.
Your code works but this is access for current prices I mean in present. I would like to get the price from past. E.g. if now is 140000 i would like to get bid price from 135500. And this is my problem.
Rgds
Czarek

NinjaTrader_Josh
08-10-2009, 07:13 AM
Czarek,

Unfortunately there is no stored historical bid/ask. If you wanted these you would have to store them in your own collection somewhere.