![]() |
This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com
|
|||||||
| Strategy Development Support for the development of custom automated trading strategies using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 | ||
|
Senior Member
Join Date: Apr 2008
Posts: 164
Thanks: 2
Thanked 3 times in 3 posts
|
Hi guys, got a strange one for you.
I have a large strategy, which has been loading 3 additional timeframes. It has been months in development and is working fine. This week I had to add another timeframe, a Day bar series of the same instrument as the chart. I'm doing it like this: if (aTR_Filter_Enabled) { Add(PeriodType.Day,1); } The trouble is, when this is activated (when the user-input 'aTR_Filter_Enabled' is true, and the Day timeframe is added, OnBarUpdate() never executes. * There are no errors in the Log tab of the Control Centre. * I have print statements in the OnStartUp() showing me what bars series I have, the output is this (which proves OnStartUp() is being executed: Quote:
I've had a look in the Trace file. Here is a large slab, but there is an Exception down the bottom hopefully you can help me with. Quote:
Thanks in advance, saltminer |
||
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
|
Hi saltminer, how much data are you loading up to run the strategy? Please remember that the BarsRequired would need to be satisfied for all series involved for the OnBarUpdate() to be called from the strategy / script.
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Senior Member
Join Date: Apr 2008
Posts: 164
Thanks: 2
Thanked 3 times in 3 posts
|
Ah, thanks. Changing the BarsRequired down to 2 got it going.
saltminer |
|
|
|
|
|
#4 | |
|
Senior Member
Join Date: Apr 2008
Posts: 164
Thanks: 2
Thanked 3 times in 3 posts
|
Ah, not so fast.
OnBarUpdate() is now called once, but never again. There are no errors shown in the Log tab. There is nothing dubious in the Trace file. I have print statments throughout OnBarUpdate() and I can see I am getting all the way through to the end. I should see a call for every bar on the chart yet to go, but I'm not. It is quite perplexing. No trades are taking place on this first execution. Here is the data from within this first-and-only OnBarUpdate() Quote:
saltminer |
|
|
|
|
|
|
#5 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
|
Is this still being run with BarsRequired = 2? How much data are you loading up here? You could see an OnBarUpdate() only for the bars were BarsRequired for all your series is satisfied, for the others it would not be called, so not even a single bars object OnBarUpdate(). If you email me the script and setup I will gladly give it a run here, too and compare.
Also, if you comment out the day - it would work as you expect still, correct?
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#6 |
|
Senior Member
Join Date: Apr 2008
Posts: 164
Thanks: 2
Thanked 3 times in 3 posts
|
Hi Bertrand,
in the printout below there is visible the Count of all bar series. Loading up is 13 days (more than the 2 required) and then hundreds of everything else. I should see hundreds of OnBarUpdate() calls but I only get one. I have now commented out the Day bar series and it still remains the same. It is so strange, as this worked earlier in the week. In many years of programming for Ninja I've never seen just one OnBarUpdate() call. I tried a different strategy and it worked fine. I'm going to try a previous build of this strategy to see if I can get it running again. If you've never seen this behaviour of a single OnBarUpdate() call, then fine, I've managed something to create something new. If you have, let me know what a way out of this situation might be. Cheers, saltminer |
|
|
|
|
|
#7 | ||||
|
Senior Member
Join Date: Apr 2008
Posts: 164
Thanks: 2
Thanked 3 times in 3 posts
|
While we're on this topic, I've got another strategy on daily bars that also loads Monthly bars and Minute bars.
I have a question about the number of bars Ninja loads in each bar series. I seem to only be able to get 13 months in the monthly timeframe loaded. I am using ES ##-## so the data goes back a long way. I wrote a stats printout, and set the chart to look bar 2000 bars. This is what it loaded : Quote:
If I change the chart to Monthly bars, to force Ninja to load monthly bars, I get this: Quote:
Why? Ninja has those months in its cache. It is able to download them on demand from the live data connection. Yet it doesn't load them into the strategy. I need more than 13 bars in a bar series. Why does it do this, and how can I force the loading of more bars? ** UPDATE.** Using the CustomRange, the bar series all load to the same date. That's more like it! Quote:
Quote:
Cheers, saltminer |
||||
|
|
|
|
|
#8 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
|
Hi saltminer, thanks for that detailed post and your efforts - would you forwarding me the test script to support and also emailing me which broker / data-provider you're using here in testing so I could replicate the exact setup in my testing as well?
I will then attempt to reproduce here on our end and update you. Thanks again,
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#9 |
|
Junior Member
Join Date: Dec 2012
Posts: 2
Thanks: 0
Thanked 0 times in 0 posts
|
I have encountered the same issue. I tried to comment out the add day bar line and it still never hits my onbarupdate(). I attach my debugger (visual studio) to the worker process and put a break point in the OnBarUpdate() and it never hits. Below are my initialize and onbarupdate methods. I am running through the Strategy Analyzer against SPY using Kinetick as the data provider. I have min bars set to 20 and time frame 1/1/2012 - 12/18/2012. Please let me know if you need more information to replicate. Thanks in advance, ~Joe
" /// <summary> /// This method is used to configure the strategy and is called once before any strategy method is called. /// </summary> protected override void Initialize() { //Add day data inside Add(this.Instrument.FullName, PeriodType.Day,1); ExitOnClose = true; //Cancels all open orders on close of designated period this.EntriesPerDirection = 1; // CalculateOnBarClose = true; } /// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { if (BarsInProgress == 1) return; //Nothing to process on Daily bars EnterLong(10,"test"); }" |
|
|
|
|
|
#10 | |
|
NinjaTrader Customer Service
Join Date: Apr 2010
Location: Denver, CO, USA
Posts: 4,794
Thanks: 160
Thanked 568 times in 559 posts
|
Quote:
You will want to add a CurrentBars check to your OnBarUpdate method to ensure that your added series has enough data Code:
if(CurrentBars[0] < BarsRequired || CurrentBars[1] < BarsRequired) return;
Matthew
NinjaTrader Customer Service |
|
|
|
|
|
|
#11 |
|
Junior Member
Join Date: Dec 2012
Posts: 2
Thanks: 0
Thanked 0 times in 0 posts
|
Thank you for the reply, it led me to figure out I did not have enough historical data downloaded for my test period. Once I downloaded more historical data I was able to hit OnBarUpdate() and could move on to more interesting issues
Cheers, Joe |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| when is OnBarUpdate() called when the "CalculateOnBarClose" property is set to true? | clearpicks | General Programming | 1 | 12-12-2010 10:15 AM |
| Initialize() called more than once before OnBarUpdate()? | aascotty | Strategy Development | 4 | 02-19-2010 04:21 AM |
| Indicator for last bar not drawing (OnBarUpdate not called) | Anagoge | Indicator Development | 1 | 09-21-2008 02:29 PM |
| Indicator's OnBarUpdate() is called twice | mgbloomfield | Automated Trading | 1 | 04-20-2008 12:07 AM |
| OnBarUpdate() - never seems to be called? | altrader | Miscellaneous Support | 5 | 03-10-2008 07:09 AM |