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
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,
-ChrisLChris L.NinjaTrader Customer Service
-
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:
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 }
-ChrisLChris L.NinjaTrader Customer Service
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,
-ChrisLChris L.NinjaTrader Customer Service
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 Stanfillirenfro, Today, 07:23 AM
|
1 response
4 views
0 likes
|
Last Post Today, 07:37 AM | ||
Started by cmtjoancolmenero, Yesterday, 03:58 PM
|
2 responses
22 views
0 likes
|
Last Post Today, 07:24 AM | ||
Started by olisav57, Yesterday, 07:39 PM
|
1 response
9 views
0 likes
|
Last Post Today, 07:23 AM | ||
Started by cocoescala, 10-12-2018, 11:02 PM
|
7 responses
944 views
0 likes
|
Last Post
by Jquiroz1975
Today, 07:21 AM
|
||
Started by oviejo, Today, 12:28 AM
|
1 response
12 views
0 likes
|
Last Post Today, 07:20 AM |
Comment