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

how to wait for 1 bar after profit is hit

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

    how to wait for 1 bar after profit is hit

    Hello,
    I am working with the strategy builder. but I have one problem:
    - the strategy re-enters a trade immediately after taking profit. I want if to wait for another bar.

    I used BarsSinceExit() but it also waited after hitting a stop. So that's not what I wanted from the strategy. I only want it to wait after taking profit, not after every single exit.

    Thanks in advance...

    #2
    Hello Hussein,

    Thank you for your inquiry.

    What you could do is monitor in OnOrderUpdate to see that it was in fact a profit target that's filled, and when that occurs set a bool. Then, in OnBarUpdate you can check both BarsSinceExitExecution() and your bool, and if the bool was set to true because a profit target filled and it's been one bar then enter again.

    Here's a link to another post showing how to check which type of order filled:



    Please let us know if we may be of further assistance to you.
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Thanks Kate,

      I understand the logic behind it. But I can't seem to find the OnOrderUpdate nor OnBarUpdate functions anywhere under the set of conditions in strategy builder. Or am i looking in the wrong place?

      Comment


        #4
        Hello Hussein,

        Thank you for your reply.

        Unfortunately there would be no way to use this approach in the Strategy Builder - I apologize as I missed that in your original post. What you could do in the builder is to use the Signal Name for the profit target when setting BarsSinceExit. If you want to specify that it waits 1 bar after a profit target is hit, you can use the Signal Name "Profit target" in the settings for Bars Since Exit to specify that you're only checking for whether it's one bar since a profit target was hit.

        Please let us know if we may be of further assistance to you.
        Kate W.NinjaTrader Customer Service

        Comment


          #5
          problem solved

          ​​​​​​​Thank you very much Kate,

          Comment


            #6
            Originally posted by NinjaTrader_Kate View Post
            Hello Hussein,

            Thank you for your reply.

            Unfortunately there would be no way to use this approach in the Strategy Builder - I apologize as I missed that in your original post. What you could do in the builder is to use the Signal Name for the profit target when setting BarsSinceExit. If you want to specify that it waits 1 bar after a profit target is hit, you can use the Signal Name "Profit target" in the settings for Bars Since Exit to specify that you're only checking for whether it's one bar since a profit target was hit.

            Please let us know if we may be of further assistance to you.
            Hi Kate or Hussein,

            I am trying to solve the same problem as you, Hussein, which is why I am posting this here. I tried to follow the instructions using BarsSinceExit in this thread but I am not doing it right. I hope you can offer some assistance.

            Ultimately, I would like the next trade placed to not be on the same bar as the previous trade. I would like one trade to occur, hit my profit or stop loss, then have the auto strategy wait until entry conditions are met again at a different time to enter it's next trade.

            I attached a picture of my strategy builder code. I also have a profit target set up on the next page of 4 ticks.

            Thanks, in advance for the help.

            -Maria
            Attached Files

            Comment


              #7
              Hello marialewis16,

              Thank you for your reply.

              The issue here is that you're checking for whether the strategy has already exited previously, but not whether it has entered at all. As you have it set up here, this would never enter because you haven't had a previous exit when the first entry would be placed.

              When no prior entries have been made, BarsSinceEntryExecution returns a -1, so we need to make a condition group that says if at least 1 bar has passed OR if no trades have been taken, then enter:

              Click image for larger version

Name:	2021-03-24_07-47-21.png
Views:	401
Size:	14.1 KB
ID:	1148260

              Please let us know if we may be of further assistance to you.
              ​​​​​​​
              Kate W.NinjaTrader Customer Service

              Comment


                #8
                Originally posted by NinjaTrader_Kate View Post
                Hello marialewis16,

                Thank you for your reply.

                The issue here is that you're checking for whether the strategy has already exited previously, but not whether it has entered at all. As you have it set up here, this would never enter because you haven't had a previous exit when the first entry would be placed.

                When no prior entries have been made, BarsSinceEntryExecution returns a -1, so we need to make a condition group that says if at least 1 bar has passed OR if no trades have been taken, then enter:

                Click image for larger version  Name:	2021-03-24_07-47-21.png Views:	0 Size:	14.1 KB ID:	1148260

                Please let us know if we may be of further assistance to you.
                Hi Kate, thank you so much for getting back to me about this, I really appreciate it. I made a condition group like you said but it still repeats order entries multiple times on the same bar. It only shows one entry when I apply the strategy to a static chart which makes it seem like it works, but when I test it in playback, it goes crazy. There should only be one rt trade there.

                I attached a picture of the trades and the builder. Maybe you can spot what I am doing wrong with the picture? I was going to move it in Set 2 but then I didn't know what would go in the "do the following" box since it is still a condition of Set 1. Also I have it set to "On Each Tick" because I want the entry as the bar is printing. All I want it to do is make one scalp, then move on until another trade sets up again later. I am sorry I can't figure it out.

                -Maria
                Attached Files
                Last edited by marialewis16; 03-24-2021, 05:13 PM.

                Comment


                  #9
                  Hello marialewis16,

                  Thank you for your reply.

                  You're using the incorrect signal name for the profit target. The correct signal name would be "Profit target" with the t in target not capitalized. It's also worth noting that if you are also using a stop loss and the position closes using that order, this would not apply, and you'd be more than 1 bar after a profit target exit so a new order would likely be immediately submitted again if the stop is hit.

                  Please let us know if we may be of further assistance to you.
                  Kate W.NinjaTrader Customer Service

                  Comment


                    #10
                    Originally posted by NinjaTrader_Kate View Post
                    Hello marialewis16,

                    Thank you for your reply.

                    You're using the incorrect signal name for the profit target. The correct signal name would be "Profit target" with the t in target not capitalized. It's also worth noting that if you are also using a stop loss and the position closes using that order, this would not apply, and you'd be more than 1 bar after a profit target exit so a new order would likely be immediately submitted again if the stop is hit.

                    Please let us know if we may be of further assistance to you.
                    Thanks Kate! Duh, rookie move on my part. Thanks for the help and for mentioning the stop loss factor. That is good to know!

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by sidlercom80, 10-28-2023, 08:49 AM
                    168 responses
                    2,262 views
                    0 likes
                    Last Post sidlercom80  
                    Started by Barry Milan, Yesterday, 10:35 PM
                    3 responses
                    10 views
                    0 likes
                    Last Post NinjaTrader_Manfred  
                    Started by WeyldFalcon, 12-10-2020, 06:48 PM
                    14 responses
                    1,429 views
                    0 likes
                    Last Post Handclap0241  
                    Started by DJ888, 04-16-2024, 06:09 PM
                    2 responses
                    9 views
                    0 likes
                    Last Post DJ888
                    by DJ888
                     
                    Started by jeronymite, 04-12-2024, 04:26 PM
                    3 responses
                    41 views
                    0 likes
                    Last Post jeronymite  
                    Working...
                    X