Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to prevent multiple trades on current bar?

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

    How to prevent multiple trades on current bar?

    Hello All,

    I am working in Strategy Builder. When my strategy executes a new trade, once the profit target or the stop loss are hit, another trade is generated. New trades are created and target filled or stopped out, over and over, until the next bar is generated.

    Is there a way to prevent subsequent trades while on the current bar? I have added into conditions the following, but it seems to be ignored... Position.MarketPosition = MarketPosition.Flat

    I would appreciate your help on this...

    Thank you in advance!
    Last edited by jmyonan3; 03-23-2022, 11:22 AM.

    #2
    Hello jmyonan3,

    You would generally use Position.MarketPosition = MarketPosition.Flat to do that, as long as the entry was filled then on the next OnBarUpdate call the position will be updated. If you used OnEachTick that generally would be the next tick.

    Do you have a screenshot of your entry condition set so I can see how you had used the position in the condition?

    Comment


      #3
      Hi Jesse,

      Thank you for jumping in to help me. Here are four screenshots including; logs, code, and a Strategy Analyzer report...nothing fancy here. I also have attached a three day back test. Crazy erratic results...

      Thanks!
      Last edited by jmyonan3; 03-23-2022, 12:23 PM.

      Comment


        #4
        Hello jmyonan3,

        That may relate to using Tick Replay. I would suggest to turn that off, your strategy is not utilizing any of the features which Tick Replay provides and that does not help with execution granularity.

        Comment


          #5
          Hi Jesse,

          Turning off Tick Replay sort of solves the problem related to Strategy Analyzer. But it is my understanding that I have more accurate results when Tick Replay is turned on.

          I thought it would be beneficial to see the behavior, so I ran in playback mode and recorded my screen. I hope this helps. When I am calculating the strategy on bar close, no problems arise (although I am NOT entering any trades at the price I want). However, when I turn on the strategy "Calculate" drop down box to "On each tick", the problem in the following linked video occurs.



          Please advise...thank you!

          Comment


            #6
            Hi Jesse,

            If you watch my video, after each order (long or short) is initiated and closed, there is a momentary gap in between when the position is flat...and once it's flat, it enters another trade. There must be a way inside Strategy Builder to set a flag where it is true while on the triggering bar and resets when it has moved on to the next bar. If this type of filtering is possible, it will prevent the successive trades from occurring.

            Is there any method of achieving this type of condition from within Strategy Builder and without hand coding?

            Thanks in advance!
            Last edited by jmyonan3; 03-23-2022, 04:57 PM.

            Comment


              #7
              Hello Jesse,

              I have been searching this forum and I believe I found the answer...but I may need some direction in implementing it.

              Here it is...

              ******************
              "Regarding BarsSinceEntryExecution() if the issue is that you are not getting any entries at all then yes you need to account for the first trade. With reference to the help guide for the method: https://ninjatrader.com/support/help...yexecution.htm You would need to check for a value of -1 OR the number of bars. So -1 means there is no previous entry. You would need to create a "group" in the condition set and the groupd would need to be set to "If Any" and then you would enter the two conditions of checking for 1 bar or checking for a -1. If either of the conditions are true then that group would be true."

              "If the issue is that regardless of the BrasSinceEntryExecution() setting that you are getting multiple entries per bar then that is a result of using Calculate.OnEachTick (or Calculate.OnPriceChange), either of those calculate modes allows the strategy to process much faster than the ability to transmit orders and receive their acknowledgement which would then allow BarsSinceEntrytExecution to work. The order process runs asynchronously to the strategy code so this means that you will need to implement your own logic controls to meet your needs. One way that you can do this is to use the current bar number. The Current Bar number changes when a new bar is formed. What you can do is create an int variable type (for example called savedBar) and in the entry conditions you would check if Misc>Current Bar is NOT equal to User Variables>savedBar and if true and your other entry conditions are true then the order is placed. In the order action section you then add the action to assign the current bar to the savedBar which prevents any further orders until the next bar. "

              *******************

              Are you able to assist in implementing the above configuration? I believe my situation is like the second paragraph.

              Thank you again for your help!

              Comment


                #8
                Hi Jesse,

                I figured it out with a lot of help from a post from March of 2020 (partially shown above). I implemented the solution identified by one of your associates there at NinjaTrader (Paul H.). The post was titled "Cant get "Bars since entry" to work".

                The second paragraph was exactly what I needed!

                Once again, thank you for your help!

                Take Care!
                Last edited by jmyonan3; 03-23-2022, 06:48 PM.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by NullPointStrategies, Today, 05:17 AM
                0 responses
                51 views
                0 likes
                Last Post NullPointStrategies  
                Started by argusthome, 03-08-2026, 10:06 AM
                0 responses
                127 views
                0 likes
                Last Post argusthome  
                Started by NabilKhattabi, 03-06-2026, 11:18 AM
                0 responses
                69 views
                0 likes
                Last Post NabilKhattabi  
                Started by Deep42, 03-06-2026, 12:28 AM
                0 responses
                42 views
                0 likes
                Last Post Deep42
                by Deep42
                 
                Started by TheRealMorford, 03-05-2026, 06:15 PM
                0 responses
                46 views
                0 likes
                Last Post TheRealMorford  
                Working...
                X