Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to Wait 1 Bar

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

    How to Wait 1 Bar

    I have issues resetting a bool after 1 bar - this Strategy runs onpricechange

    Example WaitONEBarafteranyExit=false, exit occurs, do the following WaitONEBarafteranyExit=true

    I just want when True, after close of current bar that implemented the True state, change back to False

    I USED THE FOLLOWING

    IF ALL
    WaitONEBarafteranyExit=true
    BarsSinceExitExecution(0,"",0)>0

    do the following

    WaitONEBarafteranyExit=false

    SIMPLE ENOUGH YOU WOULD THINK - BUT NOT WORKING

    #2
    I may have had another conflict with this. But if any one sees why this will not work as i have above please Post - Thanks

    Comment


      #3
      I have another similar issue that I have not resolved.

      Have a Condition of Rules become True and a int variable that defaults to 1 XYZ =1

      On condition Rules True XYZ = 2

      ISSUE i only want the Trade to send an order for 1 bar after XYZ = 2 , so of course XYZ = 2 is included in conditions for a Trade

      What I do not know is how to return XYZ = 2 back to XYZ = 1 after the next bar closes

      Thanks

      Comment


        #4
        Hello DTSSTS,

        It sounds like you are setting and checking the state of your own bool.

        When you are printing this value with the time, does this have the value you are expecting?

        Are you printing when the value is being set and this is not when expected?

        Can we see the output from your prints?

        Are you asking how to use BarsSinceExitExecution()?
        https://ninjatrader.com/support/help...texecution.htm

        This would give the number of bars since the last exit. This will return -1 if there has never been an exit.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          I understand what you state about BarsSinceExitExectiion()

          I have resolved the issue in the beginning of the post

          the second item i need help with . I am NOT setting and checking the state of my own bool.

          I am setting my own bool. I do know that the state of that bool will remain True for an extended period of bars (if those condition change then of course we change the bool to false)

          Also if an entry is made we reset the bool to false as well. WHAT I NEED HELP with is IF we do NOT have an entry on the next bar after bool statement is True, if if the conditions that switch the state from false to true, I WANT TO change the bool back to false.

          so when switch to True ONLY REMAIN TRUE FOR 1 BAR (This nothing to do with any entries or exits - as there are none)

          Comment


            #6
            Hello DTSSTS,

            To confirm, if the condition that enters an order does not evaluate as true on the bar after an entry is placed, you want to set your bool to false?

            Add the assignment to false in an else.

            if (Position.MarketPosition == MarketPosition.Long && /* conditions to enter trade here */)
            {
            // execute code to enter trade
            }
            else
            {
            myBool = false
            }
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              NOT confirm, the entry or position have NOTHING to do with this reset to false

              The particular is that this is an Variable int default to 1, if conditions become as needed then Int = 2 as that bar closes

              Then we have int = 2, when int = 2 other conditions are checked for a trade

              IF not trade occurs on the first bar that int = 2 then on bar close return int = 1 (back to default

              so each time int = 2 and no trade occurs immediately we return to 1

              thanks

              Comment


                #8
                Hello DTSSTS,

                I'm having trouble following the issue.

                Are you trying to set WaitONEBarafteranyExit to false?

                When would you like to do this?

                Would you like to do this one bar after an exit?

                Trigger the event when BarsSinceExitExecution() is 1.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by DTSSTS View Post
                  I have another similar issue that I have not resolved.

                  Have a Condition of Rules become True and a int variable that defaults to 1 XYZ =1

                  On condition Rules True XYZ = 2

                  ISSUE i only want the Trade to send an order for 1 bar after XYZ = 2 , so of course XYZ = 2 is included in conditions for a Trade

                  What I do not know is how to return XYZ = 2 back to XYZ = 1 after the next bar closes

                  Thanks
                  Sorry you did not read the 3rd post

                  I also reply earlier "understand what you state about BarsSinceExitExectiion()

                  I have resolved the issue in the beginning of the post"

                  I ONLY NEED HELP WITH THE QUOTED ITEM

                  Comment


                    #10
                    the entry or position have NOTHING to do with this reset to false

                    The particular is that this is an Variable int default to 1, if conditions become as needed then Int = 2 as that bar closes

                    Then we have int = 2, when int = 2 other conditions are checked for a trade

                    IF not trade occurs on the first bar that int = 2 then on bar close return int = 1 (back to default

                    so each time int = 2 and no trade occurs immediately we return to 1

                    Comment


                      #11
                      Hello DTSSTS,

                      What is the issue you are having?

                      Is the value not being set when you set it?
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #12
                        YES THE int is set to 2 exactly when i want it to be set

                        my Issue is I wish to set in back to int = 1 after being set to int = 2 for only 1 bar

                        Comment


                          #13
                          Hello DTSSTS,

                          After one bar, what happens when you try and set the value to 1?
                          Chelsea B.NinjaTrader Customer Service

                          Comment


                            #14
                            i do not know how to tell the code to count the bar after the int becomes 2

                            Comment


                              #15
                              Hello DTSSTS,

                              To confirm, this is not related to an entry (or exit), correct?

                              You can wait until the next time OnBarUpdate() runs for the next bar (or if running with Calculate.OnPriceChange or .OnEachTick, wait until the next tile IsFirstTickOfBar is true).

                              If you want to use a counter, below is a link to sample code of a counter.
                              https://ninjatrader.com/support/foru...260#post812260
                              Chelsea B.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by jerminedop, Today, 12:18 AM
                              0 responses
                              5 views
                              0 likes
                              Last Post jerminedop  
                              Started by cnzaxtoil, Yesterday, 11:38 PM
                              0 responses
                              4 views
                              0 likes
                              Last Post cnzaxtoil  
                              Started by cnzaxtoil, Yesterday, 11:37 PM
                              0 responses
                              3 views
                              0 likes
                              Last Post cnzaxtoil  
                              Started by sukhob, Yesterday, 04:27 PM
                              1 response
                              14 views
                              0 likes
                              Last Post zacharydw00  
                              Started by Bmnaiorwsd, Yesterday, 07:52 PM
                              0 responses
                              4 views
                              0 likes
                              Last Post Bmnaiorwsd  
                              Working...
                              X