NexusFi: Find Your Edge


Home Menu

 





order cancellation


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one mrticks with 4 posts (2 thanks)
    2. looks_two baruchs with 4 posts (0 thanks)
    3. looks_3 monpere with 2 posts (0 thanks)
    4. looks_4 kaywai with 2 posts (0 thanks)
    1. trending_up 7,339 views
    2. thumb_up 3 thanks given
    3. group 3 followers
    1. forum 11 posts
    2. attach_file 0 attachments




 
Search this Thread

order cancellation

  #1 (permalink)
kaywai
singapore
 
Posts: 131 since Nov 2009
Thanks Given: 11
Thanks Received: 7

Hi, Is it possible to create a script to cancel limit orders if they are not filled within a predetermined number of bars (for example 10 bars)? If so, how can I go about achieving that? This is all I have at the moment.

// Entry Condition: Submit a buy stop order one tick above the first 20 bar high.
if (Bars.BarsSinceSession > 20 && Close[0] >= highestHigh + TickSize)
{
// EnterLongLimit() can be used to generate buy orders.
EnterLongLimit(highestHigh+TickSize);
}


Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Trade idea based off three indicators.
Traders Hideout
Exit Strategy
NinjaTrader
How to apply profiles
Traders Hideout
Increase in trading performance by 75%
The Elite Circle
REcommedations for programming help
Sierra Chart
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Just another trading journal: PA, Wyckoff & Trends
30 thanks
Spoo-nalysis ES e-mini futures S&P 500
28 thanks
Tao te Trade: way of the WLD
24 thanks
Bigger Wins or Fewer Losses?
20 thanks
GFIs1 1 DAX trade per day journal
16 thanks
  #2 (permalink)
 
Big Mike's Avatar
 Big Mike 
Manta, Ecuador
Site Administrator
Developer
Swing Trader
 
Experience: Advanced
Platform: Custom solution
Broker: IBKR
Trading: Stocks & Futures
Frequency: Every few days
Duration: Weeks
Posts: 50,442 since Jun 2009
Thanks Given: 33,215
Thanks Received: 101,600

Track the order with IOrder then use CancelOrder to cancel.

 
Code
                            

IOrder myorder 
null;
int myorderbar 0;

myorder EnterLongLimit(highestHigh+TickSize);
myorderbar CurrentBar;

if (
myorderbar 10 CurrentBar)
  
CancelOrder(myorder); 
Typed from memory so check code first.

Mike

We're here to help: just ask the community or contact our Help Desk

Quick Links: Change your Username or Register as a Vendor
Searching for trading reviews? Review this list
Lifetime Elite Membership: Sign-up for only $149 USD
Exclusive money saving offers from our Site Sponsors: Browse Offers
Report problems with the site: Using the NexusFi changelog thread
Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #3 (permalink)
kaywai
singapore
 
Posts: 131 since Nov 2009
Thanks Given: 11
Thanks Received: 7


thank you sir! much appreciated.

Reply With Quote
  #4 (permalink)
 
mrticks's Avatar
 mrticks 
Dublin, Ireland.
 
Experience: Advanced
Platform: NinjaTrader, TOS, Multicharts, Open Source various
Trading: FDAX, cable/yen, FX, options on commodities
Posts: 67 since Jun 2009
Thanks Given: 16
Thanks Received: 10


kaywai View Post
Hi, Is it possible to create a script to cancel limit orders if they are not filled within a predetermined number of bars (for example 10 bars)? If so, how can I go about achieving that? This is all I have at the moment.

// Entry Condition: Submit a buy stop order one tick above the first 20 bar high.
if (Bars.BarsSinceSession > 20 && Close[0] >= highestHigh + TickSize)
{
// EnterLongLimit() can be used to generate buy orders.
EnterLongLimit(highestHigh+TickSize);
}


From the NinjaTrader Help Guide https://www.ninjatrader-support.com/HelpGuideV6/helpguide.html?CancelOrder

 
Code
private IOrder myEntryOrder = null; 
private int barNumberOfOrder = 0; 
 
protected override void OnBarUpdate() 
{    
    // Submit an entry order at the low of a bar 
    if (myEntryOrder == null) 
    {         
        myEntryOrder = EnterLongLimit(0, true, 1, Low[0], "Long Entry"); 
        barNumberOfOrder = CurrentBar; 
    } 
 
    // If more than 5 bars has elapsed, cancel the entry order 
    if (CurrentBar > barNumberOfOrder + 5) 
        CancelOrder(myEntryOrder); 
}
Hope that helps!

Reply With Quote
Thanked by:
  #5 (permalink)
 
mrticks's Avatar
 mrticks 
Dublin, Ireland.
 
Experience: Advanced
Platform: NinjaTrader, TOS, Multicharts, Open Source various
Trading: FDAX, cable/yen, FX, options on commodities
Posts: 67 since Jun 2009
Thanks Given: 16
Thanks Received: 10


kaywai View Post
Hi, Is it possible to create a script to cancel limit orders if they are not filled within a predetermined number of bars (for example 10 bars)? If so, how can I go about achieving that? This is all I have at the moment.

// Entry Condition: Submit a buy stop order one tick above the first 20 bar high.
if (Bars.BarsSinceSession > 20 && Close[0] >= highestHigh + TickSize)
{
// EnterLongLimit() can be used to generate buy orders.
EnterLongLimit(highestHigh+TickSize);
}


My code snippet above is incorrect for NT 7. Have had to code cancel orders today into a strat with limit orders, so they cancel if not filled after one bar.

For NT 7 it should look this:

In you variables section you need,
 
Code
#region Variables
private IOrder                              entryOrderR         = null; 
private int                                     entryBar               = 0;
In the OnBarUpdate () section you need something like this example, change for your own setups.
 
Code
protected override void OnBarUpdate()
if (Position.MarketPosition == MarketPosition.Flat 
                    && Position.MarketPosition != MarketPosition.Short
                    && Close[1] > Open[1]
                    && GetCurrentBid() < Close [1] - 2 * TickSize                
                    )
                {
                    {
                        
                        
                        entryOrderR = EnterLongStopLimit(Close[1] + 1 * TickSize, Close[1]); 
                         entryBar = CurrentBar;
                        
                        
                    }
                    // If more than 1 bars has closed since, cancel the entry order. 
                    if (CurrentBar > entryBar + 1) 
                    {    
                    CancelOrder(entryOrderR); 
                    }
                }

                else if (Position.MarketPosition == MarketPosition.Flat
                         && Position.MarketPosition != MarketPosition.Long
                         && GetCurrentAsk() > Close [1] + 2 * TickSize
                         && Close[1] < Open[1]                    
                         )
                {
                    {
                        
                        entryOrderR = EnterShortStopLimit(Close[1] - 1 * TickSize, Close[1]);
                        entryBar = CurrentBar;
                        
                    }
                    // If more than 1 bars has closed since, cancel the entry order.
                    if (CurrentBar > entryBar + 1) 
                    {
                    CancelOrder(entryOrderR); 
                    }
In my earlier sample I had left out curly brackets from the CancelOrder(MyEntryOrder); call sample. I have added to this post for my own future reference and also so it may help others in the future.

Reply With Quote
Thanked by:
  #6 (permalink)
 baruchs 
Israel
 
Experience: Intermediate
Platform: NinjaTrader
Broker: pfg
Trading: eminis
Posts: 323 since Jun 2009

You don't need any code to cancel orders!
Just issue order without "live until canceled" (the simple one) and don't renew it.

Baruch

Reply With Quote
  #7 (permalink)
 
monpere's Avatar
 monpere 
Bala, PA, USA
 
Experience: Intermediate
Platform: NinjaTrader
Broker: Mirus, IB
Trading: SPY, Oil, Euro
Posts: 1,854 since Jul 2010
Thanks Given: 300
Thanks Received: 3,371


baruchs View Post
You don't need any code to cancel orders!
Just issue order without "live until canceled" (the simple one) and don't renew it.

Baruch

live until canceled only works for 1 bar.

Reply With Quote
  #8 (permalink)
 baruchs 
Israel
 
Experience: Intermediate
Platform: NinjaTrader
Broker: pfg
Trading: eminis
Posts: 323 since Jun 2009


Quoting 
live until canceled only works for 1 bar

Your wrong!
EnterLongLimit()

Baruch

Reply With Quote
  #9 (permalink)
 
mrticks's Avatar
 mrticks 
Dublin, Ireland.
 
Experience: Advanced
Platform: NinjaTrader, TOS, Multicharts, Open Source various
Trading: FDAX, cable/yen, FX, options on commodities
Posts: 67 since Jun 2009
Thanks Given: 16
Thanks Received: 10


baruchs View Post
You don't need any code to cancel orders!
Just issue order without "live until canceled" (the simple one) and don't renew it.

Baruch

Baruch - I need to manually cancel orders otherwise they don't expire until the close of the session. Also, sometimes one of my entry signals causes an "invalid order submitted" error which then terminates the strategy.

Can you post the code or attach a sample strategy that cancels an order after one bar closes?

Reply With Quote
  #10 (permalink)
 baruchs 
Israel
 
Experience: Intermediate
Platform: NinjaTrader
Broker: pfg
Trading: eminis
Posts: 323 since Jun 2009


EnterLongLimit(Price);
Will be valid for 1 bar. Of course if you issue this order on each bar then until you stop doing it the order will exist.

Quoting 
Also, sometimes one of my entry signals causes an "invalid order submitted" error which then terminates the strategy.

How do you want me to respond to it?
Baruch

Reply With Quote




Last Updated on December 9, 2010


© 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