Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Limit number of bars to retrieve on a chart
Collapse
X
-
Limit number of bars to retrieve on a chart
I have an opening range indicator I am developing and need to restrict it to the current day. If I put it on a 5 day chart it computes all 5 day opening ranges and uses lots of computing power. What do I need to put in my code to limit that to just the current day regardless if I have a 5, 10 day chart ? When I limit the data to a one day chart all is good.Tags: None
-
Hi set2win, thanks for posting.
We have the SessionIterator class for this purpose:
On the page, you will find a short example. On the first bar of the session calculate the trading session. If the session is today's session you can begin to process the indicator, otherwise return from OnBarUpdate.
Kind regards,
-ChrisL
-
I can't get it to not calculate other days in the chart, If I give it a 5 day chart it sits there calculating for a long time, if one day chart its fast and what I want
Here is code:
protected override void OnBarUpdate()
{
DateTime dt = Time[0];
if (Bars.IsFirstBarOfSession)
{
sessionIterator.GetNextSession(Time[0], true);
// store the desired session information
tradingDay = sessionIterator.ActualTradingDayExchange;
DateTime beginTime = sessionIterator.ActualSessionBegin;
DateTime endTime = sessionIterator.ActualSessionEnd;
dtStartTime = new DateTime (dt.Year, dt.Month, dt.Day, dtStartTime.Hour, dtStartTime.Minute, dtStartTime.Second);
dtEndTime = new DateTime (dt.Year, dt.Month, dt.Day, dtEndTime.Hour, dtEndTime.Minute, dtEndTime.Second);
}
if (CurrentBars[0] < 10)
return;
if (BarsPeriod.BarsPeriodType == BarsPeriodType.Minute && sessionIterator.IsInSession(DateTime.Now, true, true) )
{
if( BarsPeriod.Value == 1)
{
if (ToTime(Time[0]) < ToTime(dtStartTime))
{
dHighestPrice = 0.0;
dLowestPrice = 0.0;
}
else if (ToTime(Time[0]) == ToTime(dtStartTime))
{
dHighestPrice = High[0];
dLowestPrice = Low[0];
dMidPrice = dLowestPrice + (dHighestPrice-dLowestPrice)/2.0;
dUpperRange = dHighestPrice + dRangeValue;
dLowerRange = dLowestPrice - dRangeValue;
}
else if (ToTime(Time[0]) > ToTime(dtStartTime) && ToTime(Time[0]) <= ToTime(dtEndTime))
{
/// Computations
if(High[0] > dHighestPrice)
dHighestPrice = High[0];
if(Low[0] < dLowestPrice)
dLowestPrice = Low[0];
Comment
-
Hi set2win, If you choose to use the Session Iterator, you can use the last value you get from DateTime beginTime = sessionIterator.ActualSessionBegin; and start plotting as long as Time[0] > beginTime (see DateTime.Compare()). Or you can detect the current day from the DateTime.Now property when the script starts up:
Kind regards,Code:if(Time[0].Year == DateTime.Now.Year && Time[0].Month == DateTime.Now.Month && Time[0].Day == DateTime.Now.Day) { BackBrush = Brushes.Red; //or use a boolean so you can start drawing once this becomes true }
-ChrisL
Comment
-
This code is derived from ecosytem opening range, i think the issue is to identity the dtStartTime / dtEndTime as of today only so if for example I want to use 930am to 940am as the opening range it must be those times for today only.
adding :
if (if (BarsPeriod.BarsPeriodType == BarsPeriodType.Minute && Time[0].Year == DateTime.Now.Year && Time[0].Month == DateTime.Now.Month && Time[0].Day == DateTime.Now.Day)
Limits the display to today only but it still seems to take a long time calculating on a 5 day series
Last edited by set2win; 04-11-2022, 03:28 PM.
Comment
-
Hi set2win, just to confirm, you are wanting to modify this opening range indicator from the ecosystem so it only calculates the values for the current day? If that is the case I can have a look at the indicator tomorrow and let you know what to change. If possible please link to the exact indicator you are using.
Kind regards,
-ChrisL
Comment
-
Here is the original code, it will show opening range for as many days as you load. I only want today. and I don't want it calculating any bars other than today. So if I add it to a 5 day chart, it will calculate present day only.Attached Files
Comment
-
Hello
I would like to ask for help with a possible modification to the indicator "Opening Range Indicator".
I would like it to draw the range between two hours for the current day (00:01 - 09:30) and the previous day (00:01 - 09:30) extending the two lines from the previous day on the current day chart.
Only the previous day and the current day.
Thank you
Last edited by oviejo; 05-06-2022, 08:30 AM.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
601 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
347 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
103 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
559 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
558 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment