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 delay entry after a profitable trade?

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

    How to delay entry after a profitable trade?

    Hi,

    I have exit strategy as below:

    SetProfitTarget("Long1", CalculationMode.Percent, MyProfitPercent);
    SetStopLoss("Long1", CalculationMode.Percent, MyStopPercent, true);

    If a trade is stopped out, it's ok, the next trade can be triggered any time if the condition is met. But if a trade reaches the profit target, I want the program to wait a certain number of bars even though the condition is met again. How to do this?

    In my case, when a trade reaches profit target, the next trade triggers immediately because the condition is met again... I want to avoid this, but I don't want to limit my program to have only one trade a day, besides for stopped out case, it's ok to let the next trade happen once the condition is met.

    Thanks.

    #2
    Originally posted by ShadowKnows View Post
    Hi,

    I have exit strategy as below:

    SetProfitTarget("Long1", CalculationMode.Percent, MyProfitPercent);
    SetStopLoss("Long1", CalculationMode.Percent, MyStopPercent, true);

    If a trade is stopped out, it's ok, the next trade can be triggered any time if the condition is met. But if a trade reaches the profit target, I want the program to wait a certain number of bars even though the condition is met again. How to do this?

    In my case, when a trade reaches profit target, the next trade triggers immediately because the condition is met again... I want to avoid this, but I don't want to limit my program to have only one trade a day, besides for stopped out case, it's ok to let the next trade happen once the condition is met.

    Thanks.
    Do you have a defined code block that resets variables at the start of the day/session?

    Comment


      #3
      Originally posted by ShadowKnows View Post
      Hi,

      I have exit strategy as below:

      SetProfitTarget("Long1", CalculationMode.Percent, MyProfitPercent);
      SetStopLoss("Long1", CalculationMode.Percent, MyStopPercent, true);

      If a trade is stopped out, it's ok, the next trade can be triggered any time if the condition is met. But if a trade reaches the profit target, I want the program to wait a certain number of bars even though the condition is met again. How to do this?

      In my case, when a trade reaches profit target, the next trade triggers immediately because the condition is met again... I want to avoid this, but I don't want to limit my program to have only one trade a day, besides for stopped out case, it's ok to let the next trade happen once the condition is met.

      Thanks.
      Hi ShadowKnows,

      Thanks for posting!

      To create a delay in the entry you can use the BarsSinceExit method to determine when to enter in a trade.

      After your profit trigger, you can have an if statement that uses BarsSinceExit() set to a number of bars after it and if your still being profitable.

      Look something like this.
      Code:
      if ((BarsSinceExit() > 10 || BarsSinceExit() == -1) && CrossAbove(SMA(10), SMA(20), 1))
               EnterLong();
      Click here for more info on using BarsSinceExit()

      Let me know if I can be of further assistance
      Cal H.NinjaTrader Customer Service

      Comment


        #4
        Originally posted by NinjaTrader_Cal View Post
        Look something like this.
        Code:
        if ((BarsSinceExit() > 10 || BarsSinceExit() == -1) && CrossAbove(SMA(10), SMA(20), 1))
                 EnterLong();
        Click here for more info on using BarsSinceExit()

        Let me know if I can be of further assistance
        Thanks a lot, Cal. It's pretty much what I was looking for. But there is one more thing, is it possible to know if the last exit is a stop-out or a profit target?

        I want to wait only when the last exit is due to hitting the target.

        Thanks.

        Comment


          #5
          Originally posted by ShadowKnows View Post
          Thanks a lot, Cal. It's pretty much what I was looking for. But there is one more thing, is it possible to know if the last exit is a stop-out or a profit target?

          I want to wait only when the last exit is due to hitting the target.

          Thanks.
          Hence my question. You are going to need a bool to keep track of that, and that bool will have to be reset. Easiest is to reset at start of the day's trading, but I guess we can finagle it to happen somewhere else, using the TradesPerformance class to determine if the last trade was a profit or loss.

          Comment


            #6
            Originally posted by koganam View Post
            Hence my question. You are going to need a bool to keep track of that, and that bool will have to be reset. Easiest is to reset at start of the day's trading, but I guess we can finagle it to happen somewhere else, using the TradesPerformance class to determine if the last trade was a profit or loss.
            There are multiple trades per day, it seems not possible to use TradesPerformance to determine if the last trade was a profit or loss?

            Comment


              #7
              Hi ShadowKnows,

              I have linked a great reference sample from our support forum on using the TradesPerformance and using that as a key to getting last trades profit.

              http://www.ninjatrader.com/support/f...ead.php?t=4084

              There is also a section in our online help guide that will explain the optioin with using TradesPerformance. You can test for a losing trade or winning trade
              http://www.ninjatrader.com/support/h...collection.htm
              Cal H.NinjaTrader Customer Service

              Comment


                #8
                Originally posted by ShadowKnows View Post
                There are multiple trades per day, it seems not possible to use TradesPerformance to determine if the last trade was a profit or loss?
                You can always determine if a particular trade was a profit or loss, especially the last trade, no matter how many trades there have been.

                Comment


                  #9
                  Thanks a lot. I think I got it.

                  Comment


                    #10
                    I want to use barsinceexit before entering into a new trade but if that is part of the condition set it will never trigger an entry b/c the very first trade was not coming out on another trade - how do i get around that. my coding skills are weak

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by andrewtrades, Today, 04:57 PM
                    1 response
                    8 views
                    0 likes
                    Last Post NinjaTrader_Manfred  
                    Started by chbruno, Today, 04:10 PM
                    0 responses
                    5 views
                    0 likes
                    Last Post chbruno
                    by chbruno
                     
                    Started by josh18955, 03-25-2023, 11:16 AM
                    6 responses
                    436 views
                    0 likes
                    Last Post Delerium  
                    Started by FAQtrader, Today, 03:35 PM
                    0 responses
                    7 views
                    0 likes
                    Last Post FAQtrader  
                    Started by rocketman7, Today, 09:41 AM
                    5 responses
                    19 views
                    0 likes
                    Last Post NinjaTrader_Jesse  
                    Working...
                    X