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)
In this thread I'm going to try to achieve something I find useful, and that currently Ninjatrader does not support: having Indicators calculated on real time (COBC false) on a CalculateOnBarClose strategy. NT support says it's not possible, but maybe we, together can achieve it.
My first thoughts:
1) We could achieve this by having a CalculateOnBarClose false strategy. All indicators would be then calculated on realtime, and we could handle COBC entry points by using FirstTickOfBar. Unfortunately backtesting a CalculateOnBarClose false strategy it's not very reliable.
2) We could achieve this by attaching a 1tick chart to the strategy, and discriminating on BarUpdate from the main chart (i.e. 1 minute) and the tick chart using BarsInProgress. So we basically could code two functions to be called in each case i.e OnBarTickUpdate() and OnBarCloseUpdate(). We could now place our code in either function depending on the granularity needed or wanted (i.e entries and trail stops on OnBarCloseUpdate and exits on OnBarTickUpdate). The only issue left is that if we want the main 1 min indicators to be updated with every OnBarTickUpdate() we need to hack something to make it work.
So, I think the way to go is the 2 option. But we need to be able to emulate the COBC false update of the indicators.
What we need is to calculate our own OHLC values for the current bar using tick data, and update the current bar of 1min indicators with them.
We could try this by:
A) Custom coding every single indicator we use in our estrategy, and replacing their use of High[], Low[], Close with our own code.
B) Adding code to the indicator class to handle this through all indicators.
At the moment I'm trying option B, I've tryed to overload the High, Low, Close Dataseries without success but I'll keep looking for a way to achieve this.
I just wanted to open this thread to hear other thoughts or ideas, and to post my advancement.
Cheers,
David.
Can you help answer these questions from other members on NexusFi?
Why don't you simply add a secondary bar series built from 1-tick bars and have that bar series running set to CalculateOnBarClose = true?
Your indicators running on that secondary bar series will then be updated with every incoming tick, and you can use them within your strategy as required.
The only problem that I can see is that NinjaTrader does not support sub-second granularity on historical data, which can falsify a backtest.
Thanks Fat Tails, but the problem I have is that my exit conditions are based in the indicators running on the 1 minute bars, and I can't find a proper translation between those and the ones running in the 1 tick or even 1 second bars.
i.e. If I want to exit when DM[14].DIMinus>XXX on the 1 minute bars, How can I find the equivalent to that in the 1 tick o 1 second bars?
You need to code it. You can take the last known value of DM[14].DiMinus which was calculated from 1 min bars. Then you apply the DM indicator formulae to both the prior values of DM stored by the indicator and the last price retrieved by the 1-tick bar series.
The result is the current intrabar value of the indicator. That is all you need to do.
That was my original idea, but then I got greedy and I though we could be able to somehow overload the high, low, close for the current bar and modify the Indicator class to have that functionality in every indicator...
Well, following Fat Tails advice, I dumped the idea of a general purpose solution and just coded what I needed. A COBC false DM indicator to handle my exits.
Here is the modified DM indicator and an example strategy (which just do print outs of the intrabar DM values)
I'm coding some other indicators that update in realtime even when using strategies with CalculateOnBarClose true.
I've coded so far: SMA, StdDev, DM, Bollinger and MACD indicators. RSI an some other will come soon.
I don't know if any of you guys have a use for them, but I was wondering if this thread was the proper place to upload them or should I place them somewhere else or under a better titled thread.