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
Find the High and Low every 15 minutes
Collapse
X
-
Hello calmsoul,
We have a reference sample that is close to this:
Indicator: Calculating the highest high or lowest low for a specified time rangeRyan M.NinjaTrader Customer Service
-
code
thank for your quick response i have been using that as reference i am stuck where my highs and lows are not getting populated. Below is the code i have. Any idea why high and lows are not printing
time = DateTime.Now; // get the current time
// condition if time <15
if (time.Minute<15){ // check if time is less than 15 minutes
startHour = time.Hour; // Default setting for StartHour
Print("condition is less than 15");
Print("Current hour is:" + time.Hour);
startMinute = 00; // Default setting for StartMinute
endHour = time.Hour; // Default setting for EndHour
endMinute = 15; // Default setting for EndMinute
if (ToTime(EndHour, EndMinute, 0) > ToTime(time))
return;
else {
calculatesr(StartHour, StartMinute, EndHour, EndMinute);
}
Comment
-
Calculatesr function
//below is the calculatesr function
publicvoid calculatesr(int StartHour, int StartMinute, int EndHour, int EndMinute)
{
if (startDateTime.Date != Time[0].Date)
{
startDateTime = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, StartHour, StartMinute, 0);
endDateTime = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, EndHour, EndMinute, 0);
}
Print("start hour in function is" + StartHour);
Print("start minute in function is" + StartMinute);
Print("end minute in function is" + EndMinute);
// Calculate the number of bars ago for the start and end bars of the specified time range
int startBarsAgo = GetBar(startDateTime);
int endBarsAgo = GetBar(endDateTime);
double highestHigh = MAX(High, startBarsAgo - endBarsAgo)[endBarsAgo];
double lowestLow = MIN(Low, startBarsAgo - endBarsAgo)[endBarsAgo];
// Set the plot values
HighestHigh.Set(highestHigh);
LowestLow.Set(lowestLow);
}
Comment
-
That reference sample is useful for making these types of calculations every day. If you only care about the last 15 minutes(Compared to CurrentTime), you can simplify a bit.
Use GetBar to get the bars ago value for 15 minutes ago and plug that in for your barsago parameter in MIN and MAX.
int fifteenMinutesAgo = GetBar(DateTime.Now.AddMinutes(-15));
double myHigh = MAX(High, fifteenMinutesAgo)[0];
This will only return useful values for the most recent 15 minutes. Prior to that, any value return is the individual bar highs and lows.Ryan M.NinjaTrader Customer Service
Comment
-
I see - you want a rolling 15 minute high / low. You'll will want to use Time[0] instead of DateTime.Now. This captures the bar time stamp, not your computer date / time.
int fifteenMinutesAgo = GetBar(Time[0].AddMinutes(-15));
double myHigh = MAX(High, fifteenMinutesAgo)[0];Ryan M.NinjaTrader Customer Service
Comment
-
bowas, we would unfortunately not have this completed as a sample study, you would need to code it out yourself with the snippet as starting point that Ryan provided - http://www.ninjatrader.com/support/h...indicators.htmBertrandNinjaTrader Customer Service
Comment
-
need help with simple plotting indicators
Originally posted by calmsoul View Posti need to create an indicator which can find the high and low every 15 minutes
Comment
-
smartguy, you can draw vertical lines using the DrawVerticalLine() method. You could draw this every 15 minutes (starting on the hour), like this:
Code:if (Time[0].Minute % 15 == 0) DrawVerticalLine("vert line" + CurrentBar, 0, Color.Black, DashStyle.Solid, 2);
AustinNinjaTrader Customer Service
Comment
-
thanks to begin with
I want to begin by thanking your for responding and offering your help. I hate to seem stupid, but how do I make that in to an indicator- I tried "creating indicator" and copy pasting this in- no luck- I am capable of importing or copy pasting an already created .cs file if you could help me with that I would be very appreciative. Thanks in advanceOriginally posted by NinjaTrader_Austin View Postsmartguy, you can draw vertical lines using the DrawVerticalLine() method. You could draw this every 15 minutes (starting on the hour), like this:
Code:if (Time[0].Minute % 15 == 0) DrawVerticalLine("vert line" + CurrentBar, 0, Color.Black, DashStyle.Solid, 2);
Comment
-
smartguy,
You should be able to create a custom indicator from this snippet.
Click Tools > New NinjaScript > Indicator
All defaults are acceptable. Click Next through the wizard until you get to the code view.
Place the snippet so that it falls in-between the two curly bracket { } of OnBarUpdate(), like this:
Code:protected override void OnBarUpdate() { if (Time[0].Minute % 15 == 0) DrawVerticalLine("vert line" + CurrentBar, 0, Color.Black, DashStyle.Solid, 2); }
Overlay = true; //means the indicator is placed on the main price panel
You also don't need a plot value so you can delete or comment the line that sets the plot.Last edited by NinjaTrader_RyanM1; 12-07-2010, 11:52 AM.Ryan M.NinjaTrader Customer Service
Comment
-
thank you
thank you for your kindness. Now how do I make it display all the way up and down panal 1 (price) rather then only on the price bar. I think it probably has something to do with the code calling for black and I use a black chart background, but when I tried to change the color in the code it won't compile, and if I stipulate a color in the indicator, it doesn't change color. I am sure it is something very simple, but I am just not up to speed in the ninja coding language.Originally posted by NinjaTrader_RyanM View Postsmartguy,
You should be able to create a custom indicator from this snippet.
Click Tools > New NinjaScript > Indicator
All defaults are acceptable. Click Next through the wizard until you get to the code view.
Place the snippet so that it falls in-between the two curly bracket { } of OnBarUpdate(), like this:
Code:protected override void OnBarUpdate() { if (Time[0].Minute % 15 == 0) DrawVerticalLine("vert line" + CurrentBar, 0, Color.Black, DashStyle.Solid, 2); }
Overlay = true; //means the indicator is placed on the main price panel
You also don't need a plot value so you can delete or comment the line that sets the plot.Last edited by smartguy; 12-07-2010, 02:37 PM.
Comment
-
Originally posted by NinjaTrader_RyanM View PostI see - you want a rolling 15 minute high / low. You'll will want to use Time[0] instead of DateTime.Now. This captures the bar time stamp, not your computer date / time.
int fifteenMinutesAgo = GetBar(Time[0].AddMinutes(-15));
double myHigh = MAX(High, fifteenMinutesAgo)[0];
Seems like calmsoul's original question has not been addressed: "i need to create an indicator which can find the high and low every 15 minutes"
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by wzgy0920, 04-20-2024, 06:09 PM
|
2 responses
26 views
0 likes
|
Last Post
by wzgy0920
Today, 10:43 PM
|
||
Started by wzgy0920, 02-22-2024, 01:11 AM
|
5 responses
32 views
0 likes
|
Last Post
by wzgy0920
Today, 10:33 PM
|
||
Started by wzgy0920, Yesterday, 09:53 PM
|
2 responses
49 views
0 likes
|
Last Post
by wzgy0920
Today, 10:29 PM
|
||
Started by Kensonprib, 04-28-2021, 10:11 AM
|
5 responses
192 views
0 likes
|
Last Post
by Hasadafa
Today, 10:19 PM
|
||
Started by GussJ, 03-04-2020, 03:11 PM
|
11 responses
3,234 views
0 likes
|
Last Post Today, 08:07 PM |
Comment