Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

OnOrderUpdate(IOrder order) status to Cancel a Working Order

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    OnOrderUpdate(IOrder order) status to Cancel a Working Order

    Having some issues with the OnOrderUpdate and Sim account.

    I have a strategy where I want to get in x ticks away from current price on a range bar chart. But if the next range bar does not get me in, then I want to cancel the order when that range bar closes.

    To test this I forced the Limit price on a Long entry to 50 for CL (curr price 46.23) when this is done. I can see the Limit price set to 50 from the OnOrderUpdate print commands. In Bold you can see it change states from Pending, Accepted, Working, Filled and the Execution price is a Buy Limit of 50 even though that is never reached.

    I must be doing something wrong. The SIM account should not execute my Buy Limit at a price that is not traded. Which should then let me monitor the IOrder status so if I see the Order as Working then I can execute CancelOrder when CurrentBar > EntryBar+1

    Any suggestions?

    -----------
    In the output Window I get the following:
    Time: 11/2/2016 9:29:55 AM PrvADR7: 1.21
    SS Green:158 Enter Long 46.23 BB: 46.26 RSI: 66.57 Stop: 46.11 Target: 46.41

    Order='NT-00019/Sim101' Name='SS Green:158' State=PendingSubmit Instrument='CL 12-16' Action=Buy Limit price=50 Stop price=0 Quantity=1 Strategy='eTesting' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='a91f5468e3924b8090fe330ddfd1c2b1' Gtd='12/1/2099 12:00:00 AM'
    Order='NT-00019/Sim101' Name='SS Green:158' State=Accepted Instrument='CL 12-16' Action=Buy Limit price=50 Stop price=0 Quantity=1 Strategy='eTesting' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='a91f5468e3924b8090fe330ddfd1c2b1' Gtd='12/1/2099 12:00:00 AM'
    Order='NT-00019/Sim101' Name='SS Green:158' State=Working Instrument='CL 12-16' Action=Buy Limit price=50 Stop price=0 Quantity=1 Strategy='eTesting' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='a91f5468e3924b8090fe330ddfd1c2b1' Gtd='12/1/2099 12:00:00 AM'
    Order='NT-00019/Sim101' Name='SS Green:158' State=Filled Instrument='CL 12-16' Action=Buy Limit price=50 Stop price=0 Quantity=1 Strategy='eTesting' Type=Limit Tif=Gtc Oco='' Filled=1 Fill price=50 Token='a91f5468e3924b8090fe330ddfd1c2b1' Gtd='12/1/2099 12:00:00 AM'

    From OnExecution:
    Execution='NT-00012' Instrument='CL 12-16' Account='Sim101' Name='SS Green:158' Exchange=Default Price=50 Quantity=1 Market position=Long Commission=0 Order='NT-00019' Time='11/2/2016 9:29:55 AM'
    Execution='NT-00013' Instrument='CL 12-16' Account='Sim101' Name='Stop loss' Exchange=Default Price=46.22 Quantity=1 Market position=Short Commission=0 Order='NT-00020' Time='11/2/2016 9:29:55 AM'

    Losing Trade! Exit @ 46.22 11/2/2016 9:29:55 AM Max Favor: 46.23
    Reset First Leg BB Crossover

    protected override void OnOrderUpdate(IOrder order)
    {
    if (entryOrder != null && entryOrder == order)
    {
    Print(order.ToString());
    if (order.OrderState == OrderState.Filled)
    entryOrder = null;
    }

    // Cancel Order if next bar does not fill (If more than 1 bars has elapsed, cancel the entry order)
    if (entryOrder != null)
    {
    if (EntryBar > 0 && CurrentBar > EntryBar + 1 && order.OrderState == OrderState.Working)
    {
    Print("here");
    CancelOrder(entryOrder);
    Print("Order Cancelled: Not Filled on next bar: " + CurrentBar);
    }
    if (order.OrderState == OrderState.Filled)
    entryOrder = null;
    } // End Cancel Order check
    }

    #2
    Hello EricC64,

    To confirm, you have submitted a buy limit order with SubmitOrder() with a price of 50.
    Is this correct?
    In other words, you are using the unmanaged approach is this correct?
    I am assuming this because when using the managed approach and not using liveUntilCancelled or setting this to false will automatically cancel an order if it is not filled on the bar it is submitted on.
    I am assuming that you are trying to replicate the liveUntilClosed parameter of EnterLongLimit() when using the unmanaged approach.

    EnterLongLimit(int barsInProgressIndex, bool liveUntilCancelled, int quantity, double limitPrice, string signalName)



    What is the current price when the buy limit is placed and when it fills?

    I imagine that the limit is being placed above the bar and is filling immediately, as a limit fills at the specified price or better, a buy limit placed above market would fill immediately.

    With the Default fill type, this shows the limit at the price it filled. With the Liberal fill type this would show at the close price.


    Attached is an example script that uses the unmanaged approach and places a limit below the bar. The example allows for the order to be cancelled if not filled on the bar it is submitted on (and then will be resubmitted on the next bar) when LiveUntilCancelled (a property i've made for the script) is set to False, or will only place the order once and allow this to remain working until filled.

    Please try and model your prints the way I have created the prints. This lets us know the current price when the entry is placed, as well as time the orders are placed and what time they are being filled.
    Attached Files
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by funk10101, Today, 12:02 AM
    1 response
    11 views
    0 likes
    Last Post NinjaTrader_LuisH  
    Started by GLFX005, Today, 03:23 AM
    1 response
    6 views
    0 likes
    Last Post NinjaTrader_Erick  
    Started by nandhumca, Yesterday, 03:41 PM
    1 response
    13 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Started by The_Sec, Yesterday, 03:37 PM
    1 response
    11 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Started by vecnopus, Today, 06:15 AM
    0 responses
    1 view
    0 likes
    Last Post vecnopus  
    Working...
    X