NexusFi: Find Your Edge


Home Menu

 





Cancel Order


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one olres7 with 5 posts (0 thanks)
    2. looks_two rleplae with 4 posts (4 thanks)
    3. looks_3 sam028 with 1 posts (1 thanks)
    4. looks_4 Quick Summary with 1 posts (0 thanks)
    1. trending_up 3,765 views
    2. thumb_up 5 thanks given
    3. group 3 followers
    1. forum 10 posts
    2. attach_file 0 attachments




 
Search this Thread

Cancel Order

  #1 (permalink)
 olres7 
Gatlinburg TN/USA
 
Experience: Intermediate
Platform: NinjaTrader
Trading: Futures
Posts: 12 since Sep 2015
Thanks Given: 5
Thanks Received: 0

Hi there!

I am trying to write a simple script to cancel an order.

If 2 bars no entry(5 min) = cancel order. I found a script similar in ninja tutorial however this code doesn't work.
I put in my strategy and back-tested and no results.

This is Ninja Trader Tutorial 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);

This is my code:

private int barNumberOfOrder = 0;
private IOrder myEntryOrder = null;
protected override void Initialize()
{

TimeInForce = Cbi.TimeInForce.Day;
ExitOnClose = true;
ExitOnCloseSeconds = 960;
ConnectionLossHandling = ConnectionLossHandling.KeepRunning;
EntriesPerDirection = 6;
EntryHandling = EntryHandling.AllEntries;
SetStopLoss("", CalculationMode.Ticks, 5, false);
SetProfitTarget("", CalculationMode.Ticks, 18);
CalculateOnBarClose = true;

}
protected override void OnBarUpdate()
{
if(myEntryOrder==null)
{
if( Range()[0] <= 9*TickSize &&
Volume[0] > 510 &&
High[0] > MAX(High, 30)[1])
{
myEntryOrder=EnterShortLimit(0,true,1,High[0]-(3*TickSize), "Short1");
barNumberOfOrder = CurrentBar;
}
}
if (CurrentBar > barNumberOfOrder + 2)
CancelOrder(myEntryOrder);
}


I spent the whole week to figure out about that issue and still no results
If you anybody knows how to fix it I would be very appreciate

Thanks,
Serge

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Ninja Mobile Trader VPS (ninjamobiletrader.com)
Trading Reviews and Vendors
Futures True Range Report
The Elite Circle
The space time continuum and the dynamics of a financial …
Emini and Emicro Index
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
Are there any eval firms that allow you to sink to your …
Traders Hideout
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Get funded firms 2023/2024 - Any recommendations or word …
59 thanks
Funded Trader platforms
36 thanks
NexusFi site changelog and issues/problem reporting
25 thanks
The Program
20 thanks
GFIs1 1 DAX trade per day journal
19 thanks
  #3 (permalink)
 
rleplae's Avatar
 rleplae 
Gits (Hooglede) Belgium
Legendary Market Wizard
 
Experience: Master
Platform: NinjaTrader, Proprietary,
Broker: Ninjabrokerage/IQfeed + Synthetic datafeed
Trading: 6A, 6B, 6C, 6E, 6J, 6S, ES, NQ, YM, AEX, CL, NG, ZB, ZN, ZC, ZS, GC
Posts: 3,003 since Sep 2013
Thanks Given: 2,442
Thanks Received: 5,863


Hello

You might consider to look at the code of the BOT i published in my thread



You will find several types of updates on an order.

Also like dynamically changing a
stop (trailing)
target (turbo)

good luck

Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #4 (permalink)
 
sam028's Avatar
 sam028 
Site Moderator
 
Posts: 3,765 since Jun 2009
Thanks Given: 3,825
Thanks Received: 4,629

Maybe a simple else missing?
Not tested nor compiled.

 
Code
                            
protected override void OnBarUpdate() { 
    if(
myEntryOrder==null) { 
        if(    
Range()[0] <= 9*TickSize && Volume[0] > 510 && High[0] > MAX(High30)[1]) {
            
myEntryOrder=EnterShortLimit(0,true,1,High[0]-(3*TickSize), "Short1");
            
barNumberOfOrder CurrentBar;
        }
    } 
    else if (
CurrentBar barNumberOfOrder 2) { //myEntryOrder is not NULL
            
Print("myEntryOrder to be cancelled: " myEntryOrder.ToString());
            
CancelOrder(myEntryOrder);
        }


Success requires no deodorant! (Sun Tzu)
Follow me on Twitter Reply With Quote
Thanked by:
  #5 (permalink)
 olres7 
Gatlinburg TN/USA
 
Experience: Intermediate
Platform: NinjaTrader
Trading: Futures
Posts: 12 since Sep 2015
Thanks Given: 5
Thanks Received: 0

I am using Ninja 7
I was trying to open your strategy thru
FILE\UTILITIES\IMPORT\AlphaTradingMethodRonV36.zip

However, It doesn't open. It says some error.

Do you know how to open it?

Thanks,
Serge





rleplae View Post
Hello

You might consider to look at the code of the BOT i published in my thread



You will find several types of updates on an order.

Also like dynamically changing a
stop (trailing)
target (turbo)

good luck


Started this thread Reply With Quote
  #6 (permalink)
 olres7 
Gatlinburg TN/USA
 
Experience: Intermediate
Platform: NinjaTrader
Trading: Futures
Posts: 12 since Sep 2015
Thanks Given: 5
Thanks Received: 0

I did it however still no results
I back-tested. I doesn't make any trades at all. I really don't know where is the problem is.
It doesn't print also:
Print("myEntryOrder to be cancelled: " + myEntryOrder.ToString());





sam028 View Post
Maybe a simple else missing?
Not tested nor compiled.

 
Code
                            
protected override void OnBarUpdate() { 

    if(
myEntryOrder==null) { 
        if(    
Range()[0] <= 9*TickSize && Volume[0] > 510 && High[0] > MAX(High30)[1]) {
            
myEntryOrder=EnterShortLimit(0,true,1,High[0]-(3*TickSize), "Short1");
            
barNumberOfOrder CurrentBar;
        }
    } 
    else if (
CurrentBar barNumberOfOrder 2) { //myEntryOrder is not NULL
            
Print("myEntryOrder to be cancelled: " myEntryOrder.ToString());
            
CancelOrder(myEntryOrder);
        }



Started this thread Reply With Quote
  #7 (permalink)
 
rleplae's Avatar
 rleplae 
Gits (Hooglede) Belgium
Legendary Market Wizard
 
Experience: Master
Platform: NinjaTrader, Proprietary,
Broker: Ninjabrokerage/IQfeed + Synthetic datafeed
Trading: 6A, 6B, 6C, 6E, 6J, 6S, ES, NQ, YM, AEX, CL, NG, ZB, ZN, ZC, ZS, GC
Posts: 3,003 since Sep 2013
Thanks Given: 2,442
Thanks Received: 5,863


olres7 View Post
I did it however still no results
I back-tested. I doesn't make any trades at all. I really don't know where is the problem is.
It doesn't print also:
Print("myEntryOrder to be cancelled: " + myEntryOrder.ToString());

1. I would recomend adding some debug information
with Print statements of the value of range
and of your 9 X ticksize

2. also output the limit you are putting on the order
if it enters the iff at all

Same for all other conditions, you will then be able to see step by step what happens.

Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
  #8 (permalink)
 
rleplae's Avatar
 rleplae 
Gits (Hooglede) Belgium
Legendary Market Wizard
 
Experience: Master
Platform: NinjaTrader, Proprietary,
Broker: Ninjabrokerage/IQfeed + Synthetic datafeed
Trading: 6A, 6B, 6C, 6E, 6J, 6S, ES, NQ, YM, AEX, CL, NG, ZB, ZN, ZC, ZS, GC
Posts: 3,003 since Sep 2013
Thanks Given: 2,442
Thanks Received: 5,863


olres7 View Post
I am using Ninja 7
I was trying to open your strategy thru
FILE\UTILITIES\IMPORT\AlphaTradingMethodRonV36.zip

However, It doesn't open. It says some error.

Do you know how to open it?

Thanks,
Serge

you simply take an unzipper
open the archive and inside is a .cs file
use it as an illustration

don't try to run the strategy
however you might find some ideas in the code..

code luck

Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #9 (permalink)
 olres7 
Gatlinburg TN/USA
 
Experience: Intermediate
Platform: NinjaTrader
Trading: Futures
Posts: 12 since Sep 2015
Thanks Given: 5
Thanks Received: 0

Thanks


rleplae View Post
you simply take an unzipper
open the archive and inside is a .cs file
use it as an illustration

don't try to run the strategy
however you might find some ideas in the code..

code luck


Started this thread Reply With Quote
  #10 (permalink)
 olres7 
Gatlinburg TN/USA
 
Experience: Intermediate
Platform: NinjaTrader
Trading: Futures
Posts: 12 since Sep 2015
Thanks Given: 5
Thanks Received: 0


Thanks,
I opened .cs with .txt file.
However, your project is so complected for me. It is completely out of my scope. I am a novice trader.
And some things are very hard for me to understand.
If you have some simple examples with an order handling that would be great.

Thanks,
Serge



rleplae View Post
you simply take an unzipper
open the archive and inside is a .cs file
use it as an illustration

don't try to run the strategy
however you might find some ideas in the code..

code luck


Started this thread Reply With Quote




Last Updated on October 21, 2015


© 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