void limites(){
//definir suelo i techo
barsRequest = new BarsRequest(Cbi.Instrument.GetInstrument("ES 6-20"), DateTime.Now.AddDays(-1), DateTime.Now);
// Parametrize your request.
barsRequest.BarsPeriod = new BarsPeriod { BarsPeriodType = BarsPeriodType.Minute, Value = 1440 };
barsRequest.TradingHours = TradingHours.Get("Default 24 x 7");
//debbug
if(barsRequest==null){Print("no esta bien hecha la request de vars pasadas");}
//request
[COLOR=#FF0000]barsRequest.Request(new Action<BarsRequest, ErrorCode, string>((bars, errorCode, errorMessage)[/COLOR] =>
{
Print("no hay error aqui");
if (errorCode != ErrorCode.NoError)
{
// Handle any errors in requesting bars here
NinjaTrader.Code.Output.Process(string.Format("Error on requesting bars: {0}, {1}",
errorCode, errorMessage), PrintTo.OutputTab1);
return;
}
//debbug
//Print("bars: " + bars.Bars.Count);
for (int i = 0; i < bars.Bars.Count; i++)
{
if(bars.Bars.GetHigh(i)>techo){ //calculo techo con RANGO=X
techo=bars.Bars.GetHigh(i);
}
if(bars.Bars.GetLow(i)<suelo){ //calculo suelo con RANGO=X
suelo=bars.Bars.GetLow(i);
}
}
}));
Print("Techo definido en: " + techo + ", suelo definido en: " + suelo);
}
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Error using barsRequest.Request()
Collapse
X
-
Error using barsRequest.Request()
I'm having trouble geting this code to work. The error says a null reference in the red line. But I can't seem to find what I'm missing. I'll explain what I'm doing in case that what I'm doing is also incorrect. I'm trying to get the past day info and then check for max and min values to define supports and resistances. I'm doing that with the request method from BarsRequest and then iterating the bars requested.
I'm also attaching a photo from the debbuger.Code:1 PhotoTags: None
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by CarlTrading, 03-31-2026, 09:41 PM
|
1 response
77 views
1 like
|
Last Post
|
||
|
Started by CarlTrading, 04-01-2026, 02:41 AM
|
0 responses
40 views
0 likes
|
Last Post
by CarlTrading
04-01-2026, 02:41 AM
|
||
|
Started by CaptainJack, 03-31-2026, 11:44 PM
|
0 responses
63 views
2 likes
|
Last Post
by CaptainJack
03-31-2026, 11:44 PM
|
||
|
Started by CarlTrading, 03-30-2026, 11:51 AM
|
0 responses
63 views
0 likes
|
Last Post
by CarlTrading
03-30-2026, 11:51 AM
|
||
|
Started by CarlTrading, 03-30-2026, 11:48 AM
|
0 responses
53 views
0 likes
|
Last Post
by CarlTrading
03-30-2026, 11:48 AM
|

Comment