Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
stoping trading on the first five days of my script
Collapse
X
-
Hello dafonseca,
Thank you for the post.
If you know how many bars that is for the series you are using you could use the CurrentBar in a condition. What series is being used?
Here is a simple example assuming the series was Daily bars:
This could also be accomplished in other ways depending on the overall goal, if you simply want to return for 5 days worth of data using the current bar is likely the most simple way.Code:if(CurrentBar < 5) return;
I look forward to being of further assistance.
-
the problem is I am using 1 min bars, but i have to get theses:
if(ToTime(Time[0])== ToTime(9, 31, 00) || ToTime(Time[0])== ToTime(9, 34, 00))
{
if (BarsInProgress == 1)
{
priorClosePrice = PriorDayOHLC().PriorClose[0];
priorClosePrice1 = PriorDayOHLC().PriorClose[1];
priorClosePrice2 = PriorDayOHLC().PriorClose[2];
priorClosePrice3 = PriorDayOHLC().PriorClose[3];
priorClosePrice4 = PriorDayOHLC().PriorClose[4];
priorClosePrice5 = PriorDayOHLC().PriorClose[5];
}
}
when i run the strtegy the log shows an error since on the first day there are 4 days out of range, What i need is RETURN until the fifth day
Comment
-
Hello dafonseca,
What is the primary that you are using? You may be able to account for this by checking that the primary has enough data before running this code, I would otherwise need that detail to know how to proceed here.
For multi series scripts you can do the following to prevent it from doing anything before enough bars are available, this would help if your primary was a daily as an example:
if(CurrentBars[0] < 5 || CurrentBars[1] < 5) return;
If you need 5 days of minute bars you may need to do 1440 * 5 to get a count for that.
I look forward to being of further assistance.
Comment
-
Hi dafonseca,
To determine, if you have a new day, you could compare the date of the current bar with the date of the previous bar. If they are not the same, you have a new day.
If you have a new day, increase a dayCounter int by one.
For one dataseries: If (Time[0].Date != Time[1].Date] ) { dayCounter = dayCounter+1 } else { no change }
For >1 dataseries use Times. Example (still looking at the primary series): If[Times[0][0].Date =! Times[0][1].Date ) { see above}
As long as the dayCounter is less than 5, return. Only if it is greater or equal to five, run the rest of your code including setting your variables.
NT-Roland
P.S.: If you like my suggestion for "Preload bars" please kindly vote for it. Could be so easy to ensure everything is up and running immediately after starting or restarting a strategy.
Dear Experts, Can I preload a certain number of bars to ensure custom indicators used in the strategy are already up and running correctly when the strategy
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by NullPointStrategies, Today, 05:17 AM
|
0 responses
38 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
124 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
64 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
41 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
46 views
0 likes
|
Last Post
|
Comment