Help wanted! Long/short strategy with cancel order and trail stop - NinjaTrader Programming | futures io social day trading
futures io futures trading


Help wanted! Long/short strategy with cancel order and trail stop
Updated: Views / Replies:3,090 / 9
Created: by mrticks Attachments:4

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
 

Help wanted! Long/short strategy with cancel order and trail stop

  #1 (permalink)
Elite Member
Dublin, Ireland.
 
Futures Experience: Advanced
Platform: NinjaTrader, TOS, Multicharts, Open Source various
Favorite Futures: FDAX, cable/yen, FX, options on commodities
 
mrticks's Avatar
 
Posts: 67 since Jun 2009
Thanks: 16 given, 9 received

Help wanted! Long/short strategy with cancel order and trail stop

Hey Folks am looking for some help with the attached strategy. It does everything I want it to do but only once! It will go long/short after entry signal with a stop loss and then if it is profit will trail the stop loss at the open [1] as coded. However, once this order is stopped out it does not take any other orders.

I posted on the NT forum here Long/short strategy with cancel order and trail stop - NinjaTrader Support Forum and was told I need to make sure "IOrder object is reset to null" but am not sure where to do this as I copied this strat from the NT sample strategies.

Basically, I'm looking for a strat to do the following:
1. Enter long if Close[1] > Open[1]
or
Enter short if Close[1] < Open[1]

2. Set initial stop loss to n ticks.

3. Cancel pending order if not filled after n bars.

4. If n ticks in profit then set stop loss to low/high of Open[1].


If anyone could point me in the right direction I would REALLY appreciate it!


Thanks.

Attached Files
Register to download File Type: zip TrailOneBar.zip (3.0 KB, 50 views)
Reply With Quote
 
  #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)
Elite Member
Near the BEuTiFULL Horse Shoe
 
Futures Experience: Beginner
Platform: NinjaTrader
Broker/Data: MBTrading Dukascopy ZenFire
Favorite Futures: $EURUSD when it is trending
 
Trader.Jon's Avatar
 
Posts: 500 since Jul 2009
Thanks: 401 given, 176 received

A little help


I am not a programmer, and I didnt integrate into your code, so I did add some code snippets that might help you along the road (into your own shell) .. dont try to compile, I didnt use your namespaces or ordersignal names. I hope it helps.

TJ

Attached Files
Register to download File Type: txt FDAX1LBtrail.cs.txt (11.0 KB, 71 views)
Reply With Quote
The following user says Thank You to Trader.Jon for this post:
 
  #4 (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


mrticks View Post


If anyone could point me in the right direction I would REALLY appreciate it!


Thanks.

You have a logic error so it is not going to run the way you expect it to work.

And use Round2TickSize instead of the (7 * (TickSize / 2)) thing you are doing.

Reply With Quote
 
  #5 (permalink)
Elite Member
Dublin, Ireland.
 
Futures Experience: Advanced
Platform: NinjaTrader, TOS, Multicharts, Open Source various
Favorite Futures: FDAX, cable/yen, FX, options on commodities
 
mrticks's Avatar
 
Posts: 67 since Jun 2009
Thanks: 16 given, 9 received


Trader.Jon View Post
I am not a programmer, and I didnt integrate into your code, so I did add some code snippets that might help you along the road (into your own shell) .. dont try to compile, I didnt use your namespaces or ordersignal names. I hope it helps.

TJ

Hi TJ thanks for that!

I've cobbled together another strat from your sample code, will test it now and see how it behaves. I appreciate you taking a look at this.


Thanks!

Attached Files
Register to download File Type: txt Trailing_One_Bar_prev_cancel_order.txt (12.2 KB, 44 views)
Reply With Quote
 
  #6 (permalink)
Elite Member
Dublin, Ireland.
 
Futures Experience: Advanced
Platform: NinjaTrader, TOS, Multicharts, Open Source various
Favorite Futures: FDAX, cable/yen, FX, options on commodities
 
mrticks's Avatar
 
Posts: 67 since Jun 2009
Thanks: 16 given, 9 received


traderwerks View Post
You have a logic error so it is not going to run the way you expect it to work.

And use Round2TickSize instead of the (7 * (TickSize / 2)) thing you are doing.

I took out that piece of code in my latest version as I only had that in there from copying a sample snippet.

I read your blog by the way and like the sample strategies you post on the website for reference!

Reply With Quote
 
  #7 (permalink)
Elite Member
Near the BEuTiFULL Horse Shoe
 
Futures Experience: Beginner
Platform: NinjaTrader
Broker/Data: MBTrading Dukascopy ZenFire
Favorite Futures: $EURUSD when it is trending
 
Trader.Jon's Avatar
 
Posts: 500 since Jul 2009
Thanks: 401 given, 176 received

l@@king at code


mrticks View Post
Hi TJ thanks for that!

I've cobbled together another strat from your sample code, will test it now and see how it behaves. I appreciate you taking a look at this.


Thanks!

Have you tried out your new code? I will have a quick look later if you still need that comment ... unfortunately I dont use breakeven in my code ( anytime recently ) and I may have some challenge to follow correctly.

Jon

Reply With Quote
 
  #8 (permalink)
Elite Member
Dublin, Ireland.
 
Futures Experience: Advanced
Platform: NinjaTrader, TOS, Multicharts, Open Source various
Favorite Futures: FDAX, cable/yen, FX, options on commodities
 
mrticks's Avatar
 
Posts: 67 since Jun 2009
Thanks: 16 given, 9 received


Trader.Jon View Post
Have you tried out your new code? I will have a quick look later if you still need that comment ... unfortunately I dont use breakeven in my code ( anytime recently ) and I may have some challenge to follow correctly.

Jon

Hi Jon,

I tested it but alas it did not perform as I had hoped. It will enter long or short and set a stop loss and then move to breakeven but does not modify the trail stop to follow at O/H/L/C of n bars ago or

SetStopLoss( "Long", CalculationMode.Price, Open[3] + 2 * TickSize, false);

as they say in C#.

I've attached the strat if you'd like to give it a whirl and see if you can do anything with it!

 
Code
/* If we have a long position and the current price is breakeven + x ticks in profit, raise the stop-loss order to Open[3] + 2 * TickSize.
            
                */
                if (Position.MarketPosition == MarketPosition.Long && Close[0] >= Position.AvgPrice + 8 * TickSize)
            {
                // Checks to see if Close[0] is b/e + x ticks
                if (GetCurrentAsk() > previousPrice + trailProfitTrigger * TickSize)
                {
                    // Modifies stop-loss to Open[3] + 2 * TickSize
                    SetStopLoss( "Long", CalculationMode.Price, Open[3] + 2 * TickSize, false);
                }
            }
            
            /* If we have a short position and the current price is x ticks in profit, raise the stop-loss order to breakeven.
            
                */
            if (Position.MarketPosition == MarketPosition.Short && Close[0] <= Position.AvgPrice - 4 * TickSize)
            {
                // Checks to see if our Stop Order has been submitted already
                if (stopOrder != null && stopOrder.StopPrice > Position.AvgPrice)
                {
                    // Modifies stop-loss to breakeven
                    stopOrder = ExitShortStop(0, true, stopOrder.Quantity, Position.AvgPrice, "ShortStop", "Short1SB");
                }
            }

Attached Files
Register to download File Type: zip sample_trail_strat_TJ.zip (3.7 KB, 31 views)
Reply With Quote
 
  #9 (permalink)
Elite Member
Lubbock TX
 
Futures Experience: Intermediate
Platform: NinjaTrader
Broker/Data: Stage 5 Trading
Favorite Futures: CL
 
MWinfrey's Avatar
 
Posts: 1,879 since Jul 2009
Thanks: 1,449 given, 3,306 received


mrticks View Post
Hi Jon,

I tested it but alas it did not perform as I had hoped. It will enter long or short and set a stop loss and then move to breakeven but does not modify the trail stop to follow at O/H/L/C of n bars ago or

SetStopLoss( "Long", CalculationMode.Price, Open[3] + 2 * TickSize, false);

as they say in C#.

I've attached the strat if you'd like to give it a whirl and see if you can do anything with it!

 
Code
/* If we have a long position and the current price is breakeven + x ticks in profit, raise the stop-loss order to Open[3] + 2 * TickSize.
 
                */
                if (Position.MarketPosition == MarketPosition.Long && Close[0] >= Position.AvgPrice + 8 * TickSize)
            {
                // Checks to see if Close[0] is b/e + x ticks
                if (GetCurrentAsk() > previousPrice + trailProfitTrigger * TickSize)
                {
                    // Modifies stop-loss to Open[3] + 2 * TickSize
                    SetStopLoss( "Long", CalculationMode.Price, Open[3] + 2 * TickSize, false);
                }
            }
 
            /* If we have a short position and the current price is x ticks in profit, raise the stop-loss order to breakeven.
 
                */
            if (Position.MarketPosition == MarketPosition.Short && Close[0] <= Position.AvgPrice - 4 * TickSize)
            {
                // Checks to see if our Stop Order has been submitted already
                if (stopOrder != null && stopOrder.StopPrice > Position.AvgPrice)
                {
                    // Modifies stop-loss to breakeven
                    stopOrder = ExitShortStop(0, true, stopOrder.Quantity, Position.AvgPrice, "ShortStop", "Short1SB");
                }
            }

MrTicks, it just occured to me that you aren't an elite member. The code I'm going to share will be limited to Elite members only.

Reply With Quote
 
  #10 (permalink)
Elite Member
Lubbock TX
 
Futures Experience: Intermediate
Platform: NinjaTrader
Broker/Data: Stage 5 Trading
Favorite Futures: CL
 
MWinfrey's Avatar
 
Posts: 1,879 since Jul 2009
Thanks: 1,449 given, 3,306 received

Generic Strategy for nt6.5 and nt7


Must be a member of the elite circle to download and use.

https://futures.io/free_downloads/vip_elite_circle/689-download.html?view
https://futures.io/free_downloads/vip_elite_circle/691-download.html?view

Reply With Quote
The following 4 users say Thank You to MWinfrey for this post:

Reply



futures io > > > > > Help wanted! Long/short strategy with cancel order and trail stop

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
Possible to trail a stop per Parabolic SAR? christhesquid NinjaTrader Programming 12 August 30th, 2013 06:33 PM
cancel last order terratec NinjaTrader Programming 16 September 1st, 2011 02:17 PM
ATM Order Cancel Project Baseheadz NinjaTrader Programming 4 August 16th, 2011 12:32 AM
ATR Stop Trail need help pls Falco11 NinjaTrader Programming 6 January 20th, 2011 05:53 AM
simple go long or go short strategy stephenszpak NinjaTrader Programming 7 July 21st, 2010 11:05 AM


All times are GMT -4. The time now is 06:54 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.13 seconds with 20 queries on phoenix via your IP 54.90.92.204