NexusFi: Find Your Edge


Home Menu

 





Ignore previous sessions


Discussion in NinjaTrader

Updated
    1. trending_up 4,260 views
    2. thumb_up 7 thanks given
    3. group 2 followers
    1. forum 11 posts
    2. attach_file 0 attachments




 
Search this Thread

Ignore previous sessions

  #1 (permalink)
 humy65 
Haifa/Israel
 
Experience: Beginner
Platform: NinjaTrader
Trading: Stocks
Posts: 15 since Mar 2012
Thanks Given: 3
Thanks Received: 2

I would like to avoid in my OnBarUpdate processing all bars that are prior to the current session - how ?

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
ZombieSqueeze
Platforms and Indicators
My NT8 Volume Profile Split by Asian/Euro/Open
NinjaTrader
NexusFi Journal Challenge - April 2024
Feedback and Announcements
Request for MACD with option to use different MAs for fa …
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Retail Trading As An Industry
67 thanks
NexusFi site changelog and issues/problem reporting
48 thanks
Battlestations: Show us your trading desks!
43 thanks
GFIs1 1 DAX trade per day journal
32 thanks
What percentage per day is possible? [Poll]
31 thanks

  #2 (permalink)
 
Big Mike's Avatar
 Big Mike 
Manta, Ecuador
Site Administrator
Developer
Swing Trader
 
Experience: Advanced
Platform: Custom solution
Broker: IBKR
Trading: Stocks & Futures
Frequency: Every few days
Duration: Weeks
Posts: 50,322 since Jun 2009
Thanks Given: 33,143
Thanks Received: 101,476

Add at the top of OnBarUpdate

if (Historical) return;

Mike

We're here to help: just ask the community or contact our Help Desk

Quick Links: Change your Username or Register as a Vendor
Searching for trading reviews? Review this list
Lifetime Elite Membership: Sign-up for only $149 USD
Exclusive money saving offers from our Site Sponsors: Browse Offers
Report problems with the site: Using the NexusFi changelog thread
Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
The following user says Thank You to Big Mike for this post:
  #3 (permalink)
 
Big Mike's Avatar
 Big Mike 
Manta, Ecuador
Site Administrator
Developer
Swing Trader
 
Experience: Advanced
Platform: Custom solution
Broker: IBKR
Trading: Stocks & Futures
Frequency: Every few days
Duration: Weeks
Posts: 50,322 since Jun 2009
Thanks Given: 33,143
Thanks Received: 101,476



humy65 View Post
I would like to avoid in my OnBarUpdate processing all bars that are prior to the current session - how ?

If you really want to include all the bars of current session, and not just the current bar, then you would need to do some logic check for the current bar date vs the Bars.Session stuff. I don't have Ninja up and haven't looked at that kind of code in years, but you can find sessions under Bars.Session* if I remember right.

Otherwise the if (Historical) return; would get you 99% there.

Mike

We're here to help: just ask the community or contact our Help Desk

Quick Links: Change your Username or Register as a Vendor
Searching for trading reviews? Review this list
Lifetime Elite Membership: Sign-up for only $149 USD
Exclusive money saving offers from our Site Sponsors: Browse Offers
Report problems with the site: Using the NexusFi changelog thread
Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
The following user says Thank You to Big Mike for this post:
  #4 (permalink)
 humy65 
Haifa/Israel
 
Experience: Beginner
Platform: NinjaTrader
Trading: Stocks
Posts: 15 since Mar 2012
Thanks Given: 3
Thanks Received: 2


Big Mike View Post
If you really want to include all the bars of current session, and not just the current bar, then you would need to do some logic check for the current bar date vs the Bars.Session stuff. I don't have Ninja up and haven't looked at that kind of code in years, but you can find sessions under Bars.Session* if I remember right.

Otherwise the if (Historical) return; would get you 99% there.

Mike

t

I need all bars in current session, not just the last.... so I'll have a look into the Bars.Session collection...

BTW : is there a way for me to detect whether the current connection is Market Replay connection ? (In side an indicator)

Started this thread Reply With Quote
  #5 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,102


humy65 View Post
I would like to avoid in my OnBarUpdate processing all bars that are prior to the current session - how ?

Before I answer, I need to come back to a definition

Trading day: Refers to the contract of the instrument that you trade. For example for ES the trading day currently starts at 3:30 PM Central Time and ends at 3:15 PM Central Time next day. Starting from November 18, the trading day for ES will start at 5:00 PM Central Time and end at 4:15 PM Central Time.

Session: Part of the trading day. For ES there could be night session from 3:30 PM to 8:30 AM and a day session from 8:30 AM to 3:15 PM.

NinjaTrader uses both the concept of the trading day and the session. A trading day can be made up of 1, 2 or 3 sessions - theoretically there could be more than 3, but I have never seen any practical application.

I assume that you want to know how to avoid to process any bars prior to the current trading day. I do not know why you want to do that, there is really no need, as you can easily code indicators that reset at the beginning of each session. For example, I have coded a SMA that resets at the start of the session to apply it to the NYSE Tick, because I do not want to include tick values of the prior trading day.

But coming back to your question, this is how not to process bars of the prior trading day:

(1) collect the current time
(2) find the start time (date, hour, minutes) of the trading day
(3) check each bar that is processed, whether it has a time stamp prior to the start of the trading day or afterwards


Current Time

You may use DateTime.Now. If you are connected to Market Replay you can use a method Now
 
Code
private DateTime Now
{
	get 
	{ 
		DateTime now = (Bars.MarketData.Connection.Options.Provider == Cbi.Provider.Replay ? Bars.MarketData.Connection.Now : DateTime.Now); 
		if (now.Millisecond > 0)
			now = Cbi.Globals.MinDate.AddSeconds((long) System.Math.Floor(now.Subtract(Cbi.Globals.MinDate).TotalSeconds));
		return now;
	}
}


Find the start of the current session
 
Code
private DateTime sessionBegin;
private DateTime sessionEnd;
Bars.Session.GetNextBeginEnd(Now, out sessionBegin, out sessionEnd);

will retrieve the session begin and end time of the current session of the primary bars. I have used the method Now defined above.


Check whether the current bar processed belongs to the current session

If you want to check whether the timestamp of the current bar belongs to the session that includes "Now", you have to differentiate between 2 cases.

Bars Built from ticks: You need to check, whether the timestamp iof the processed bar iss greater or equal that the value for sessionBegin.
Minute bars: You need to check, whether the timestamp of the processed bar is greater than the value for sessionBegin.

For example, if your ES session starts at 8:30 AM Central Time, then

-> a minute bar with the timestamp of 8:30 belongs to the prior session, you do not want to include it
-> a tick built bar (tick, volume, range, Renko bars ....) with the timestamp of 8:30 belongs to the current session, you want to include it


Attention

Depending on how you implement that concept, it will reset your indicators at the session start or it will not. I personally cannot imagine any reason to eliminate the bars of the prior session. Your request looks strange to me, and you have not explained what it can be used for.

Reply With Quote
The following 3 users say Thank You to Fat Tails for this post:
  #6 (permalink)
 humy65 
Haifa/Israel
 
Experience: Beginner
Platform: NinjaTrader
Trading: Stocks
Posts: 15 since Mar 2012
Thanks Given: 3
Thanks Received: 2


Fat Tails View Post
Before I answer, I need to come back to a definition

Trading day: Refers to the contract of the instrument that you trade. For example for ES the trading day currently starts at 3:30 PM Central Time and ends at 3:15 PM Central Time next day. Starting from November 18, the trading day for ES will start at 5:00 PM Central Time and end at 4:15 PM Central Time.

Session: Part of the trading day. For ES there could be night session from 3:30 PM to 8:30 AM and a day session from 8:30 AM to 3:15 PM.

NinjaTrader uses both the concept of the trading day and the session. A trading day can be made up of 1, 2 or 3 sessions - theoretically there could be more than 3, but I have never seen any practical application.

I assume that you want to know how to avoid to process any bars prior to the current trading day. I do not know why you want to do that, there is really no need, as you can easily code indicators that reset at the beginning of each session. For example, I have coded a SMA that resets at the start of the session to apply it to the NYSE Tick, because I do not want to include tick values of the prior trading day.

But coming back to your question, this is how not to process bars of the prior trading day:

(1) collect the current time
(2) find the start time (date, hour, minutes) of the trading day
(3) check each bar that is processed, whether it has a time stamp prior to the start of the trading day or afterwards


Current Time

You may use DateTime.Now. If you are connected to Market Replay you can use a method Now
 
Code
private DateTime Now
{
	get 
	{ 
		DateTime now = (Bars.MarketData.Connection.Options.Provider == Cbi.Provider.Replay ? Bars.MarketData.Connection.Now : DateTime.Now); 
		if (now.Millisecond > 0)
			now = Cbi.Globals.MinDate.AddSeconds((long) System.Math.Floor(now.Subtract(Cbi.Globals.MinDate).TotalSeconds));
		return now;
	}
}


Find the start of the current session
 
Code
private DateTime sessionBegin;
private DateTime sessionEnd;
Bars.Session.GetNextBeginEnd(Now, out sessionBegin, out sessionEnd);

will retrieve the session begin and end time of the current session of the primary bars. I have used the method Now defined above.


Check whether the current bar processed belongs to the current session

If you want to check whether the timestamp of the current bar belongs to the session that includes "Now", you have to differentiate between 2 cases.

Bars Built from ticks: You need to check, whether the timestamp iof the processed bar iss greater or equal that the value for sessionBegin.
Minute bars: You need to check, whether the timestamp of the processed bar is greater than the value for sessionBegin.

For example, if your ES session starts at 8:30 AM Central Time, then

-> a minute bar with the timestamp of 8:30 belongs to the prior session, you do not want to include it
-> a tick built bar (tick, volume, range, Renko bars ....) with the timestamp of 8:30 belongs to the current session, you want to include it


Attention

Depending on how you implement that concept, it will reset your indicators at the session start or it will not. I personally cannot imagine any reason to eliminate the bars of the prior session. Your request looks strange to me, and you have not explained what it can be used for.


Thanks much for the detailed answer!!!

The reason I want to process just the current session's bars is that as I'm processing 1 tick series and my
processing incurs an overhead which involves communication to external program - I need to make sure
the overhead when loading a chart which has long history is minimal.

Started this thread Reply With Quote
  #7 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,102


humy65 View Post
Thanks much for the detailed answer!!!

The reason I want to process just the current session's bars is that as I'm processing 1 tick series and my
processing incurs an overhead which involves communication to external program - I need to make sure
the overhead when loading a chart which has long history is minimal.


What about opening a chart with a lookback period of 1 or 2 days?

If you leave out the data prior to the current trading day, your indicators may display false values. Each indicator has a training period, for recursive indicators this can be pretty long.

Reply With Quote
  #8 (permalink)
 humy65 
Haifa/Israel
 
Experience: Beginner
Platform: NinjaTrader
Trading: Stocks
Posts: 15 since Mar 2012
Thanks Given: 3
Thanks Received: 2


Fat Tails View Post
What about opening a chart with a lookback period of 1 or 2 days?

If you leave out the data prior to the current trading day, your indicators may display false values. Each indicator has a training period, for recursive indicators this can be pretty long.

No worries - this indicator has no display, it is used just as an integration vehicle to external application which gets tick data from the the NT feed.

If I'm to use the lookback period option, can it be set (by the indicator) ?
Can it be set for each dataseries to be a different value (this is a multi instrument, multi time frame indicator) ?

Started this thread Reply With Quote
  #9 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,102


humy65 View Post
No worries - this indicator has no display, it is used just as an integration vehicle to external application which gets tick data from the the NT feed.

If I'm to use the lookback period option, can it be set (by the indicator) ?
Can it be set for each dataseries to be a different value (this is a multi instrument, multi time frame indicator) ?

You cannot set the lookback of the chart from the inidcator, and it is not possible to have different values for different instruments.

What you can do is simply check for a start date /start time when OnBarUpdate() is running. For example, if you trade ES and today's session started at 4:30 Eastern Time yesterday, you simply add three lines in the beginning of OnBarUpdate():
 
Code
DateTime startTime =  DateTime.Now.AddDays(-1).Date. AddHours(16).AddMinutes(30);
if((Bars.BarsType.BuiltFrom == PeriodType.Tick && Time[0] < startTime) || (Bars.BarsType.BuiltFrom == PeriodType.Minute && Time[0] <= startTime)
  return;

This would be the easiest solution. If you want to use that in Replay Mode, then you replace DateTime.Now with the method Now as shown above.

Reply With Quote
  #10 (permalink)
 humy65 
Haifa/Israel
 
Experience: Beginner
Platform: NinjaTrader
Trading: Stocks
Posts: 15 since Mar 2012
Thanks Given: 3
Thanks Received: 2



Fat Tails View Post
You cannot set the lookback of the chart from the inidcator, and it is not possible to have different values for different instruments.

What you can do is simply check for a start date /start time when OnBarUpdate() is running. For example, if you trade ES and today's session started at 4:30 Eastern Time yesterday, you simply add three lines in the beginning of OnBarUpdate():
 
Code
DateTime startTime =  DateTime.Now.AddDays(-1).Date. AddHours(16).AddMinutes(30);
if((Bars.BarsType.BuiltFrom == PeriodType.Tick && Time[0] < startTime) || (Bars.BarsType.BuiltFrom == PeriodType.Minute && Time[0] <= startTime)
  return;

This would be the easiest solution. If you want to use that in Replay Mode, then you replace DateTime.Now with the method Now as shown above.

Sure...though start of session should be derived from the instrument and not as a constant... Thanks much !!!!

Started this thread Reply With Quote
The following user says Thank You to humy65 for this post:





Last Updated on October 7, 2012


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts