NexusFi: Find Your Edge


Home Menu

 





OnBarUpdate() in a loop ?


Discussion in NinjaTrader

Updated
    1. trending_up 303 views
    2. thumb_up 3 thanks given
    3. group 3 followers
    1. forum 3 posts
    2. attach_file 0 attachments




 
 

OnBarUpdate() in a loop ?

 
 watomi 
Vienna
 
Experience: Intermediate
Platform: NinjaTrader
Trading: Futures
Posts: 5 since Oct 2020
Thanks Given: 5
Thanks Received: 0

Hi,

I want to call OnBarUpdate() multiple times, like having a Shell/Loop above it. Let me explain what I try to achieve.

I want to set a StartTime = 10:00 and EndTime == 16:00. In that period, I take some statistics for each bar. Once this is done for the entire Time Frame, let’s say 5 days (5 sessions and I expect to get 5x “Bars.IsFirstBarOfSession”), I want to collect the same statistics for StartTime = 11:00 and EndTime = 16:00 for every bar again.

I can achieve this with Properties and set the StartTime and EndTime BUT I would need to run this manually and make changes to the Properties manually, let’s say 5 times for StartTime = 10:00, 11:00, 12:00, 13:00 etc.

But instead of having the time set manually, I want to have the time set Automatically to 10:00, run NT completely thru all Bars, then automatically set to 11:00, run again OnBarUpdate() thru all Bars.

Note: i might even want to change other variables/properties. So its basically similar to NT Strategy Analyzer - Optimizer, where multiple iterations run.

For( int i=0; i < 5; i++ )
{

switch( i)
{
Case 0:
StartTime = 10:00;
EndTime = 16:00;
Case 1:
StartTime = 11:00;
EndTime = 16:00
Case 3:
StartTime = 12:00;
EndTime = 16:00
Etc.
}

OnBarUpdate()
{
If( ToTime(Time[0]) > ToTime(StartTime) && ToTime(Time[0]) <= ToTime(EndTime) )
{
// collecting my statistics
}
// but also outside i want to collect information/statistics
}
}

How can I achieve this best; do i need to write a Windows script to achieve this?

Maybe this has been discussed already somewhere and someone can send me the link of it.

Any help is much appreciated !

Started this thread

Can you help answer these questions
from other members on NexusFi?
My NT8 Volume Profile Split by Asian/Euro/Open
NinjaTrader
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
ZombieSqueeze
Platforms and Indicators
Exit Strategy
NinjaTrader
New Micros: Ultra 10-Year & Ultra T-Bond -- Live Now
Treasury Notes and Bonds
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Get funded firms 2023/2024 - Any recommendations or word …
61 thanks
Funded Trader platforms
39 thanks
NexusFi site changelog and issues/problem reporting
26 thanks
The Program
18 thanks
Battlestations: Show us your trading desks!
18 thanks
 
 
sam028's Avatar
 sam028 
Site Moderator
 
Posts: 3,765 since Jun 2009
Thanks Given: 3,825
Thanks Received: 4,629

OnBarUpdate() is called, well, when a bar is updated, you can't call it by yourself.
You have to find another way to collect your stats.



watomi View Post
Hi,

I want to call OnBarUpdate() multiple times, like having a Shell/Loop above it. Let me explain what I try to achieve.

I want to set a StartTime = 10:00 and EndTime == 16:00. In that period, I take some statistics for each bar. Once this is done for the entire Time Frame, let’s say 5 days (5 sessions and I expect to get 5x “Bars.IsFirstBarOfSession”), I want to collect the same statistics for StartTime = 11:00 and EndTime = 16:00 for every bar again.

I can achieve this with Properties and set the StartTime and EndTime BUT I would need to run this manually and make changes to the Properties manually, let’s say 5 times for StartTime = 10:00, 11:00, 12:00, 13:00 etc.

But instead of having the time set manually, I want to have the time set Automatically to 10:00, run NT completely thru all Bars, then automatically set to 11:00, run again OnBarUpdate() thru all Bars.

Note: i might even want to change other variables/properties. So its basically similar to NT Strategy Analyzer - Optimizer, where multiple iterations run.

For( int i=0; i < 5; i++ )
{

switch( i)
{
Case 0:
StartTime = 10:00;
EndTime = 16:00;
Case 1:
StartTime = 11:00;
EndTime = 16:00
Case 3:
StartTime = 12:00;
EndTime = 16:00
Etc.
}

OnBarUpdate()
{
If( ToTime(Time[0]) > ToTime(StartTime) && ToTime(Time[0]) <= ToTime(EndTime) )
{
// collecting my statistics
}
// but also outside i want to collect information/statistics
}
}

How can I achieve this best; do i need to write a Windows script to achieve this?

Maybe this has been discussed already somewhere and someone can send me the link of it.

Any help is much appreciated !


Success requires no deodorant! (Sun Tzu)
Follow me on Twitter
 
 reach4thelasers 
London, United Kingdom
 
Experience: Advanced
Platform: Ninjatrader
Trading: Futures Algo Trading
Posts: 18 since Feb 2017
Thanks Given: 11
Thanks Received: 11


You could do what you want with a BarsRequest object.

https://ninjatrader.com/support/helpGuides/nt8/NT%20HelpGuide%20English.html?barsrequest.htm

This would allow you to request a number of bars between certain times:

you would pass in the times as DateTime.Today.AddHours(11) [datetime today refers to Midnight today. Add 11 hours to get 11am today)

This would return you a Bars object which you can loop through as shown on the docs

 
 watomi 
Vienna
 
Experience: Intermediate
Platform: NinjaTrader
Trading: Futures
Posts: 5 since Oct 2020
Thanks Given: 5
Thanks Received: 0

Thx for the info. I found a way.

Started this thread

 



Last Updated on May 26, 2023


© 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