Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
How to get SP 500 index in a script?
Collapse
X
-
When using Strategy Analyser. I try backtest the strategy on DOW30 list with periodType.Day. First I try run the backtest without Add() and I get results. But when I adding the line Add() I don't get any results even though I don't even use the added index anywhere in the code. I have compile it and I don't get any errors. Code example, when uncomment Add() the script will stop working:Originally posted by NinjaTrader_RyanM View PostHi hoyje,
Are there any error messages in log tab of control center when you run the strategy? What is not working about it exactly?
Code:protected override void Initialize() { //Add("^SP500", PeriodType.Day, 5000); SetStopLoss("", CalculationMode.Percent, 10, false); CalculateOnBarClose = true; } protected override void OnBarUpdate() { if (IsHighHigherThenHighestHigh) EnterLong(); if (IsLowLowerThenLowestLow) ExitLong(); } private bool IsHighHigherThenHighestHigh { get { return High[0] > MAX(High, 50)[1]; } } private bool IsLowLowerThenLowestLow { get { return Low[0] < MIN(Low, 20)[1]; } }
Comment
-
You're adding a 5000-Day series. Minimum bars required must be satisfied for all series. With the default setting of 20, your strategy would require at least 270 years of historical daily data before it would start taking orders.
If you want to add a 1 day series, this is done with:
Add(PeriodType.Day, 1);Last edited by NinjaTrader_RyanM1; 12-06-2011, 03:00 PM.Ryan M.NinjaTrader Customer Service
Comment
-
Seems to work now. Thanks for the help Ryan!Originally posted by NinjaTrader_RyanM View PostYou're adding a 5000-Day series. Minimum bars required must be satisfied for all series. With the default setting of 20, your strategy would require at least 27 years of historical daily data before it would start taking orders.
If you want to add a 1 day series, this is done with:
Add(PeriodType.Day, 1);
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Hwop38, 05-04-2026, 07:02 PM
|
0 responses
173 views
0 likes
|
Last Post
by Hwop38
05-04-2026, 07:02 PM
|
||
|
Started by CaptainJack, 04-24-2026, 11:07 PM
|
0 responses
328 views
0 likes
|
Last Post
by CaptainJack
04-24-2026, 11:07 PM
|
||
|
Started by Mindset, 04-21-2026, 06:46 AM
|
0 responses
252 views
0 likes
|
Last Post
by Mindset
04-21-2026, 06:46 AM
|
||
|
Started by M4ndoo, 04-20-2026, 05:21 PM
|
0 responses
354 views
0 likes
|
Last Post
by M4ndoo
04-20-2026, 05:21 PM
|
||
|
Started by M4ndoo, 04-19-2026, 05:54 PM
|
0 responses
181 views
0 likes
|
Last Post
by M4ndoo
04-19-2026, 05:54 PM
|

Comment