Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
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 for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
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!
Can you help answer these questions from other members on NexusFi?
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...
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.
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;
}