Announcement
Collapse
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
Partner 728x90
Collapse
NinjaTrader
How to get SP 500 index in a script?
Collapse
X
-
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
-
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 guillembm, Yesterday, 11:25 AM
|
2 responses
9 views
0 likes
|
Last Post
by guillembm
Yesterday, 11:58 PM
|
||
Started by junkone, 04-21-2024, 07:17 AM
|
9 responses
68 views
0 likes
|
Last Post
by jeronymite
Yesterday, 11:51 PM
|
||
Started by trilliantrader, 04-18-2024, 08:16 AM
|
4 responses
20 views
0 likes
|
Last Post Yesterday, 10:33 PM | ||
Started by mgco4you, Yesterday, 09:46 PM
|
1 response
11 views
0 likes
|
Last Post Yesterday, 09:56 PM | ||
Started by wzgy0920, Yesterday, 09:53 PM
|
0 responses
10 views
0 likes
|
Last Post
by wzgy0920
Yesterday, 09:53 PM
|
Comment