View Full Version : 1st Hour High/Low
pijamatrader
03-21-2007, 04:56 AM
Hi, does anyone know where I can find, or how I can make an indicator that plots a line showing the 1st hour's High/Low of the session?
Thanks,
PijamaTrader
NinjaTrader_Ray
03-21-2007, 05:06 AM
A system indicator does not exist but you can program one in NinjaScript. If you are new to programming, this will require a learning curve. If you have programming background, please see the Help Guide section for NinjaScript. There are some indicator development tutorials to get you started. You can also look at the code for the PriorDayOHLC to get an idea of how to go about programming the logic for such an indicator.
Ray
qitrader
04-04-2007, 01:30 AM
I am also interested in this indicator.
Is there a function that allows you to store values from a given time/date?
thanks
NinjaTrader_Ray
04-04-2007, 01:43 AM
No there is not.
Ray
qitrader
04-04-2007, 01:43 AM
This is the logic I have but would like some help with the translation to get me started.
THanks
Qi
// New day settings
if ( DateTime[0]<>Date[1] )
DateInFromTo= (Date>=iFromYYYMMDD && Date<=iToYYYMMDD);
bool FirstTrade=true;
double RangeH=H;
double RangeL=L; // first bars High Low are Ranges h&l
TimeH=Time;
TimeL=Time;
// Range settings
If L<LowD(0)[1] then TimeL=Time; {if new H or L, remember the time of H or L}
If H>HighD(0)[1] then TimeH=Time;
If Time=OpenRangeTime then begin // if openning range is finished
RangeH=HighD(0); RangeL=LowD(0); RangeHtime=TimeH; RangeLtime=TimeL; end; // remember Range parameters
NinjaTrader_Ray
04-04-2007, 01:46 AM
I suggest reviewing some of our system indicator source files. Check out the @PreviousDayOHL to get an idea of how this can be done.
Ray
qitrader
05-22-2007, 08:48 PM
In NT, how do I recall the High or Low of a given time?
Can I declare a variable representing 930am EST and another as 1000a EST as below?
e.g.
private double start_time = 0930;
private double end_time = 1000;
thanks
qitrader
05-22-2007, 09:28 PM
There seems to be a few requests to the OR lines. So I will start providing my logic. Let me know if it needs to be corrected.
Thanks
#region Using declarations
using System;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.ComponentModel;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Gui.Chart;
#endregion
// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
[Description("Opening Range Breakout")]
[Gui.Design.DisplayName("OR Breakout")]
public class OpeningRange : Indicator
{
#region Variables
private DateTime currentDate = Cbi.Globals.MinDate;
private int start_time = 0930;
private int start_time = 1000;
private int PeriodHigh = 0;
private int PeriodLow = 9999;
#endregion
/// <summary>
/// This method is used to configure the indicator and is called once before any bar data is loaded.
/// </summary>
protected override void Initialize()
{
Add(new Plot(Color.Orange, PlotStyle.Line, "PeriodHigh"));
Add(new Plot(Color.Orange, PlotStyle.Line, "PeriodLow"));
AutoScale = false;
CalculateOnBarClose = false; // Call 'OnBarUpdate' on every tick
Overlay = true; // Plots the indicator on top of price
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
if (currentDate != Time[0].Date)//if new day
{
PeriodHigh = 0; // re-initialize PeriodHigh,PeriodLow for the new day
PeriodLow = 9999;
}
if (StartTime <= Time[0] || Time[0] <= EndTime) {
if (High[0] > PeriodHigh) { PeriodHigh = High ; }
if (Low[0] < PeriodLow) { PeriodLow = Low ; }
PeriodLow = Low ;
}
}
#region Properties
[Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
[XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
public DataSeries Plot0
{
get { return Values[0]; }
}
#endregion
}
}
qitrader
05-23-2007, 06:16 AM
I have uploaded part of my code but still getting error messages.
The name 'StartTime' does not exist in the current context
" " 'EndTime' " " " " " " "
Any help in the code is appreciated
thanks
NinjaTrader_Ray
05-23-2007, 07:01 AM
StartTime --> You have not declared this anywhere, that's why it says it does not exist. Even if you rectify this, your logic will not work. Please review the following Help Guide section.
http://www.ninjatrader-support.com/HelpGuideV6/ToTime.html
qitrader
05-23-2007, 07:24 AM
Hi
I changed the code to the following but it still doesn't plot the lines. Any help is appreciated. THe code compiled correctly.
protected override void Initialize()
{
Add(new Plot(Color.Orange, PlotStyle.Line, "PeriodHigh"));
Add(new Plot(Color.Orange, PlotStyle.Line, "PeriodLow"));
AutoScale = false;
CalculateOnBarClose = false; // Call 'OnBarUpdate' on every tick
Overlay = true; // Plots the indicator on top of price
}
protected override void OnBarUpdate()
{
if (currentDate != Time[0].Date)//if new day
{
PeriodHigh = 0; // re-initialize PeriodHigh,PeriodLow for the new day
PeriodLow = 9999;
}
if (ToTime(Time[0]) > start_time && ToTime(Time[0]) < end_time) {
if (High[0] > PeriodHigh) { PeriodHigh = High[0] ; }
if (Low[0] < PeriodLow) { PeriodLow = Low[0] ; }
}
}
NinjaTrader_Ray
05-23-2007, 07:56 AM
Hi,
Its not plotting since you are not setting any plot values. I would scrap this indicator and start through the wizard and add plots named PeriodHigh and PeriodLow and then have the wizard generate all of the code required.
Then add back your logic and when you have to set the value of your plots, you would do something like:
PeriodHigh.Set(plotValueHere);
qitrader
05-23-2007, 09:35 AM
I think I am very close but I got 1 error message.
Cannot apply indexing with [] to an expression of type 'double'
NinjaTrader_Ray
05-23-2007, 10:08 AM
PHigh is a variable not an array that can be indexed.
Should be PeriodHigh.Set(PHigh);
qitrader
05-24-2007, 06:52 AM
Hi
The code works now but my logic is flawed. How do I use the following properties?
Bars.GetSessionBar(int sessionsAgo).High
Bars.GetSessionBar(int sessionsAgo).Low
Trying to gather the highest high and lowest low of session from start period to end period.
Thanks
NinjaTrader_Ray
05-24-2007, 07:44 AM
If you require the high and low of the session, why don't you just use the indicator CurrentDayOHL ?
Help Guide - http://www.ninjatrader-support.com/HelpGuideV6/CurrentDayOHL.html
qitrader
05-24-2007, 10:08 AM
Hi,
Where do I use it? I try declaring it in variables section and I still get "The name 'CurrentOHL' does not exist in the current context" I also tried placing it under ONbarUpdate and same problem occurs.
Thanks
NinjaTrader_Ray
05-24-2007, 10:24 AM
So that I am on the same page as you...
- What do you want to do, have an indicator that plots the day's highest high and lowest low?
- If yes, there is no need to create a custom indicator, just open a chart and add the CurrentDayOHL indicator.
- Is there something else you want to do? I yes, please let me know and I can provide additional assistance.
qitrader
05-24-2007, 10:30 AM
Ray,
I want to plot the highest high and lowest low of the first 30 minutes of the trading session. For this I would need a property that can look at the highs/lows from 930am EST till 1000am EST. Then plot the highest high and lowest low from that period.
Thanks
NinjaTrader_Ray
05-24-2007, 10:36 AM
Thanks for the clarification.
Then you will have to create a custom indicator for sure. In english...
If the time is between your session start time and session start time + 30 mins plot the value of the current high.
Same for current low.
To access the current high or low:
CurrentDayOHL().CurrentHigh[0]
CurrentDayOHL().CurrentLow[0]
qitrader
05-24-2007, 11:32 AM
How do I use this?
I followed the example in the help filebut when I compile, I get "The name 'CurrentOHL' does not exist in the current context"
NinjaTrader_Dierk
05-24-2007, 12:01 PM
Rename CurrentOHL to CurrentDayOHL(as suggested by Ray's post). We will fix the bug in the docs with next update.
qitrader
05-24-2007, 12:12 PM
Hi
I get the following error:
An object reference is required for the nonstatic field, method, or property 'NinjaTrader.Indicator.Indicator.CurrentDayOHL()' Indicator\OpenRange.cs 28 20
qitrader
05-24-2007, 12:26 PM
Here is partial code
if (currentDate != Time[0].Date)//if new day
{
pHigh = 0; // re-initialize PeriodHigh,PeriodLow for the new day
pLow = 9999;
}
if (ToTime(Time[0]) > 93000 && ToTime(Time[0]) < 100000)
{
if (High[0] > pHigh) { pHigh = CurrentDayOHL().CurrentHigh[0] ; }
if (Low[0] < pLow) { pLow = CurrentDayOHL().CurrentLow[0] ;}
PeriodHigh.Set(PHigh);
PeriodLow.Set(PLow);
}
NinjaTrader_Dierk
05-24-2007, 12:27 PM
- I suppose you are on latest NT6R2, no?
- could you please the code line which causes the trouble (click on the error message and you'll see)? (edit: disregard, since you just posted)
Thanks
Just looking through this thread, it appears over complicated. Would the following not do the job? - in OnBarUpdate()
if (ToTime(Time[0]) == 100000)
{
pHigh = CurrentDayOHL().CurrentHigh[0];
pLow = CurrentDayOHL().CurrentLow[0];
}
if (ToTime(Time[0]) >= 100000)
{
periodHigh.Set(pHigh);
periodLow.Set(pLow);
}
There would be nothing plotted until 1000hrs, then you will get the highest and lowest price for the day so far up to 1000hrs, plotted as a straight line for the rest of the day. I think that is what is being attempted, or maybe I misunderstood something.
MJT
NinjaTrader_Ray
05-25-2007, 01:29 PM
Yes, that would work.
qitrader
05-26-2007, 06:11 PM
MJT,
That worked. It always seem easier after the problem is solved. Thank you so much. :)
Ray
Also, are there any examples to code this similar strategy to be used in Market Analyzer? When close > Phigh, then flash Green.
When close < Plow, then flash Red.
THanks again
NinjaTrader_Ray
05-26-2007, 08:15 PM
You would have to code a new indicator. I would code it and set the indicator plot value to > 0 when condition A is true, < 0 when condition B is true.
Then you can add this indicator to the Market Analyzer and set color conditions based on the indicator value.
BradB
05-29-2007, 04:38 PM
I just stumbled across this post. CurrentDayOHL would not work if the chart begins at 12:00am. If you truly want only the 1st hour after the market opens try:
private double Hour1High =0.0;
private double Hour1Low =0.0;
OnBarUpdate...
if (currentDate != Time[0].Date)
Hour1High = 0;
Hour1Low = 9999;
if (ToTime(Time[0]) >= 93000 && ToTime(Time[0]) < 103000)
{
if (High[0] > Hour1High)
Hour1High = High[0];
if (Low[0] < Hour1Low)
Hour1Low = Low[0];
}
qitrader
06-12-2007, 06:03 AM
How would I set a parameter so I can easily change from a 5 min, 15min or 30min OR.
I have tried using:
private double starttime =093000;
private double endtime =100000;
But it doesn't allow me to customize it in the indicator panel.
thanks
NinjaTrader_Ray
06-12-2007, 07:05 AM
If you mean changing the underlying data series? If yes, this is not possible.
qitrader
06-13-2007, 05:38 PM
What I mean is to have under Parameters:
StartTime: 930 am
EndTime: 1000 am
These 2 parameters can be modified from the Indicator window.
Thanks
NinjaTrader_Dierk
06-13-2007, 10:52 PM
You can not customize start/end time of the underlying series by custom parameters. You only can set session begin/end for the complete chart.
whitmark
06-14-2007, 05:08 AM
qitrader,
If you are looking to isolate the high/low for the first hour of the trading day, the logic that BradB offers will work and yes, you can define the start and end time for that initial period by including integer parameter for time (e.g., 93000, 103000) that can then be changed from the indicator panel.
But as Ray and Dierk point out, you cannot wrap a variable assignment to indicator dataseries value within a time-based if-then statement and expect it to work.
qitrader
07-12-2007, 05:54 AM
Whit,
If I can't use IF then statements, can you suggest something else that might work? I want to quickly change the OR settings in the indicator window.
Any tips you can recommend to make this work in Market Analyzer? E.g.
Blue if close > OR high
Red if close < OR low
thanks
qitrader
whitmark
07-12-2007, 02:01 PM
quitrader,
Is this what you are looking for? This indicator returns 4 states based on the defined market start time and opening range duration in minutes. The defined statuses are:
3 = close above opening range
2 = close in opening range
1 = close below opening range
0 = calculating opening range period
As Ray pointed out, these conditions can be color coded in Market Analyzer as I have demonstrated. Please use the Files, Utilities, Import NinjaScript option to load this indicator.
Regards,
Whitmark
qitrader
07-13-2007, 06:48 AM
Whitmark,
I appreciate your help. I will test it out today and see how it works.
thank you,
q
qitrader
07-16-2007, 12:01 PM
Mark,
THe OR indicator works well on the long side but not on the short side. I tried with ER2 today and it remained at (2) while it was below the Opening range. Any help is appreciated.
Thanks
Q
whitmark
07-16-2007, 12:35 PM
hmm . . . seems to work fine on my end, pls see attached. Remember, its coded to change states for a close above or below the ORB and not the high or low of the bar. If you are still having issues best to post a screen shot.
Regards,
Whitmark
qitrader
07-16-2007, 12:43 PM
I think I know where the problem is. It works on a 24H template but I have a default template that runs from 930 AM till 415 PM.
Q
qitrader
07-16-2007, 12:58 PM
Here is a screenshot.
Left = 24 HR
Right = modified to 930 to 415 EST
thanks
Q
whitmark
07-16-2007, 05:31 PM
qitrader,
I've added some day-break logic to accommodate your trading session usage. Keep in mind that there might be some alternative "opening range" periods and chart session begin and end times, particularly for forex, for which this implementation may not work, but for most morning range breakout applications this indicator will work fine. I've updated the previous post with the latest code. Enjoy!
Regards,
Whitmark