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 Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
633 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
364 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
105 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
567 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
568 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment