NexusFi: Find Your Edge


Home Menu

 





OnBarUpdate() in a loop ?


Discussion in NinjaTrader

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




 
Search this Thread

OnBarUpdate() in a loop ?

  #1 (permalink)
 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 Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Trade idea based off three indicators.
Traders Hideout
ZombieSqueeze
Platforms and Indicators
MC PL editor upgrade
MultiCharts
Cheap historycal L1 data for stocks
Stocks and ETFs
Quantum physics & Trading dynamics
The Elite Circle
 
  #2 (permalink)
 
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 Reply With Quote
  #3 (permalink)
 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

Reply With Quote
  #4 (permalink)
 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 Reply With Quote




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