PDA

View Full Version : Session Begin and session End


blarouche
10-05-2009, 08:36 AM
Hi guys

I am testing the new version 7. I am migrating from 6.5 and I have met some problems that I would like to address with you this morning.


In my old script I was using ChartControl.SessionBegin and ChartControl.SessionEnd that obviously don't work anymore.


What is the script I should write to get the same result as before.

I tried GetSession()...... like you mention in your email but get compiled errors


Thanks

Bernard

NinjaTrader_Josh
10-05-2009, 08:52 AM
Hi blarouche,

Please try this:

BarsArray[int barSeries].Session.SessionsOfDay[int dayOfWeek].BeginTime

blarouche
10-05-2009, 09:12 AM
Josh



Here is my old code :

if(ToTime(Time[0]) >= ToTime(ChartControl.SessionEnd)){
...
}

Now I should write :

if(ToTime(Time[0]) >= ToTime(BarsArray[0].Session.SessionsOfDay[3].EndTime));

int barseries being ?
int SessionOfDay : I put 3 but I just need to know if we are in a regular session.


This script didn't work


Bernard

NinjaTrader_Josh
10-05-2009, 09:15 AM
blarouche,

The concept of Session begin/end times is different in NT7. You now have actual session templates that is controlled in the Session Manager window. Before in 6.5, you only had one session setting which was determined by the chart or whatever you set it as when starting the strategy in the Strategies tab. Now, you choose the session template you want to use for the instrument and it has many start/end times depending on the days.

barSeries refers to which BarsInProgress you are on. If you have a multi series script then you will need to define this as to which instrument you want to be checking. SessionsOfDay[] determines which actually session definition you want to look at. Please open up the Session Manager to get a feel for this. 0 corresponds to the first listed day, 1 the next, etc.

blarouche
10-05-2009, 09:29 AM
Josh

OK I understand.
But my code still don't work.

I get the following error :

The best overload method match for NinjaTrader.Indicator.Indicator.ToTime(System DateTime) has some invalid arguments)
Argument1 : cannot convert from int to System Datetime.

It seems that my code before was returning a DateTime and now with the new script it is returning an int..


Bernard

NinjaTrader_Josh
10-05-2009, 09:39 AM
Bernard,

That would be correct. Before you were converting the DateTime to an int with ToTime(). Now it is already an int to begin with so you don't need to use ToTime() to further convert it.

blarouche
10-05-2009, 09:42 AM
Josh

You're right

It now works

Many thanks


Bernard

blarouche
10-05-2009, 09:54 AM
Josh

Still need help on the following code :


TimeSpan duration = ChartControl.SessionEnd - ChartControl.SessionBegin;


I was looking for a duration TimeSpan between End and Start Time of a session.


What would be the new code ?
I need to return a DataTime object.


Bernard

NinjaTrader_Josh
10-05-2009, 09:57 AM
Bernard,

These do not return DateTimes. You could try to create your own DateTime by parsing the ints components into hours, minutes, seconds.

You could also try BarsArray[int barSeries].Session.NextBeginTime and .NextEndTime which should return DateTimes.

blarouche
10-05-2009, 10:44 AM
Josh

It worked with this :

BarsArray[int barSeries].Session.NextBeginTime and .NextEndTime





Thank you very much

Bernard

nkhoi
10-22-2009, 11:57 AM
Bernard,

That would be correct. Before you were converting the DateTime to an int with ToTime(). Now it is already an int to begin with so you don't need to use ToTime() to further convert it.


Does it mean if you upgrade to 7 you will have to re-write many of home growth indicator?

NinjaTrader_Bertrand
10-22-2009, 12:06 PM
nkhoi, for some scripts this is correct - to see code breaking changes, please consult this document which we update as we move forward - http://www.ninjatrader-support2.com/vb/showthread.php?t=21016

ytrender
11-13-2009, 11:47 AM
Hello Mr Bertrand,

I am hopelesly stuck with trying to code SMA of prior 7 sessions range. Line bellow does not return any value?
double rangeB = PriorDayOHLC().PriorOpen[0]-PriorDayOHLC().PriorLow[0];

I have seen your sugestions on using
Bars.GetSessionBar as well as SampleGetHighLowbyTimeRange, but I am still confused as to implementation of SMA of prior DAILY range?
I know that NinjaTrader 7 supports this better. I really need your sugestions to above or perhaps help to get beta 7.

Thank you.

Gene.

NinjaTrader_Josh
11-13-2009, 12:06 PM
Please check your Control Center logs for any runtime errors.

ytrender
11-18-2009, 08:04 AM
Good Morning Bertrand,

You have not reply to my last messages. If you can please look at the code below. I took it from the sample code and tried to adapt it for Open-Low Daily range for intraday chart. It doesn't plot ???

if (EndHour < StartHour)
return;

if (ToTime(EndHour, EndMinute, 0) > ToTime(Time[0]))
return;

if (startDateTime.Date != Time[0].Date)
{
startDateTime = new DateTime(Time[0].Year, Time[0].Month, Time[1].Day, StartHour, StartMinute, 0); //changed to Time[1].Day???
endDateTime = new DateTime(Time[0].Year, Time[0].Month, Time[4].Day, EndHour, EndMinute, 0);//Time[12].Day
}

// 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 smaLow = SMA(Low,startBarsAgo - endBarsAgo)[endBarsAgo];
double smaOpen = SMA(Open,startBarsAgo - endBarsAgo)[endBarsAgo];


double Myrange = (smaOpen-smaLow);




double x = Open[0] - Myrange;

MyNumber.Set(x);


Thank you for Help,

Ytrender

NinjaTrader_Bertrand
11-18-2009, 01:00 PM
ytrender, sorry I didn't catch up earlier here with you - for what you look for I think the following is simpler to work with -


protected override void OnBarUpdate()
{
highLow.Set(CurrentDayOHL().CurrentHigh[0] - CurrentDayOHL().CurrentLow[0]);

Plot0.Set(SMA(highLow, Bars.BarsSinceSession)[0]);

}


You would just need to define the highLow custom data series in the variables -


private DataSeries highLow;


and Initialize() -


highLow = new DataSeries(this);


Then it would return you an SMA with the length of bars into the current session over the developing session range.

ytrender
11-18-2009, 03:27 PM
Thank you Bertrand,

Unfortunately I can't plot any values from your example?
I don't understand , if I Plot indicator on 15 min timeframe how do I get a daily sma high-low range from code below? It looks to me this is a neat solution for intraday range. By DAILY I mean Yesterday+Monday+Friday....It should be really simple, except that it is'nt. Perhaps I was not clear in what I am trying to do?
I just need to call daily SMA(MyRange,7) from any timeframe. That is why I have been looking at SampleGetHighLowByTimeRange example. But I dont know how to pass period to startTime and endTime

Sorry for confusion,

Thank you

Gene

NinjaTrader_Josh
11-18-2009, 03:40 PM
Gene,

Please provide full code of what you have so far. Thank you.

ytrender
11-18-2009, 08:09 PM
Hi Josh, Thank you for trying to help,

This file is not mine, I simply tried to adapt the SampleGetHighLowByTimeRange to doing something like daily High-Low range for intraday timeframe. My Qestiones inside attached zip.

Thank you very much,

Gene.

NinjaTrader_Bertrand
11-19-2009, 07:57 AM
ytrender, thanks for posting - I'll take a look.

NinjaTrader_Bertrand
11-19-2009, 02:37 PM
Gene, took at look at your code - are you on 6.5 or our 7 beta?

This would be more straightforward on 7, as you then have access to multiple series and instruments in indicators, too. Whereas in 6.5 this is possible for strategies only, thus you could access the SMA of the daily High Low Range in a strategy and plot it via the Strategy Plot techniques (or just draw lines at your final buy / sell levels calculated).

http://www.ninjatrader-support.com/HelpGuideV6/MultiTimeFrameInstruments.html

ytrender
11-20-2009, 10:10 AM
Hi everybody,

I have never had this problem before, I am getting an error and exception in Market Analyzer with several studys that used to work just fine.
In analyser property and label dont change to my custom indicator insted it crashes if I click apply
Msg in Log Error on calling the OnBarUpdate for indicator... on bar 19;index was outside the bounds of array
Failed to set property Indicator to market analyzer column...Exception has been thrown by the target of invocation????

Appreciate any help,

Thank you.

NinjaTrader_Bertrand
11-20-2009, 11:08 AM
ytrender, those are the NinjaTrader 7 bug reporting / issue resolving forums here, could you please repost this in the regular forum under the Market Analyzer entry? I also just replied to your PM, please check your forum inbox. Thanks