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

Create a stop order upon a trigger price

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

    Create a stop order upon a trigger price

    How would I code a stop order to trigger at my break even price let say if the stock had gained 1%?

    #2
    Hello,

    Thanks for the note.

    Would you be doing this in the NinjaScript wizard or via the programming in NinjaScript.

    -Brett

    Comment


      #3
      Programming in ninjascript...

      Comment


        #4
        Hello cfree5119,
        I am following up Brett and is happy to assist you.

        You can use Position.AvgPrice to calculate the new stop like

        if (Position.MarketPosition == MarketPosition.Long && Close[0] >= Position.AvgPrice + Position.AvgPrice * .01 )
        {
        SetStopLoss(CalculationMode.Price, Position.AvgPrice);
        }

        The above code is for long only.

        Please let me know if this works for you or not.

        Regards,
        Joydeep.
        JoydeepNinjaTrader Customer Service

        Comment


          #5
          Works great! Thank you.

          Could I also setup say a 5% stoploss in case the security never hits its breakeven price criteria? Sorry, limited programming experience on my end.

          To boot... maybe a price target as well.
          Last edited by cfree5119; 01-09-2012, 05:27 PM.

          Comment


            #6
            Hello,

            Yes, you would use SetStopLoss() before you enter the trade to the value you would like using the method Joydeep demontrated below. Instead of using Position.AvgPrice and MarketPosition however since that does not exist yet since you are not in a position you would instead just use the Close[0] price and find out where the 5% level would be. Then set your original stop loss to that value.

            SetProfitTarget can be used like the following.



            Also here is the reference for SetStopLoss()



            Let me know if any questions.

            -Brett

            Comment


              #7
              I setup my absolute 5% stop loss under the Initialize() method.

              SetStopLoss("Long Turtle Entry", CalculationMode.Percent,stopTrigger1, false);


              I then setup my breakeven stop loss under OnBarUpdate() as:

              if (Position.MarketPosition == MarketPosition.Long && Close[0] >= Position.AvgPrice + Position.AvgPrice * breakEvenStopTrigger)
              {
              SetStopLoss(CalculationMode.Price, Position.AvgPrice);
              }

              The strategy does not recognize the latter when both stop losses are setup. Not sure how to "dynamically" change the sl. Thank you.

              Comment


                #8
                Hello,

                Thanks for the post.

                Make sure they both have the same name. You have one with Long Turtle Entry and one without.

                Finally please see this sample for dynamically changing the SL and PT.

                Comment


                  #9
                  Thank you... tremendous help.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by kulwinder73, Today, 10:31 AM
                  1 response
                  8 views
                  0 likes
                  Last Post NinjaTrader_Erick  
                  Started by RookieTrader, Today, 09:37 AM
                  3 responses
                  15 views
                  0 likes
                  Last Post NinjaTrader_ChelseaB  
                  Started by terofs, Yesterday, 04:18 PM
                  1 response
                  24 views
                  0 likes
                  Last Post terofs
                  by terofs
                   
                  Started by CommonWhale, Today, 09:55 AM
                  1 response
                  6 views
                  0 likes
                  Last Post NinjaTrader_Erick  
                  Started by Gerik, Today, 09:40 AM
                  2 responses
                  8 views
                  0 likes
                  Last Post Gerik
                  by Gerik
                   
                  Working...
                  X