Testing precision in NT
15 replies
xlhuang1995
8 years ago #115059
Hello folks,
I don’t know if there is any of you backtesting strategies generated by SQ in NT. What I’ve found is that, when retesting strategies in SQ, it’s filling orders at the precision you choose (tick simualtion, 1 min, selected TF, etc.), but checking entry/exit conditions only when a bar is closed(M1, M5, M15, according to the TF of the strategy).
If you don’t get what I am saying, let’s say, you are testing a simple M15 RSI reverse strategy which uses stop orders for entry, with 1min testing precision. SQ will check if RSI touches 70/30 every 15 minutes, but check if your stop order can be filled every 1 min.
I don’t know if SQ is designed to do so, or whatever. The problem is, however, after we export the strategy to NT, we can only choose to run it “Calculated on Bar Close” or not.
If we choose YES, NT will then check both entry conditions and order fills tick by tick.
If we choose NO, neither will be done tick by tick, but bar by bar.
No matter what we choose, the strategy will not work exactly as how it worked in SQ. I have to add lines of codes to the strategy to make it generate the same trades between SQ and NT.
I am wondering if there is actually someone who can get the same test results by simply following the instructions of how to install SQ for NT.
Wasn’t SQ designed for easy exports of strategies? Why do I have to make these efforts which could easily be fixed on the software itself?
tomas262
8 years ago #136629
Hello,
the NT backtesting engine is supposed to evaluate strategy only on bar close as shown here https://ninjatrader.com/support/helpGuides/nt7/?discrepancies_real_time_vs_bac.htm
xlhuang1995
8 years ago #136641
Yeah that’s true. But in realtime trading, you can choose to Calculate on Bar Close or not. In this case, test results from SQ cannot be used because it only fill your orders tick by tick but not process entry condition.
Also in backtesting you can add what NT called Intrabar Granularity in your codes to provide intrabar fills.
mabi
8 years ago #136647
What code did you add ?
tomas262
8 years ago #136651
Helllo,
thanks for suggestions. NT Intrabar Granularity tweak could be added to SQ4 I will forward this to developers. For realtime trading you need to maintain same conditions and precision (evaluating on bar close) as are in SQ3. You are always using “Selected Timeframe precision” with NinjaTrader backtesting engine and historical data imported from NT
dirkdiggler
7 years ago #136975
What code did you add ?
If you want to get good back test fill quality you can make these modifications.
1. Replace the SQManagedStrategy with the attached text.
2. Add this code to Initialize
protected override void Initialize() { Add(PeriodType.Range,1); }
3. Add this code to OnBarUpdate
protected override void OnBarUpdate() { if (BarsInProgress !=0) return; }
4. Look in the code for BarsSinceEntry() and change it to BarsSinceEntry(0,””,0)
You will now get back test quality on 1 period range bars, faster than 1 period tick, as long as you have tick data in the Ninja database.
tomas262
7 years ago #136988
Great, thanks for sharing!
mabi
7 years ago #137480
Just wanna add that i have this weekend tested 5 supposedly good strategies generated on SQ with Market replay data on the same period ( 1 year) . The real result are very different . Tick precision is needed indeed.
Ninjatrader is just a trading platform to execute trades width .SQ is supposedly a strategy generator that can create strategies for use width Ninjatrader. To me it seems they do not perform at all in real market as tested .
Is there a way to Export /Convert tick data from NInjatrader to Metatrader format so that tick precision can be used for testing in SQ to sort out the bad ones ? It is needed indeed or can SQ team make a conversion tool like this .
dirkdiggler
7 years ago #137497
Mabi, the method I posted above will give you near identical results to market replay. It will save you some time.
mabi
7 years ago #137498
Mabi, the method I posted above will give you near identical results to market replay. It will save you some time.
I really appreciate that. Would like to filter them before they get to Ninjatrader thought. Thats why i nagged as a reminder. The only thing said about this problem before is that it ” Can” be implemented in SQ4 but not that they have any plan to do it.
DanT
7 years ago #137599
Hello,
I generated some strategies at 10 min, the data feed that I used is 10 min fron Ninja Trader.
Same problem in StrategyQuant and on NinjaTrader backtest, many of trades (70-80%) are closed on the same bar.
How can I do an accurate backtest? I’m newbie on SQ and on NT 🙂
Thanks,
Dan
tomas262
7 years ago #137620
Hello,
I generated some strategies at 10 min, the data feed that I used is 10 min fron Ninja Trader.
Same problem in StrategyQuant and on NinjaTrader backtest, many of trades (70-80%) are closed on the same bar.
How can I do an accurate backtest? I’m newbie on SQ and on NT 🙂
Thanks,
Dan
Hi Dan, replied you about this via email
mabi
7 years ago #137628
Hello,
I generated some strategies at 10 min, the data feed that I used is 10 min fron Ninja Trader.
Same problem in StrategyQuant and on NinjaTrader backtest, many of trades (70-80%) are closed on the same bar.
How can I do an accurate backtest? I’m newbie on SQ and on NT 🙂
Thanks,
Dan
This is a problem in regards to Ninjatrader . They could have fixed that 10 years ago but never did. It is no money in to fixing this but alot of money in not fixing it . All “snake” Vendors use this issue to show their fake trading results in what ever system they may be selling just a few inside bar trades can destroy you system and they can be hidden aswell especially at close of day.There is ways to fix this as above post from dirkdiggler . Or you can buy an intrabar addon for ninjatrader at backtestdata.com that works with historical backtesting or optimization for all thirdparty strategies. The best test is still market replay or live incubation. When using SQ and NInjatrader data u have to build strategies that do not have inside bar trades at all.
DanT
7 years ago #137641
If you want to get good back test fill quality you can make these modifications.
1. Replace the SQManagedStrategy with the attached text.
2. Add this code to Initialize
protected override void Initialize() { Add(PeriodType.Range,1); }3. Add this code to OnBarUpdate
protected override void OnBarUpdate() { if (BarsInProgress !=0) return; }4. Look in the code for BarsSinceEntry() and change it to BarsSinceEntry(0,””,0)
You will now get back test quality on 1 period range bars, faster than 1 period tick, as long as you have tick data in the Ninja database.
Hi,
I do steps 1-3, but 4 not, because in my strategy I don’t have any “BarsSinceEntry()”. Can you tell me how can I do this, and where I must add this condition?
Thanks,
Dan
dirkdiggler
7 years ago #137643
Your strategy may not include the BarsSinceEntry method in its logic. But if it does you can put 0,””,0 between the ().
mabi
7 years ago #137652
Marketreplay.net have a sale on their pro version for Ninjatrader. 1/3 of the price i got it for. Supports batch download of continous contracts. I use it as incubation of a strategy . Test up to end of 2015 and run it on Market replay remaining 6 months and then live data for a week and then i try it with real money.
Viewing 15 replies - 1 through 15 (of 15 total)