NexusFi: Find Your Edge


Home Menu

 





Noob OnBarUpdate() question


Discussion in NinjaTrader

Updated
    1. trending_up 6,181 views
    2. thumb_up 1 thanks given
    3. group 2 followers
    1. forum 5 posts
    2. attach_file 0 attachments




 
Search this Thread
  #1 (permalink)
SetFreeByTruth
Minneapolis Minnesota
 
Posts: 5 since Mar 2011
Thanks Given: 2
Thanks Received: 0

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

 
  #3 (permalink)
 
gulabv's Avatar
 gulabv 
Dallas, TX
 
Experience: Beginner
Platform: Ninjatrader
Broker: Zen-Fire
Trading: ZN, 6E
Posts: 286 since May 2010
Thanks Given: 161
Thanks Received: 169


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
  #4 (permalink)
SetFreeByTruth
Minneapolis Minnesota
 
Posts: 5 since Mar 2011
Thanks Given: 2
Thanks Received: 0

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
  #5 (permalink)
 
gulabv's Avatar
 gulabv 
Dallas, TX
 
Experience: Beginner
Platform: Ninjatrader
Broker: Zen-Fire
Trading: ZN, 6E
Posts: 286 since May 2010
Thanks Given: 161
Thanks Received: 169

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
Thanked by:
  #6 (permalink)
SetFreeByTruth
Minneapolis Minnesota
 
Posts: 5 since Mar 2011
Thanks Given: 2
Thanks Received: 0

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


Reply With Quote




Last Updated on March 30, 2011


© 2026 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 - Downloads - Top
no new posts