Advanced managed orders ninjascript with intrabar granularity - futures io
futures io futures trading



Advanced managed orders ninjascript with intrabar granularity


Discussion in NinjaTrader

Updated
    1. trending_up 1,976 views
    2. thumb_up 4 thanks given
    3. group 2 followers
    1. forum 7 posts
    2. attach_file 2 attachments




Welcome to futures io: the largest futures trading community on the planet, with well over 125,000 members
  • 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 and simple.

-- Big Mike, Site Administrator

(If you already have an account, login at the top of the page)

 
Search this Thread
 

Advanced managed orders ninjascript with intrabar granularity

(login for full post details)
  #1 (permalink)
Atlanta + GA/USA
 
Experience: Intermediate
Platform: NinjaTrader
Trading: Forex
 
iPipper427's Avatar
 
Posts: 34 since Jul 2012
Thanks: 57 given, 14 received

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

Started this thread Reply With Quote

Journal Challenge February 2021 results (so far):
Competing for $1500 in prizes from Topstep
looks_oneSBtrader82 's Trading Journalby SBtrader82
(169 thanks from 31 posts)
looks_twoJust BEING a Trader: Letting Go!!by iqgod
(116 thanks from 33 posts)
looks_3Wisdom is Emptinessby Mtype
(68 thanks from 25 posts)
looks_4Deetee’s DAX Trading Journal (time based)by Deetee
(31 thanks from 17 posts)
looks_5Journal for peanuts1956by peanuts1956
(23 thanks from 13 posts)
 
 
(login for full post details)
  #3 (permalink)
McKinney, TX
 
Experience: Intermediate
Platform: ThinkOrSwim, NinjaTrader
Broker: TOS & Rithmic
Trading: The indexes, ES, YM, NQ & RTY
 
Posts: 171 since Aug 2012
Thanks: 216 given, 157 received



iPipper427 View Post
I have searched already for a definitive solution to no avail... Help or a point in the right direction appreciated..

I am Using OnOrderUpdate() and OnExecution().
It seems this should be a simple thing to do.

Albeit I am a novice programmer

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.

Reply With Quote
The following user says Thank You to dynoweb for this post:
 
(login for full post details)
  #4 (permalink)
Atlanta + GA/USA
 
Experience: Intermediate
Platform: NinjaTrader
Trading: Forex
 
iPipper427's Avatar
 
Posts: 34 since Jul 2012
Thanks: 57 given, 14 received

@dynoweb

Thanks so much for this...

One thing when I loaded it into vs2012 it immediately flagged this

 
Code
// Change short close order to close if stop trigger (closed above channel)
    		if (null != closeOrderShortStop)
			{
				if (closeOrderShort == null
					&& High[0] > channelHigh
					&& barNumberSinceFilled != barNumberSinceFilled
					)


barNumberSinceFilled != barNumberSinceFilled.....is a comparison to the same variable which will always be false

Started this thread Reply With Quote
 
(login for full post details)
  #5 (permalink)
Atlanta + GA/USA
 
Experience: Intermediate
Platform: NinjaTrader
Trading: Forex
 
iPipper427's Avatar
 
Posts: 34 since Jul 2012
Thanks: 57 given, 14 received

While perusing your code..
In one of your if statements can't remember which as I changed then later thought to post it..

if(null != someEntryOrder)

I changed to

if(someEntryOrder != null)

Never tested in code the reverse order of the null check...
Not sure if it makes a difference..

Also I am using managed orders not unmanaged...
However am considering using unmanaged as it removes certain limitations.

Will post code and screenshot this evening of my problem..Hard to move forward without knowledge of accurate(as possible) backtesting.

Started this thread Reply With Quote
 
(login for full post details)
  #6 (permalink)
Atlanta + GA/USA
 
Experience: Intermediate
Platform: NinjaTrader
Trading: Forex
 
iPipper427's Avatar
 
Posts: 34 since Jul 2012
Thanks: 57 given, 14 received

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!!!

Primary is 60 min EURUSD;

Screenshot and Code zip;




Attached Files
Register to download File Type: zip LongEntryTest.zip (1.7 KB, 25 views)
Started this thread Reply With Quote
The following 2 users say Thank You to iPipper427 for this post:
 
(login for full post details)
  #7 (permalink)
McKinney, TX
 
Experience: Intermediate
Platform: ThinkOrSwim, NinjaTrader
Broker: TOS & Rithmic
Trading: The indexes, ES, YM, NQ & RTY
 
Posts: 171 since Aug 2012
Thanks: 216 given, 157 received


iPipper427 View Post
While perusing your code..
In one of your if statements can't remember which as I changed then later thought to post it..

if(null != someEntryOrder)

I changed to

if(someEntryOrder != null)

Never tested in code the reverse order of the null check...
Not sure if it makes a difference..

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.

Reply With Quote
 
(login for full post details)
  #8 (permalink)
McKinney, TX
 
Experience: Intermediate
Platform: ThinkOrSwim, NinjaTrader
Broker: TOS & Rithmic
Trading: The indexes, ES, YM, NQ & RTY
 
Posts: 171 since Aug 2012
Thanks: 216 given, 157 received


iPipper427 View Post
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!!!

Primary is 60 min EURUSD;

Screenshot and Code zip;




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.

Reply With Quote
The following user says Thank You to dynoweb for this post:


futures io Trading Community Platforms and Indicators NinjaTrader > Advanced managed orders ninjascript with intrabar granularity


Last Updated on June 4, 2013


Upcoming Webinars and Events
 

NinjaTrader Indicator Challenge!

Ongoing
 

Journal Challenge w/$1500 prizes from Topstep!

February
 

Battlestations! Show us your trading desk - $1,500 in prizes!

March
 

Call Option Buying: The New Pain Trade? w/Carley Garner

Elite only
     



Copyright © 2021 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
All information is for educational use only and is not investment advice.
There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
no new posts