PDA

View Full Version : Current high/low of specific sessions


K. SATO
05-10-2010, 12:18 PM
Hi,

(1) Code(a) plots the high and low of current day according to the session begins and session ends time defined in the chart properties. Code(b) get the first bar of the session.

(a) if (Bars.SessionBreak)
{
currentHigh = High[0];
currentLow = Low[0];
}
currentHigh = Math.Max(currentHigh, High[0]);
currentLow = Math.Min(currentLow, Low[0]);

(b) if(Bars.FirstBarOfSession)

(2) What function should I use if I would like to plot the current high and low as well as to get the the first bar of the following defined sessions(eg. 9:15 to 10:15 ; 10:15 to 11:15 ; 11:15 to 12:15 and so on)? Thanks in advance.

NinjaTrader_Tim
05-10-2010, 01:57 PM
Hi K. SATO,

You can create time filter similar to the one here - http://www.ninjatrader.com/support/forum/showthread.php?t=3226

You could then flag (record) the bar at which the time filter begins, then find the MAX over the last bars, back until the bar that the time filter started.

K. SATO
05-12-2010, 01:12 PM
Hi Tim,

(1) I mainly look at Range Bar Chart.I think I'm really lost in getting the first bar of the specified session. I try the following code but it seems only to work on time based chart.

if(ToTime(Time[0]) ==211500 || ToTime(Time[0]) ==221500 || ToTime(Time[0]) ==231500 || ToTime(Time[0]) ==01500)

{
h1 = High[0];
l1 = Low[0];
}

p1.Set (h1);
p2.Set (l1);

DrawRegion("reg1",CurrentBar, 0, p1, p2, Color.Transparent, Color.DarkGray, 4);

(2) I try Bars.GetBar ; Bars.SessionBreak ; Bars.FirstBarOfSession . They are all either related to the session begins time defined in chart properties or time stamp is needed.

(3) I know I've to flat the first bar then apply

if(ToTime(Time[0]) >211500 && ToTime(Time[0]) <221500 || ToTime(Time[0]) >22150 && ToTime(Time[0]) <231500) and MAX/ MIN which should solve the problem? Any further advice will be much appreciated!

(4) For the time being,I just have to change the session begins and ends time in chart properties in order to get whant I want temporarily but it's too inconvenient. Attachment refered.

NinjaTrader_Tim
05-12-2010, 02:01 PM
Hi K. SATO,

1. When you use 'ToTime(Time[0]) ==211500" you are trying to satisfy the condition that the single timestamp of the bar equals 211500. With Range bars, the start and end of each bar is determined by when the range of the bar is completed, and not by a round interval, like 1 or 5 minute interval charts. And therefore the timestamp likely won't meet your condition.

2. The GetBar() is used as in the following page - http://www.ninjatrader-support.com/HelpGuideV6/helpguide.html?GetBar

As for SessionBreak and FirstBarOfSession, that will indeed be determined by the chart settings.

You could either use an interval that will offer time stamps to meet the condition in 1, or use a much "looser" range for the condition, such as...

ToTime(Time[0]) >211500 && ToTime(Time[0]) <222000

which is a condition that is not guaranteed to be met, but is more likely depending on the Range interval you use.

K. SATO
05-12-2010, 02:50 PM
Hi Tim,

So am I right to say based on current NT6.5 or even NT7.0, it won't be able to do what I wanted if Range Bars Chart is preferred? Any possibility to solve this in the near future?

NinjaTrader_Tim
05-12-2010, 03:11 PM
Hi K. SATO,

You can do this with the current versions. You will just need to figure out a way to satisfy the condition using range bars.

For example, if you use...

if(ToTime(Time[0]) > 211500)

The first range bar that satisfies this will be processed.


You can then grab the value you want....

if(ToTime(Time[0]) > 211500)
{
h1 = High[0];
l1 = Low[0];
}



Then make sure the values are not grabbed again...

if(ToTime(Time[0]) > 211500 && bool = true)
{
h1 = High[0];
l1 = Low[0];
bool = false
}


Then reset the bool before your next time condition.

K. SATO
05-15-2010, 09:21 AM
Hi Tim,

I'm totally new to programming .Furthermore this is the first time I deal with BOOL. I try the following .Code compiled but nothing plotted and shown. Can you kindly point out my mistakes? Thanks again.

#region Variables
// Wizard generated variables
// User defined variables (add any user defined variables below)

private double h1 ;
private double l1 ;

private bool isInit;

private DataSeries p1;
private DataSeries p2;

#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()
{

p1 = new DataSeries (this);
p2 = new DataSeries (this);

CalculateOnBarClose = true;
Overlay = true;
PriceTypeSupported = false;

}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{

if(ToTime(Time[0]) >210000 && isInit==true || ToTime(Time[0]) >211500 && isInit==true)

{
h1 = High[0];
l1 = Low[0];
isInit = false;

Print("h1:" + h1.ToString());

p1.Set (h1);
p2.Set (l1);
}

DrawRegion("Reg1", CurrentBar, 0, p1, p2, Color.Transparent, Color.DarkRed,10);
}

NinjaTrader_RyanM
05-15-2010, 02:03 PM
Hello K.Sato,

First thing I would look at here is simplifying your condition:

if(ToTime(Time[0]) >210000 && isInit==true || ToTime(Time[0]) >211500 && isInit==true)

Maybe try separating these conditions into separate if statements.

Clarify your intentions a bit here and we may be able to get you on the right track.

K. SATO
05-15-2010, 02:30 PM
Hi RyanM,

I'm sorry for disturbing your weekend. Actually I would like to plot the current high and low as well as to get the the first bar's High and Low of the following defined sessions on Range Bars Chart (eg. 9:15 to 10:15 ; 10:15 to 11:15 ; 11:15 to 12:15 and so on over the 24 hours market). Now I've the difficulty in getting the first bar values to be used next when I apply MAX/MIN.Your guidance will be much appreciated!

NinjaTrader_Josh
05-15-2010, 07:12 PM
K. SATO,

You will need to use the time filter as Ryan has shown you in the previous post for each of your time ranges. Then inside your if-statement you will want to keep track of your own variable for Highs and Lows. When a new high is reached within that time range, store that value into your variable. Every time you have a bar within that time range you compare its high versus your stored value. If the new bar's high > the stored high then you have a new high and you should store that instead. Then at the end of the time range you will have that range's high/low. Please see here:

http://www.ninjatrader.com/support/forum/showthread.php?t=8600