Noob OnBarUpdate() question - futures io
futures io futures trading



Noob OnBarUpdate() question


Discussion in NinjaTrader

Updated by SetFreeByTruth
    1. trending_up 4,229 views
    2. thumb_up 1 thanks given
    3. group 2 followers
    1. forum 5 replies
    2. attach_file 0 attachments




Welcome to futures io: the largest futures trading community on the planet, with well over 100,000 members
  • Genuine reviews from real traders, not fake reviews from stealth vendors
  • Quality education from leading professional traders
  • We are a friendly, helpful, and positive community
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts
  • We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

(If you already have an account, login at the top of the page)

 
Search this Thread
 

Noob OnBarUpdate() question

(login for full post details)
  #1 (permalink)
Minneapolis Minnesota
 
 
Posts: 5 since Mar 2011
Thanks: 2 given, 0 received

I have years of MT4 programming experience but am brand-new to NinjaTrader.

When does the OnBarUpdate() strategy event fire? I would expect it to fire whenever the current bar is updated, similiar to MT4's start() function, but when I load my test strategy it immediately fires for every historical bar in the chart. I added some debug lines to display Time[0] for each call to OnBarUpdate() and it's clearly being called hundreds of times as there are hundreds of bars on my 1-Min chart. This all happens within 1-2 seconds of enabling the strategy.

Am I loading the strategy incorrectly? It's behaving as if I'm doing a backtest, not a forward test. Again, for those familiar with MT4, I'm trying to duplicate MT4's start() functionality, which fires on each new incoming tick.

Thank you!

Reply With Quote

Can you help answer these questions
from other members on futures io?
Evening session trading
NinjaTrader
Horizontal Line Indicator
Platforms and Indicators
Need a near crosses scan help for TOS
ThinkOrSwim
OPEN_CLOSE_DOTS
ThinkOrSwim
How to place NT8 indicator output into a grid, under each bar?
NinjaTrader
 
 
(login for full post details)
  #3 (permalink)
Dallas, TX
 
Experience: Beginner
Platform: Ninjatrader
Broker: Zen-Fire
Trading: ZN, 6E
 
gulabv's Avatar
 
Posts: 286 since May 2010
Thanks: 161 given, 167 received


You need to set the CalculateOnBarClose property to TRUE in the Initialize() method of the indicator/strategy for OnBarUpdate() to fire once your tick/range/minute/renko/etc. bar closes otherwise this event will fire for each incoming tick of data...

Reply With Quote
 
(login for full post details)
  #4 (permalink)
Minneapolis Minnesota
 
 
Posts: 5 since Mar 2011
Thanks: 2 given, 0 received

Hello gulabv,

Thank you for the reply. I am already setting CalculateOnBarClose to TRUE in the Initialize method as you recommended.

The problem is: when I first load the strategy, OnBarUpdate() is getting called for every pre-existing historical bar in the chart. In other words: not just for new incoming ticks, but also for every bar already on the chart.

Again, it's acting like it's in "backtest" mode. I want it to process only future ticks, not past ticks. I must be missing something very elementary.

Kind regards...

Reply With Quote
 
(login for full post details)
  #5 (permalink)
Dallas, TX
 
Experience: Beginner
Platform: Ninjatrader
Broker: Zen-Fire
Trading: ZN, 6E
 
gulabv's Avatar
 
Posts: 286 since May 2010
Thanks: 161 given, 167 received

Check out the help in NT for the keyword HISTORICAL

Indicates if the NinjaScript object is running on historical data. With a strategy, when running a backtest, this property will always return true. When running a live strategy, this property will be true until the strategy starts processing real-time data. The property can be of value for many different applications.


1. Filtering out historical data for real-time strategies that does not require any historical data to initialize.


Property Value
This property returns true if the strategy is running on historical data; otherwise, false.


Syntax
Historical


Property Of
Custom Indicator, Custom Strategy


Examples
protected override void OnBarUpdate()
{
// Only run on real-time data
if (Historical)
return;
}

Reply With Quote
The following user says Thank You to gulabv for this post:
 
(login for full post details)
  #6 (permalink)
Minneapolis Minnesota
 
 
Posts: 5 since Mar 2011
Thanks: 2 given, 0 received

Now we're talkin'! That was exactly what I needed. Thank you!

Reply With Quote


futures io Trading Community Platforms and Indicators NinjaTrader > Noob OnBarUpdate() question


March 30, 2011


Upcoming Webinars and Events
 

Live Video Panel: Ask Me Anything w/Ironbeam Brokerage

Aug 6
     



Copyright © 2020 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
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.
no new posts