Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
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);
}
Can you help answer these questions from other members on NexusFi?
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
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,
In the OnBarUpdate () section you need something like this example, change for your own setups.
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.
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
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?