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

Reverse at Stop

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

    Reverse at Stop

    I would like to reverse my strategy position if my stop is hit. I don't rhink I 've seen any methods to do that. How do I know when my stop is hit, in order to issue the opposite order? What is the best way I can do this using the available Ninjascript functionality?

    #2
    Just place a EnterShortStop() order if you were long and it will automatically reverse you when the stop is hit.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Thanks,

      How about reversing on a trail stop?

      Originally posted by Josh View Post
      Just place a EnterShortStop() order if you were long and it will automatically reverse you when the stop is hit.

      Comment


        #4
        Check for your position direction. If your trail stop is hit your position would be zero at that moment place a short order if you were long.

        Code:
        bool enteredLong = false;
        if (Close[0] > Open[0])
        {
             EnterLong();
             enteredLong = true;
        }
        if (enteredLong && Position.MarketPosition == MarketPosition.Flat)
        {
             EnterShort();
             enteredLong = false;
        }
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Revers trailing stop

          Hello Josh,

          I am also interested to know how to reverse a trailing stop but the code you posted does not work and I can not achive to make it work.
          The strategy goes long all the time the trailing stop is trigered but never short.
          I supose this happense because you declared the bool = false in OnBarUpdate so after the strategy goes Long and enterlong is set to = true, the next bar enterlong is again reseted to false (or am I wrong??), so the strategy goes always long.
          I can not leave the bool without asigning a valuo but I also do not achive to asigne the bool corectly in Initialize (allways get the error, entered long does not exist in the current context), so I dont know haw to make it work.

          Can someone help out please.



          Originally posted by Josh View Post
          Check for your position direction. If your trail stop is hit your position would be zero at that moment place a short order if you were long.

          Code:
          bool enteredLong = false;
          if (Close[0] > Open[0])
          {
               EnterLong();
               enteredLong = true;
          }
          if (enteredLong && Position.MarketPosition == MarketPosition.Flat)
          {
               EnterShort();
               enteredLong = false;
          }
          Last edited by whitegun; 04-03-2008, 08:53 AM.

          Comment


            #6
            Hi whitegun,

            Your initial assessment is correct. I only threw out a general framework. You would normally want the bool in the "Variables" section of your code. This section is above the Initialize() method. Do

            private bool enteredLong = false;
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Flatten All Positions ?

              Under a strategy, is there any way to check for open positions; and if found, then flatten everything ?

              Like..

              if (Position.MarketPosition != MarketPosition.Flat)
              {
              .. Flatten everything !
              }

              Just curious.

              Comment


                #8
                There is no access to the account level position which is what I suspect you mean.
                RayNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by samish18, 04-17-2024, 08:57 AM
                16 responses
                55 views
                0 likes
                Last Post samish18  
                Started by arvidvanstaey, Today, 02:19 PM
                3 responses
                9 views
                0 likes
                Last Post NinjaTrader_Zachary  
                Started by jordanq2, Today, 03:10 PM
                2 responses
                8 views
                0 likes
                Last Post jordanq2  
                Started by traderqz, Today, 12:06 AM
                10 responses
                18 views
                0 likes
                Last Post traderqz  
                Started by algospoke, 04-17-2024, 06:40 PM
                5 responses
                47 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Working...
                X