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

Entry and stops work fine but target never reaches OnExecution()

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

    Entry and stops work fine but target never reaches OnExecution()

    It's been a while since I've created a new strategy but I'm having an issue that I don't remember having before.

    In my onbarupdate() I create the entry order when it is needed.

    This updates and fires without trouble. When OnExecution() is called with the entry order it changes the variables to allow my stop and target to be placed. In the past I have had the stop and target created within the OnExecution() but because this system updates intrabar this shouldn't be an issue.

    The stop and target get placed and I am now correctly sitting in the trade. As it moves my direction it will update the stop and keep the wide target in the same location. If the stop gets hit it correctly sends to the OnOrderupdate() and onexecution() and resets the system so that it can keep trading.

    However for some reason unknown to me when the target is hit it will take profit as it should but then never reset. I've traced orders and added print statements to both onorderupdate() and onexecution and the targetOrder never gets sent to either.

    the syntax of my orders:
    Code:
    targetOrder1 = ExitShortLimit(0, true, amountFilled, priceFilledAt-4, "Limit Short Exit 1", "Counter Short Entry 1");
    
    stopOrder1     = ExitShortStop(0, true, amountFilled, shortStopLocation, "Stop Market Short Exit 1", "Counter Short Entry 1");
    
    ------------------------------
    protected override void OnExecution(IExecution execution)
    {
    if(targetOrder1 != null && targetOrder1 == execution.Order)
                    Print("THIS IS NEVER HIT");
    
    if(stopOrder1!= null && stopOrder1== execution.Order)
                    Print("THIS IS HIT");
    }

    #2
    shazzmoe, can you try printing out every execution and see if the target execution comes through there before you start trying to match it?
    Code:
    protected override void OnExecution(IExecution execution)
    {
       Print(execution.ToString());
    }
    AustinNinjaTrader Customer Service

    Comment


      #3
      it does look like it is being sent. I'm getting the following execution printed:

      Execution='01871fcc1ccf442c83739de2a7bf90fb' Instrument='TF 09-11' Account='Sim101' Name='Limit Short Exit 1' Exchange=Default Price=684.6 Quantity=1 Market position=Long Commission=0 Order='bce19e02b83c4c27adbfd0d55ec2ce37' Time='8/12/2011 5:26:36 PM'

      But now I'm baffled as to why it wouldn't be getting matched properly. The Name posted here matches the one I have tied with targetOrder1.

      Right now I'm thinking of trying to do a name based match but I'd rather try and solve this issue.

      Comment


        #4
        I'll also note that the targetOrder1 does get matched properly in the OnOrderUpdate when it is first placed, just never after that

        Comment


          #5
          Could you please send over your full script so I can test this out and see what could be going on?
          AustinNinjaTrader Customer Service

          Comment


            #6
            unfortunately I can't send over the entire script but thanks to the print statement you've shown me I have found the issue.

            For some reason the instant the target is filled targetOrder1 is set to null. The only place in all of my code that sets this to null is within the match that is never reached (and variable declaration).

            My output window is basically like this. The first line of OnExecution prints the order that is displayed. Notice it's getting set to null just before this.

            target not null
            target not null
            target not null
            target not null
            target not null
            target not null
            target null
            EXECUTION: Execution='c4dbae01aecd477c962e514abf64b749' Instrument='TF 09-11' Account='Sim101' Name='Limit Short Exit 1' Exchange=Default Price=650.5 Quantity=1 Market position=Long Commission=0 Order='a3a8534592f04733bbea42caf5067bbc' Time='8/12/2011 6:50:35 PM'
            target null
            target null
            target null
            target null


            onbarupdate contains
            Code:
            if(targetOrder1 == null)
                            Print("target null");            
                        else
                            Print("target not null");

            Comment


              #7
              Hi shazzmoe,

              Sidenote: It's best practice to assign null to your order objects once they reach a filled or cancelled state. Maybe you have this in from copying OnOrderUpdate() examples?

              I would not know what your strategy is doing, but if you can post a simplified version here we can take a look.
              Ryan M.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by thumper57, Yesterday, 04:30 PM
              1 response
              9 views
              0 likes
              Last Post NinjaTrader_BrandonH  
              Started by dcriador, Yesterday, 12:06 PM
              1 response
              16 views
              0 likes
              Last Post NinjaTrader_BrandonH  
              Started by dcriador, Yesterday, 12:04 PM
              1 response
              18 views
              0 likes
              Last Post NinjaTrader_BrandonH  
              Started by cutzpr, Yesterday, 08:54 AM
              1 response
              14 views
              0 likes
              Last Post NinjaTrader_BrandonH  
              Started by gcztraders, Yesterday, 03:58 AM
              1 response
              17 views
              0 likes
              Last Post NinjaTrader_BrandonH  
              Working...
              X