Code for range break out strategy - NinjaTrader Programming | futures io social day trading
futures io futures trading


Code for range break out strategy
Updated: Views / Replies:8,745 / 22
Created: by ticker Attachments:0

Welcome to futures io.

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

futures io is the largest futures trading community on the planet, with over 90,000 members. At futures io, our goal has always been and always will be to create a friendly, positive, forward-thinking community where members can openly share and discuss everything the world of trading has to offer. The community is one of the friendliest you will find on any subject, with members going out of their way to help others. Some of the primary differences between futures io and other trading sites revolve around the standards of our community. Those standards include a code of conduct for our members, as well as extremely high standards that govern which partners we do business with, and which products or services we recommend to our members.

At futures io, our focus is on quality education. No hype, gimmicks, or secret sauce. The truth is: trading is hard. To succeed, you need to surround yourself with the right support system, educational content, and trading mentors Ė all of which you can find on futures io, utilizing our social trading environment.

With futures io, you can find honest trading reviews on brokers, trading rooms, indicator packages, trading strategies, and much more. Our trading review process is highly moderated to ensure that only genuine users are allowed, so you donít need to worry about fake reviews.

We are fundamentally different than most other trading sites:
  • We are here to help. Just let us know what you need.
  • We work extremely hard to keep things positive in our community.
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts.
  • We firmly believe in and encourage sharing. The holy grail is within you, we can help you find it.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.

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

Reply
 
Thread Tools Search this Thread
 

Code for range break out strategy

  #11 (permalink)
Elite Member
Fort Collins, Colorado
 
Futures Experience: Intermediate
Platform: NT7
Favorite Futures: ES
 
Posts: 57 since Feb 2011
Thanks: 48 given, 43 received

@NJMAC
Thanks for that. I was about to ask you why you felt the need to do it the way you were suggesting when your post came up! I like the futures.io (formerly BMT) feature of adding the newest while I'm reading....

I didn't perceive the original poster to be asking about server-side orders, but of course, a OCO option is better when the order is placed. Are you suggesting placing the code
 
Code
SubmitOrder(0,OrderAction.Buy,OrderType.Stop, 1, 0, Close[0] + 10 * TickSize, "EntryStopOCO", "BuyStopEntry" );
into the strategy in place of the standard order
 
Code
EnterLong(DefaultQuantity, "");
and in lieu of
 
Code
SetProfitTarget("", CalculationMode.Ticks, 4);
            SetStopLoss("", CalculationMode.Ticks, 4, true);
?

I have not played much with server side orders, so I am interested if this can be slapped into any strategy to enter a OCO.

I should say... I haven't run an NT Strategy live connected to the Broker, and have only used them to backtest and then alert me to place a trade live. From what I think you are saying, the method I used would not place a live stop when the order is sent, but would keep the stop on my machine and enter it only on triggering. Is that correct?


Last edited by fctrader; March 8th, 2012 at 05:37 PM. Reason: last paragraph/question added
Reply With Quote
The following user says Thank You to fctrader for this post:
 
  #12 (permalink)
Elite Member
Atkinson, NH USA
 
Futures Experience: Intermediate
Platform: NinjaTrader 8/TensorFlow
Broker/Data: NinjaTrader Brokerage
Favorite Futures: Futures, CL, ES, ZB
 
NJAMC's Avatar
 
Posts: 1,925 since Dec 2010
Thanks: 2,962 given, 2,294 received


fctrader View Post
@NJMAC
Thanks for that. I was about to ask you why you felt the need to do it the way you were suggesting when your post came up! I like the futures.io (formerly BMT) feature of adding the newest while I'm reading....

I didn't perceive the original poster to be asking about server-side orders, but of course, a OCO option is better when the order is placed. Are you suggesting placing the code
 
Code
SubmitOrder(0,OrderAction.Buy,OrderType.Stop, 1, 0, Close[0] + 10 * TickSize, "EntryStopOCO", "BuyStopEntry" );
into the strategy in place of the standard order
 
Code
EnterLong(DefaultQuantity, "");
and in lieu of
 
Code
SetProfitTarget("", CalculationMode.Ticks, 4);
            SetStopLoss("", CalculationMode.Ticks, 4, true);
?

I have not played much with server side orders, so I am interested if this can be slapped into any strategy to enter a OCO.

I guess in a generic coding format, you would do the following for each Bar/Tick depending upon your desires in your OnBarUpdate():
{
//Calculate BuyPrice & SellPrice for current bar/tick
BuyPrice = your formula for top side Stop
SellPrice = your formula for bottom side Stop

// SetPT & SL using NT functions (Do this before placing the orders belo, if fixed values you can set in your Init() fuction)
...


// Place orders on market (depending upon your Broker, NT might manage locally like your code above)
SubmitOrder(0,OrderAction.Buy,OrderType.Stop, 1, 0, BuyPrice, "EntryStopOCO", "BuyStopEntry" );
SubmitOrder(0, OrderAction.Sell, OrderType.Stop, 1, 0, SellPrice, "EntryStopOCO", "SellStopEntry");

}

Hope that helps. With each Bar or Tick you would update your OCO to reflect what you would consider a breakout (becareful on the Tick as you generate LOTS of order to your broker and market, an statistically you will move your order out before you have a chance to trigger... Morale, be sure to set COBC=True using this approach or know what you are doing).

Nil per os
-NJAMC [Generic Programmer]

LOM WIKI: NT-Local-Order-Manager-LOM-Guide
Artificial Bee Colony Optimization
Reply With Quote
The following user says Thank You to NJAMC for this post:
 
  #13 (permalink)
Elite Member
Fort Collins, Colorado
 
Futures Experience: Intermediate
Platform: NT7
Favorite Futures: ES
 
Posts: 57 since Feb 2011
Thanks: 48 given, 43 received


So, to make sure I'm understanding in regards to the original poster; if he wants to enter a server side order at 9:30 based on his 9:00-9:30 range, he could enter your code into an if statement as follows, (assuming he has specified the stops, as you mentioned)

 
Code
if (ToTime(Time[0]) > ToTime(9, 30, 0) && TradePlaced <1)
			{
// Place orders on market (depending upon your Broker, NT might manage locally like your code above)
                                SubmitOrder(0,OrderAction.Buy,OrderType.Stop, 1, 0, CurrentOpenRangeHigh, "EntryStopOCO", "BuyStopEntry" );
                                SubmitOrder(0, OrderAction.Sell, OrderType.Stop, 1, 0, CurrentOpenRangeLow, "EntryStopOCO", "SellStopEntry");
                                TradePlaced++;
			}
And that would put the orders into the system to trigger when the condition is met, along with a stop and profit target? Are these GTC or Day orders? Can we control for that in the original order? Or, did I miss the object of doing it in the first place?

Reply With Quote
The following user says Thank You to fctrader for this post:
 
  #14 (permalink)
Elite Member
Israel
 
Futures Experience: Intermediate
Platform: NinjaTrader
Broker/Data: pfg
Favorite Futures: eminis
 
Posts: 323 since Jun 2009
Thanks: 6 given, 206 received

The difference is not that in managed approach (demonstrated) are not server side orders, but there are NO orders until after a fact.
To do it in managed approach:
get rangehigh, rangelow and rangemiddle.
Run on 1 min TF and if above middle (if previous was below middle cancel sell order) fire longstop.
The opposite for below middle.
This will guarantee 99.99999999% of execution. I'm willing to miss 0.000000001% of trades. (which will happen if in 1 min the price jumps from below the middle of 30min range to above the high or vs.

Baruch

Reply With Quote
The following user says Thank You to baruchs for this post:
 
  #15 (permalink)
 Vendor: www.traderwerks.com 
Taipei Taiwan
 
Futures Experience: Advanced
Platform: NinjaTrader
Broker/Data: Optimus
Favorite Futures: TW
 
Posts: 693 since Jun 2009
Thanks: 440 given, 440 received

I agree with @baruchs.

I would stay away from unmanaged orders. They are not worth it for something like this. I have done the same thing with managed orders, so I would say it is more risk than it is worth.

Math. A gateway drug to reality.
Reply With Quote
The following 2 users say Thank You to traderwerks for this post:
 
  #16 (permalink)
Elite Member
Atkinson, NH USA
 
Futures Experience: Intermediate
Platform: NinjaTrader 8/TensorFlow
Broker/Data: NinjaTrader Brokerage
Favorite Futures: Futures, CL, ES, ZB
 
NJAMC's Avatar
 
Posts: 1,925 since Dec 2010
Thanks: 2,962 given, 2,294 received


traderwerks View Post
I agree with @baruchs.

I would stay away from unmanaged orders. They are not worth it for something like this. I have done the same thing with managed orders, so I would say it is more risk than it is worth.

I can tell you that Unmanaged orders are complex on the programming side. Best to avoid if you can.

Nil per os
-NJAMC [Generic Programmer]

LOM WIKI: NT-Local-Order-Manager-LOM-Guide
Artificial Bee Colony Optimization
Reply With Quote
 
  #17 (permalink)
Elite Member
Fort Collins, Colorado
 
Futures Experience: Intermediate
Platform: NT7
Favorite Futures: ES
 
Posts: 57 since Feb 2011
Thanks: 48 given, 43 received

Answer
This post has been selected as an answer to the original posters question Answer

I really appreciate all of the explanation of the Managed vs Unmanaged Approach in NT7. I had not thought much about that, and it has inspired me to go into a little more depth in it. So, thanks to all for those comments.

Not to minimize any of that, but to return to the Thread topic, the original poster wanted a simple Timed Range breakout strategy. NJAMC said


NJAMC View Post
Hi,

This is the type of flexibility I was adding to NT using the LOM. This can only be done with unmanaged transactions which require a lot of overhead in NT7. The LOM project on futures.io (formerly BMT) is designed to encapsulate that complexity and give very complex transactions with minimal programming effort.

I will bring your attention to 2 functions:
publicvoid SetAutoSLPTTicks(int m_StopLoss, int m_ProfitTarget,int m_PositionNumber)
publicbool GoMarketBracket(int m_SharesTraded,double low,double high,int m_PositionNumber)


Use the first function in LOM to set your automatic SL & PT in Ticks. The 2nd function would be in your main OnBarUpdate () or OnMarketData() functions to set the High & Low brackets you wish to enter. Once the order is filled, LOM will set the SL & PT correctly depending if the Short or Long was entered based upon your bracket.

Which several people agreed with.

Now that everyone has come full circle to saying that we (less experienced programmers) should avoid using Unmanaged Transactions, which is repeated in NT7 help,


Quoting 
NT7 Help
The Unmanaged approach is reserved for VERY EXPERIENCED programmers. In place of the convenience layer that the Managed approach offered, the Unmanaged approach instead offers ultimate flexibility in terms of order submission and management. This section will discuss some of the basics of working with Unmanaged order methods.

is my code for the breakout strategy valid? It seems to me that it enters the trade (the Order for the Trade) when my PC sees the event (breakout) occur. If I use the SetStopLoss and SetProfitTarget as used in the code, the orders are placed on the server-side concurrently with the entry, as enumerated in NT Help here,


Quoting 
NT7 Help
Closing a Position using a Stop Loss, Trailing Stop and/or Profit Target

You can predefine a stop loss, trailing stop and/or profit target in a strategy by calling the SetStopLoss(), SetTrailStop() or SetProfitTarget() methods from inside the Initialize() method. When these methods are called, they submit live working orders in real-time operation as executions are reported as a result of calling an entry method. Stop and target orders are submitted to the market as soon as fills come in from an entry order. Trailing stop orders are modified in real-time and NOT on the close of a bar. A stop and target order are also tied via OCO (one cancels the other) so if one is filled, the other is automatically cancelled.

So, it seems to me that what the OP is asking for can be done without Unmanaged Transactions.

Mind you, I'm not saying my code is pretty or efficient, just that it works for his purpose. Is that correct?

Reply With Quote
The following user says Thank You to fctrader for this post:
 
  #18 (permalink)
Elite Member
Houston TX
 
Futures Experience: Advanced
Platform: NinjaTrader
Favorite Futures: TF
 
ticker's Avatar
 
Posts: 49 since Oct 2010
Thanks: 63 given, 9 received

Wow guys you are impressive with your in depth knowledge if ninja/coding. I had an emergency come up at home and couldnt keep up with this thread till now.

Thanks @NJAMC and @fctrader for kicking off the responses and everyone for chipping in.

So, I need to improve my code reading skills to understand which of these code bits really answers the question...

Ill read thru a bit and see which one I can figure out.

- Ticker

Reply With Quote
 
  #19 (permalink)
Elite Member
Houston TX
 
Futures Experience: Advanced
Platform: NinjaTrader
Favorite Futures: TF
 
ticker's Avatar
 
Posts: 49 since Oct 2010
Thanks: 63 given, 9 received

Would anyone know how to backtest this strategy? Ive been looking back manually for many many long hours, and thinking there must be a simpler way. I see overall 85% success rate so far, that on the first break of the range it goes for at least one point.

I assume this has to be coded vs being able to use the strategy wizard/backtest?

(I wish Ninja would be more intuitive, but you seem to have to be a coding genius to do anything with this tool)

Reply With Quote
 
  #20 (permalink)
Elite Member
Atkinson, NH USA
 
Futures Experience: Intermediate
Platform: NinjaTrader 8/TensorFlow
Broker/Data: NinjaTrader Brokerage
Favorite Futures: Futures, CL, ES, ZB
 
NJAMC's Avatar
 
Posts: 1,925 since Dec 2010
Thanks: 2,962 given, 2,294 received



ticker View Post
Would anyone know how to backtest this strategy? Ive been looking back manually for many many long hours, and thinking there must be a simpler way. I see overall 85% success rate so far, that on the first break of the range it goes for at least one point.

I assume this has to be coded vs being able to use the strategy wizard/backtest?

(I wish Ninja would be more intuitive, but you seem to have to be a coding genius to do anything with this tool)

If you are not using Replay Testing or Forward live testing, it is unlikely you are getting good results. Just be careful using the results.

Nil per os
-NJAMC [Generic Programmer]

LOM WIKI: NT-Local-Order-Manager-LOM-Guide
Artificial Bee Colony Optimization
Reply With Quote

Reply



futures io > > > > > Code for range break out strategy

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Upcoming Webinars and Events (4:30PM ET unless noted)

Jigsaw Trading: TBA

Elite only

FuturesTrader71: TBA

Elite only

NinjaTrader: TBA

Jan 18

RandBots: TBA

Jan 23

GFF Brokers & CME Group: Futures & Bitcoin

Elite only

Adam Grimes: TBA

Elite only

Ran Aroussi: TBA

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
Trendline break-out strategy Ralph07 NinjaTrader Programming 4 January 24th, 2014 02:30 PM
Range Bars as base type for Better Line Break? aligator Traders Hideout 4 September 25th, 2011 11:04 PM
How to install Range Bar code in Thinkorswim rcs9234 ThinkOrSwim 5 July 7th, 2011 03:12 PM
NT7 - code break changes + TRADING LIVE max-td NinjaTrader Programming 9 April 12th, 2010 11:53 AM
Range bar code help traderlars The Elite Circle 23 December 30th, 2009 01:27 AM


All times are GMT -4. The time now is 08:58 PM.

Copyright © 2017 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
Page generated 2017-12-13 in 0.17 seconds with 39 queries on phoenix via your IP 54.160.245.121