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

Issue "re-setting" a counter

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

    Issue "re-setting" a counter

    Greetings,

    I'm using a "counter" in my strategy code so as to prevent re-submission of orders on each bar when I do not wish them. It works fine, however I'm having an issue with how to best "reset" the counter so as to enable future trade possibilities...here's what I'm doing:

    if("a set of conditions is TRUE" && subsequentCounter < 1)
    {

    //enter a trade...and...set the counter...
    subsequentCounter = 1;
    }

    My code I've been using to "reset" the counter back to "0" is the following:

    if((Position.MarketPosition == MarketPosition.Short) ||
    (Position.MarketPosition == MarketPosition.Long))
    {
    if(subsequentCounter == 1){subsequentCounter = 0;}
    } //reset counter if it needs to be after trade triggers


    The problem with this (I believe) is that since this code is calculated only upon bar close...if a trade is entered AND exited INTRA-BAR the counter is never going to be "reset"...this causes problems with future trade conditions not triggering trades. I'm looking for suggestions on how to best correct this?

    #2
    If you are using NT6.5 you can easily accommodate for this by coding in the OnPositionUpdate() method.

    When you receive a "filled" event then you submit your counter reset.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Hi,

      Thanks for the response. My version is 6.0.1000.6 (demo). Are you saying that in version 6.5 there's something called an "OnPositionUpdate" function that is called when orders are placed and/or conditions for order entry have become true?

      Comment


        #4
        Yes, version NT 6.5 Beta. You can download the beta within this forum. Please keep in mind that this level of functionality is aimed at advanced programmers.
        RayNinjaTrader Customer Service

        Comment


          #5
          Hi,

          So is the Beta necessary for what I wish to do? Is there no equivilant command to use that signifies a "filled" or potentially filled order?

          Comment


            #6
            You can always check Position.Quantity to see what is filled etc...
            RayNinjaTrader Customer Service

            Comment


              #7
              OK, so it sounds like I could re-write my "reset" code to read:

              if((Position.Quantity == 0)
              {
              if(subsequentCounter == 1){subsequentCounter = 0;}
              } //reset counter if it needs to be after trade triggers


              I'm assuming that if "Position.Quantity" returns "0" that no positions are "open", correct?

              Comment


                #8
                That is correct.
                RayNinjaTrader Customer Service

                Comment


                  #9
                  Thanks. Is there a way to associate "Position.Quantity" with different potential trade conditions? So if a strategy for example had 4 conditions that might initiate trade activity when conditions were true is it possible to know which of those "Positions" have quantity values open associated with them?

                  Comment


                    #10
                    This is not possible.
                    RayNinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by PhillT, 04-19-2024, 02:16 PM
                    3 responses
                    16 views
                    0 likes
                    Last Post mangel2000  
                    Started by TraderBCL, Today, 02:37 AM
                    0 responses
                    1 view
                    0 likes
                    Last Post TraderBCL  
                    Started by mangel2000, Today, 02:23 AM
                    0 responses
                    7 views
                    0 likes
                    Last Post mangel2000  
                    Started by mangel2000, Today, 01:30 AM
                    0 responses
                    14 views
                    0 likes
                    Last Post mangel2000  
                    Started by Doxxxx, Today, 01:24 AM
                    0 responses
                    7 views
                    0 likes
                    Last Post Doxxxx
                    by Doxxxx
                     
                    Working...
                    X