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)
Advanced managed orders ninjascript with intrabar granularity
I have searched already for a definitive solution to no avail... Help or a point in the right direction appreciated..
I have coded a simple strat that subtracts xpips from the previous close to enter a long..opposite for shorts.
Instrument: EURUSD;
Primary Time Frame: 60min;
Granularity 1min;
Price based on last;
All works well when limit and stop are not in same Primary Time Frame, however when the stop and limit fall within the primary price range it enters and exits same bar irregardless of which should have hit in proper order..
Example:
Open is the high of the bar and close is the low... no price zig zag intrabar just down I am filled on long trade yet profit target is hit same bar...no way could have happened...
Very inaccurate test..
I have browsed futures.io (formerly BMT) and also NT forums...
It appears others have had same issue yet I haven't found a viable solution..
If anyone knows how to work around this with more of an accurate way to BACKTEST Please inform!!!
I am Using OnOrderUpdate() and OnExecution().
It seems this should be a simple thing to do.
Albeit I am a novice programmer
If needed I could post code
Can you help answer these questions from other members on NexusFi?
Broker: TD Ameritrade (soon to be Schwab) & NinjaTrader
Trading: The indexes, ES, YM, NQ & RTY
Posts: 171 since Aug 2012
Thanks Given: 216
Thanks Received: 157
Hi, I'll first start by saying if you're a novice programmer you're taking on a fairly complex set of code. I'm an experienced programmer and have done several of my latest strategies using the OnOrderUpdate/Execution events. If you want to see an example of my use of those events, check out the battle of the bots and do a search for non-image attachments and grab my strategy. Even with the complexities that I've put into my strategy, I still think there are a couple of additional items that I'm missing in my code. For example, when I get an event, I change values of variables that on the next tick update the code of the previous tick update may not have fully executed.
As an alternative use the managed orders. This should simplify your code. Otherwise, hopefully my code will help give you some answers.
This is some sample code I put together to demonstrate....What I feel is a known issue...
All I am Looking for is proper way to get accurate test using this simple idea..
A Base workaround if you will for backtesting purposes...ie no Live trading!!!
Broker: TD Ameritrade (soon to be Schwab) & NinjaTrader
Trading: The indexes, ES, YM, NQ & RTY
Posts: 171 since Aug 2012
Thanks Given: 216
Thanks Received: 157
the order doesn't make any difference in this case. In a prior programming language using the null first avoided a null pointer error. It's been so long ago, that I don't remember when it mattered.
Broker: TD Ameritrade (soon to be Schwab) & NinjaTrader
Trading: The indexes, ES, YM, NQ & RTY
Posts: 171 since Aug 2012
Thanks Given: 216
Thanks Received: 157
I haven't spent a lot of time looking at this, but first impressions are that the exits are happening because the stops are 150 which is within the range on the bar they open the position. On back testing data I think the tick price movement within the bar is summarized so it knows it's open, high and low and close, but not when within that bar it was at a particular price. That being the case on back testing, assume the worse, it triggers the long buy on the high price and the short got hit when the price was at the lower portion of the bar. If you use market orders, the approximate entry price on back testing is the bar open price and close price is the open of the next bar. When you add multi-time frame bar data, you need to make sure which bar triggered the on bar update and ignore code based on the other time frame.
Just for fun, extend your longStopLoss to 750 and see how it changes the results.