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

Unmanaged + BarsSinceEntry

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

    Unmanaged + BarsSinceEntry

    I cannot get barssinceentry() to work with unmanaged exits.

    I have tried custom logic to determine the # of bars using CurrentBar() and it wont work either.

    What i want to do is enter my long position within the onbarupdate() method and my exits are triggered within the Onexecution() method. I need 1 bar delay (do not want orders entering and exiting on the same bar)

    I have no compile errors but if i try to set a condition within onexecution() similar to below:


    if (myBarsSinceEntry() > 1)
    {
    exitlimit = Submitorder()
    }


    with myBarsSinceEntry() =
    {
    CurrentBar-myEntryBar;

    }




    myEntryBar = CurrentBar is located within the entry order {} within the onbarupdate method.

    Any help would be appreciated.

    #2
    neb1998, bars don't really exist inside the OnExecution() method, so you'll have to keep track of CurrentBar within the OnBarUpdate() method. You could create a new variable (something like myCurrentBar), and then update it everytime OnBarUpdate() is called.
    Code:
    // in variables
    int myCurrentBar = 0;
    
    OnBarUpdate()
    {
    myCurrentBar = CurrentBar;
    // other code goes here
    }
    AustinNinjaTrader Customer Service

    Comment


      #3
      Yeah i have done that also, is there a way to delay the onexecution method from executing?

      Comment


        #4
        neb1998, it is not possible to delay the OnExecution() method.
        AustinNinjaTrader Customer Service

        Comment


          #5
          Well if i am correct in my understanding of how onexecution works....As soon as my long orders are filled, onorderupdate, then onexecution proceed in this order. If an order gets to onexecution and my long order is the only outstanding order it would make sense that it will not be executed again till another fill order would take place, is this correct?

          Comment


            #6
            IT would seem if this is the case that barssinceentry or any other equation could not be used to delay the exits from executing during backtesting if the onexecution method is used.

            Unless the onexecution method can again be recalled from the onbarupdate with some custom code? Say after x bars since entry.

            Comment


              #7
              neb, can you please clarify this statement "If an order gets to onexecution and my long order is the only outstanding order it would make sense that it will not be executed again till another fill order would take place, is this correct"?

              As I said, there is no concept of bars in the OnExecution() method, so you won't be able to use BarsSinceEntry() there. It is also unfortunately not possible to call the method again with custom code.
              AustinNinjaTrader Customer Service

              Comment


                #8
                I mean if i place one submitorder prior to onexecution, within the onbarupdate method and the order is filled. On execution is then called (after onorderupdate). Whatever code i have within onexecution will execute once.

                If my long order remains the onexecution method will not be run again till i have a new fill (next long order) etc...

                Meaning that once an order is filled the onexecution method is executed once per order filled. Which would basically eliminate anyway to delay an exit from being delayed a bar with code within the onexecution method. Which means all my exits will need to be outside of the onexecution method.

                Strat is 1 entry long
                4 exits, 2 limit, 2 stop.
                2 of the stops are fire and forget from on execution
                and 2 are limit exits that fire and update within the onbarupdate method after execution.

                This all works fine. I just do not want the entry and exit on the same 15 min primary bar.

                Comment


                  #9
                  You're correct in your understanding, you would work then not from the OnExecution() method for this purpose - if the bars timing is not what you need / seek you could also work with custom timers in C# to provide the event order / sequence you need.
                  BertrandNinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by mintos, 04-02-2024, 08:22 PM
                  10 responses
                  44 views
                  0 likes
                  Last Post mintos
                  by mintos
                   
                  Started by cmtjoancolmenero, Yesterday, 02:31 PM
                  7 responses
                  23 views
                  0 likes
                  Last Post NinjaTrader_ChelseaB  
                  Started by hdge4u, 04-29-2024, 12:23 PM
                  3 responses
                  19 views
                  0 likes
                  Last Post MisterTee  
                  Started by PaulMohn, 04-24-2024, 03:49 AM
                  5 responses
                  40 views
                  0 likes
                  Last Post NinjaTrader_ChelseaB  
                  Started by claxxical, 05-30-2017, 12:30 PM
                  38 responses
                  4,482 views
                  0 likes
                  Last Post alancurry  
                  Working...
                  X