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,718 / 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

  #1 (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

Code for range break out strategy

Code for range break out strategy - (in ninjatrader) Im attempting to write a simple strategy to enter a trade after price breaks the range of a given time period.

Example, if price breaks the high of the 9:00 to 9:30 price range then go long for 1 point... or if price breaks the low of the 9:00 to 9:30 price range, then go short for 1 point...

Lots of sharp people, would appreciate your insights, thanks!

*****************
original question edited for to better articulate the challenge...thanks

- Ticker


Last edited by ticker; March 15th, 2012 at 11:04 PM.
Reply With Quote
The following user says Thank You to ticker for this post:
 
  #2 (permalink)
Quick Summary
Quick Summary Post

Quick Summary is created and edited by users like you... Add FAQ's, Links and other Relevant Information by clicking the edit button in the lower right hand corner of this message.

 
  #3 (permalink)
Site Administrator
Manta, Ecuador
 
Futures Experience: Advanced
Platform: My own custom solution
Favorite Futures: E-mini ES S&P 500
 
Big Mike's Avatar
 
Posts: 46,238 since Jun 2009
Thanks: 29,350 given, 83,218 received


 
Thread Moved


Moved to NinjaTrader Programming



When creating a new thread, note which subforum you are in. Here is a short list of suggestions:

- Topic: Anything to do with an Elite indicator -> Subforum: The Elite Circle
- Topic: Looking for an existing indicator, or how-to use an indicator -> Subforum: (the platform)
- Topic: Programmer needing help with non-Elite indicator -> Subforum: (the platform) - Programming
- Topic: Want an indicator created/modified -> Reply to "Want indicator created free" in Elite Circle
- Topic: Vendors (trading rooms, commercial indicators) -> Subforum: Vendors/Product Reviews
- Topic: Discussion of Forex or Currency trading -> Subforum: Forex and Currency Trading
- Topic: Journals of your trading -> Subforum: Trading Journals or Elite Trading Journals
- Topic: General trading related discussions -> Subforum: Traders Hideout
- Topic: Discussion of a trading method -> Subforum: Traders Hideout
- Topic: Automated Trading -> Subforum: Elite Automated Trading

Last, any Elite Member may create more or less any of these topics in The Elite Circle at your own discretion (your support is appreciated).

This is just a short general list and doesn't cover everything. If you are unsure where to create your new thread, just create it in Traders Hideout and a moderator will move it if necessary.

-- Big Mike Trading


Due to time constraints, please do not PM me if your question can be resolved or answered on the forum.

Need help?
1) Stop changing things. No new indicators, charts, or methods. Be consistent with what is in front of you first.
2) Start a journal and post to it daily with the trades you made to show your strengths and weaknesses.
3) Set goals for yourself to reach daily. Make them about how you trade, not how much money you make.
4) Accept responsibility for your actions. Stop looking elsewhere to explain away poor performance.
5) Where to start as a trader? Watch this webinar and read this thread for hundreds of questions and answers.
6)
Help using the forum? Watch this video to learn general tips on using the site.

If you want
to support our community, become an Elite Member.

Reply With Quote
 
  #4 (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
Code for range break out strategy - (in ninjatrader) Im attempting to write a simple strategy to enter a trade after price breaks the range of a given time period. Example, if price breaks out long after 9:00 to 9:30 then go long for 1 point... or if price breaks the low from 9:00 to 9:30, then go short for 1 point...
Lots of sharp people, would appreciate your insights, thanks!

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.

Nil per os
-NJAMC [Generic Programmer]

LOM WIKI: NT-Local-Order-Manager-LOM-Guide
Artificial Bee Colony Optimization
Reply With Quote
The following 2 users say Thank You to NJAMC for this post:
 
  #5 (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


Quoting 
This can only be done with unmanaged transactions

Are you sure?

Reply With Quote
The following user says Thank You to baruchs for this post:
 
  #6 (permalink)
Elite Member
Arizona, USA
 
Futures Experience: Intermediate
Platform: NinjaTrader
Broker/Data: MB Trading
Favorite Futures: Cello
 
serac's Avatar
 
Posts: 116 since Jan 2011
Thanks: 321 given, 137 received


baruchs View Post
Are you sure?


I'm sure.

Concurrent Stop Orders? - NinjaTrader Support Forum

Reply With Quote
The following user says Thank You to serac for this post:
 
  #7 (permalink)
Elite Member
Fort Collins, Colorado
 
Futures Experience: Intermediate
Platform: NT7
Favorite Futures: ES
 
Posts: 57 since Feb 2011
Thanks: 48 given, 43 received

Here is some simple code that does what you want. It has no stop-loss / profit-targets, and it doesn't display the opening range on the chart, but those are easy to add yourself.

I could be missing something, since others seem to think it isn't possible, but it seems to work for opening an order based on your criteria. Adding a profit target should be as easy as picking the amount away from your entry. I wrote it from the ground up, and I have to profess, I don't know anything about "unmanaged transactions" so tell me if I missed something.

 
Code
public class OpenRangeBreakout : Strategy
    {
        #region Variables
        // Wizard generated variables
        // User defined variables (add any user defined variables below)
			private double CurrentDay;
			private double CurrentOpenRangeHigh;
			private double CurrentOpenRangeLow;
        #endregion

        /// <summary>
        /// This method is used to configure the strategy and is called once before any strategy method is called.
        /// </summary>
        protected override void Initialize()
        {
            CalculateOnBarClose = true;
        }

        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            // Condition set 1
            if (ToDay(Time[0]) != CurrentDay)
			{
				CurrentDay = ToDay(Time[0]);
				CurrentOpenRangeHigh = 0;
				CurrentOpenRangeLow = 100000;
			}
			if (ToTime(Time[0]) >= ToTime(9, 0, 0)
                && ToTime(Time[0]) <= ToTime(9, 30, 0))
            {
                if (High[0] > CurrentOpenRangeHigh)
				{
					CurrentOpenRangeHigh = High[0];
				}
				if (Low[0] < CurrentOpenRangeLow)
				{
					CurrentOpenRangeLow = Low[0];
				}
            }
			if (ToTime(Time[0]) > ToTime(9, 30, 0) && ToTime(Time[0]) < ToTime(16, 0, 0))
			{
				if (Close[0] > CurrentOpenRangeHigh)
				{
					EnterLong(DefaultQuantity, "");
				}
				if (Close[0] < CurrentOpenRangeLow)
				{
					EnterShort(DefaultQuantity, "");
				}
			}
        }
As it is currently written, it will enter the trade, and then in the analyzer, close it at the end of day if you have it set to do so.

Hope it helps.

Reply With Quote
The following user says Thank You to fctrader for this post:
 
  #8 (permalink)
Elite Member
Fort Collins, Colorado
 
Futures Experience: Intermediate
Platform: NT7
Favorite Futures: ES
 
Posts: 57 since Feb 2011
Thanks: 48 given, 43 received

For fun... Here it is with a 4 tick Profit Target and a 4 tick Stop Loss. Because it has targets and losses, I have made it so that it only goes long once per day, and short once per day. If you want it to only trade on the first break, change both the "LongTrade" and "ShortTrade" to be just TodaysTrade, and you will get only one trade per day.

 
Code
 /// Buys a breakout above Opening Range. Sells a breakout below.
    /// </summary>
    [Description("Buys a breakout above Opening Range. Sells a breakout below.")]
    public class OpenRangeBreakout : Strategy
    {
        #region Variables
        // Wizard generated variables
        // User defined variables (add any user defined variables below)
			private double CurrentDay;
			private double CurrentOpenRangeHigh;
			private double CurrentOpenRangeLow;
			private int LongTrade;
			private int ShortTrade;
        #endregion

        /// <summary>
        /// This method is used to configure the strategy and is called once before any strategy method is called.
        /// </summary>
        protected override void Initialize()
        {
            CalculateOnBarClose = true;
			SetProfitTarget("", CalculationMode.Ticks, 4);
            SetStopLoss("", CalculationMode.Ticks, 4, true);
        }

        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            // Condition set 1
            if (ToDay(Time[0]) != CurrentDay)
			{
				CurrentDay = ToDay(Time[0]);
				CurrentOpenRangeHigh = 0;
				CurrentOpenRangeLow = 100000;
				LongTrade = 0;
				ShortTrade = 0;
			}
			if (ToTime(Time[0]) >= ToTime(9, 0, 0)
                && ToTime(Time[0]) <= ToTime(9, 30, 0))
            {
                if (High[0] > CurrentOpenRangeHigh)
				{
					CurrentOpenRangeHigh = High[0];
				}
				if (Low[0] < CurrentOpenRangeLow)
				{
					CurrentOpenRangeLow = Low[0];
				}
            }
			if (ToTime(Time[0]) > ToTime(9, 30, 0) && ToTime(Time[0]) < ToTime(16, 0, 0))
			{
				if (Close[0] > CurrentOpenRangeHigh && LongTrade <1)
				{
					EnterLong(DefaultQuantity, "");
					LongTrade++;
				}
				if (Close[0] < CurrentOpenRangeLow && ShortTrade < 1)
				{
					EnterShort(DefaultQuantity, "");
					ShortTrade++;
				}
			}
        }

Reply With Quote
The following 3 users say Thank You to fctrader for this post:
 
  #9 (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



Good find, it is worth trying as a managed OCO order. Here is the recommended approach:

 
Code
SubmitOrder(0,OrderAction.Buy,OrderType.Stop, 1, 0, Close[0] + 10 * TickSize, "EntryStopOCO", "BuyStopEntry" );

SubmitOrder(0, OrderAction.Sell, OrderType.Stop, 1, 0, Close[0] - 10 * TickSize, "EntryStopOCO", "SellStopEntry");
Thanks @serac

Nil per os
-NJAMC [Generic Programmer]

LOM WIKI: NT-Local-Order-Manager-LOM-Guide
Artificial Bee Colony Optimization
Reply With Quote
 
  #10 (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
Here is some simple code that does what you want. It has no stop-loss / profit-targets, and it doesn't display the opening range on the chart, but those are easy to add yourself.

I could be missing something, since others seem to think it isn't possible, but it seems to work for opening an order based on your criteria. Adding a profit target should be as easy as picking the amount away from your entry. I wrote it from the ground up, and I have to profess, I don't know anything about "unmanaged transactions" so tell me if I missed something.

As it is currently written, it will enter the trade, and then in the analyzer, close it at the end of day if you have it set to do so.

Hope it helps.

Hi @fctrader,

Your approach here works, but your OCO bracket is driven by your PC. These are not live orders on the market, but you go Long/Short when you detect the event. You could set this to run per tick to minimize slipage if you have a large movement on one bar.

I think the intent was to have two live StopLimit orders, one in each direction to catch the break out. Not sure, if this works for the person starting the thread it certainly works with those limitations.

Thanks for your perspective.

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)

Linda Bradford Raschke: Reading The Tape

Elite only

Adam Grimes: TBA

Elite only

NinjaTrader: TBA

January

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 07:09 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-11 in 0.15 seconds with 37 queries on phoenix via your IP 54.92.194.75