NexusFi: Find Your Edge


Home Menu

 





Advanced managed orders ninjascript with intrabar granularity


Discussion in NinjaTrader

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




 
Search this Thread

Advanced managed orders ninjascript with intrabar granularity

  #1 (permalink)
 
iPipper427's Avatar
 iPipper427 
Atlanta + GA/USA
 
Experience: Intermediate
Platform: NinjaTrader
Trading: Forex
Posts: 34 since Jul 2012
Thanks Given: 57
Thanks Received: 14

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

Can you help answer these questions
from other members on NexusFi?
Request for MACD with option to use different MAs for fa …
NinjaTrader
ZombieSqueeze
Platforms and Indicators
My NT8 Volume Profile Split by Asian/Euro/Open
NinjaTrader
NexusFi Journal Challenge - April 2024
Feedback and Announcements
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Retail Trading As An Industry
58 thanks
Battlestations: Show us your trading desks!
55 thanks
NexusFi site changelog and issues/problem reporting
48 thanks
What percentage per day is possible? [Poll]
31 thanks
GFIs1 1 DAX trade per day journal
29 thanks

  #3 (permalink)
 dynoweb 
McKinney, TX
 
Experience: Intermediate
Platform: ThinkOrSwim, NinjaTrader
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



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.

Follow me on Twitter Reply With Quote
The following user says Thank You to dynoweb for this post:
  #4 (permalink)
 
iPipper427's Avatar
 iPipper427 
Atlanta + GA/USA
 
Experience: Intermediate
Platform: NinjaTrader
Trading: Forex
Posts: 34 since Jul 2012
Thanks Given: 57
Thanks Received: 14

@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
  #5 (permalink)
 
iPipper427's Avatar
 iPipper427 
Atlanta + GA/USA
 
Experience: Intermediate
Platform: NinjaTrader
Trading: Forex
Posts: 34 since Jul 2012
Thanks Given: 57
Thanks Received: 14

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
  #6 (permalink)
 
iPipper427's Avatar
 iPipper427 
Atlanta + GA/USA
 
Experience: Intermediate
Platform: NinjaTrader
Trading: Forex
Posts: 34 since Jul 2012
Thanks Given: 57
Thanks Received: 14

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
Elite Membership required to download: LongEntryTest.zip
Started this thread Reply With Quote
The following 2 users say Thank You to iPipper427 for this post:
  #7 (permalink)
 dynoweb 
McKinney, TX
 
Experience: Intermediate
Platform: ThinkOrSwim, NinjaTrader
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


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.

Follow me on Twitter Reply With Quote
  #8 (permalink)
 dynoweb 
McKinney, TX
 
Experience: Intermediate
Platform: ThinkOrSwim, NinjaTrader
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


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.

Follow me on Twitter Reply With Quote
The following user says Thank You to dynoweb for this post:





Last Updated on June 4, 2013


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
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.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts