Thanks in advance.
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Time Limit Help
Collapse
X
-
Time Limit Help
Hello I'm hoping someone can tell me how to put a time limit on something. For example, if I have an int variable that counts something. I want to reset it back to 0 every 60 seconds.
Thanks in advance.Tags: None
-
Hello 26psicivic,
You can use an integer as a counter that is incremented on every event (like OnBarUpdate() updating).
Below is a link to a forum post that discusses and has sample code.
If you add a 1 minute (or 60 second) series with AddDataSeries you can reset this back to 0 in the BarsInProgress index of that series every 60 seconds.
Chelsea B.NinjaTrader Customer Service
-
I was wanting to know how to use time to reset the integer. I want to only allow a certain amount of time for something to happen.Originally posted by NinjaTrader_ChelseaB View PostHello 26psicivic,
You can use an integer as a counter that is incremented on every event (like OnBarUpdate() updating).
Below is a link to a forum post that discusses and has sample code.
If you add a 1 minute (or 60 second) series with AddDataSeries you can reset this back to 0 in the BarsInProgress index of that series every 60 seconds.
https://ninjatrader.com/support/help...inprogress.htm
Let's try another example. If I have a 2 step entry process where 2 conditions have to be met. When the first condition is met I want to allow 60 seconds for the second condition to be met. If the second condition is met then that will be my entry. If the second condition is not met then it will start over with the first condition.
Comment
-
Hello 26psicivic,
By adding a 60 second series, this would cause OnBarUpdate() to update every 60 seconds (in both historical and realtime).
private bool checkingSecondCondition;
AddDataSeries(BarsPeriodType.Second, 60);
if (BarsInProgress == 0)
{
if (/*first conditions*/)
{
checkingSecondCondition = true;
}
if (checkingSecondCondition == true && /* second conditions /*)
{
// second condition was true within 60 seconds
}
}
else if (BarsInProgress == 1)
{
checkingSecondCondition = false; // reset back to false after 60 seconds
}
You could also add a 1 second series and check that the Time[0].Minute is 0.
If you not interested in this working in historical and having this work in real-time only, you could use a timer.
Chelsea B.NinjaTrader Customer Service
Comment
-
Oh ok, I see what you're saying. Will this still work if I already have other data series?Originally posted by NinjaTrader_ChelseaB View PostHello 26psicivic,
By adding a 60 second series, this would cause OnBarUpdate() to update every 60 seconds (in both historical and realtime).
private bool checkingSecondCondition;
AddDataSeries(BarsPeriodType.Second, 60);
if (BarsInProgress == 0)
{
if (/*first conditions*/)
{
checkingSecondCondition = true;
}
if (checkingSecondCondition == true && /* second conditions /*)
{
// second condition was true within 60 seconds
}
}
else if (BarsInProgress == 1)
{
checkingSecondCondition = false; // reset back to false after 60 seconds
}
You could also add a 1 second series and check that the Time[0].Minute is 0.
If you not interested in this working in historical and having this work in real-time only, you could use a timer.
https://ninjatrader.com/support/foru...445#post496445
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by NullPointStrategies, Today, 05:17 AM
|
0 responses
49 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
126 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
67 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
42 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