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

On Execution Update

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

    On Execution Update

    Hello. I expect this info exists somewhere but I can't find it.
    I have code where my Stops are entered in the OnExecutionUpdate. What appears to be happening is that with each partial fill I'm getting a stop submitted for the full order amount. Conceivably, I could have a stop associated with each partial fill but that causes problems for other parts of the code, so I'm just trying to submit a single stop following a complete fill based on the average fill price. My code looks like this:

    protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time)
    {
    if (isBuyCont1)
    {
    enterPrice = execution.Order.AverageFillPrice;
    buyCont1TrailPrice = enterPrice-stopSize;
    if(execution.Order.OrderState==OrderState.Filled)
    {
    stopOrder = SubmitOrderUnmanaged(0, OrderAction.Sell, OrderType.StopMarket, execution.Order.Filled, 0, buyCont1TrailPrice, ocoSignal, stopSignal);

    targetOrder = SubmitOrderUnmanaged(0,OrderAction.Sell, OrderType.Limit, execution.Order.Filled, enterPrice+targetSize,0,ocoSignal,targetSignal);
    }
    Sorry for the formatting. Does anything stick out as to why I might be getting multiple stops submitted when I get partial fills?
    Thanks

    #2
    Hello stewarco.

    Thanks for the note.

    One way I could see to prevent this would be checking the Filled property of the Order object for the correct quantity:



    The error might be coming from a different part of your code since the snipped you posted submits the stop only if the OrderState is Filled and not PartFilled. I would advise you add prints at the top of your OnExecutionUpdate() method to print data about the Order object being evaluated.

    I look forward to assisting further.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      follow up

      Hi. Maybe I'm unclear about the meaning of "Filled".
      My understanding is that Filled means the entire order has been filled, and so by making sure that Order.State = Filled, I would only be submitting a stop order once. Similarly, I thought I could try submitting the stop if Order.State <> PartFilled, i.e. only when it's complete.

      Am I correct in that the Order info that gets passed to OnExecutionUpdate is the actual order, and not just the partial portion that has been executed?

      Comment


        #4
        Hello stewarco,

        Thanks for the reply.

        I tested the behavior myself and (if Orderstate == Filled) always results in just one Stop order. Checking (if Orderstate == PartFilled) results in the output that you are getting, multiple stops for each partial fill. I would need to see your full script to see if I can reproduce the output that you are getting. If you do not want to post it here, you may email platformsupport[at]ninjatrader[dot]com and paste the link to this thread in the body.

        I look forward to your reply.
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          Thanks

          Ok thanks. I will try to tinker some more to see what’s going on. The problem I’m having is when I back test the code there are no partial fills, so I can’t replicate the issue except when I’m live which obviously is a tricky way to test. I guess I could just run it live in a simulation account?

          Comment


            #6
            Hello stewarco,

            Thanks for the reply.

            Sorry for not mentioning it earlier, but you can force the simulation account to get partial fills by going to Tools>Options>Trading> Check "Enforce partial fills".

            Please let us know if you have any questions.
            Chris L.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by martin70, 03-24-2023, 04:58 AM
            14 responses
            105 views
            0 likes
            Last Post martin70  
            Started by TraderBCL, Today, 04:38 AM
            0 responses
            2 views
            0 likes
            Last Post TraderBCL  
            Started by Radano, 06-10-2021, 01:40 AM
            19 responses
            606 views
            0 likes
            Last Post Radano
            by Radano
             
            Started by KenneGaray, Today, 03:48 AM
            0 responses
            4 views
            0 likes
            Last Post KenneGaray  
            Started by thanajo, 05-04-2021, 02:11 AM
            4 responses
            470 views
            0 likes
            Last Post tradingnasdaqprueba  
            Working...
            X