Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Falling Unrealized Profit Signal for Exit Help

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

    Falling Unrealized Profit Signal for Exit Help

    Hi, I'm new to ninjatrader so sorry if this is a somewhat basic question.

    I want to add in a condition to an automated trading strategy that if my unrealized profit starts to fall by a certain amount (ticks or % or $) it sends a signal to exit the trade. For example, if you had a profit target of $300 and the strategy gets to $250 and starts to fall, the signal would exit the position after a loss of 20%. What's the best way to add in this condition?

    Thanks!

    #2
    Hello,
    Can you clarify if you are referring to a 20% loss from entry or 20% loss from the position being up $250?
    Cody B.NinjaTrader Customer Service

    Comment


      #3
      A 20% loss from the position being up $250

      Comment


        #4
        Hello,
        I have provided an example below of how you could achieve this. Please let me know if you have any questions on this example.
        Code:
        private bool profitRisk = false;
        private double profitPrice = 0;
        
        protected override void OnBarUpdate()
        {
        	if(Position.GetProfitLoss(Close[0], PerformanceUnit.Currency) = 250 && !profitRisk)
        	{
        		profitPrice = Close[0];
        		profitRisk = true;
        	}
        	if(profitRisk && profitPrice != 0)
        		if((profitPrice - Close[0])/ 100 == 0.2)
        			ExitLong();
        }
        Cody B.NinjaTrader Customer Service

        Comment


          #5
          Thank you so much!

          if(Position.GetProfitLoss(Close[0], PerformanceUnit.Currency) = 250 && !profitRisk)

          For this component is it possible to adjust the if statement to a value that is equal to or greater than?

          Comment


            #6
            Hello,
            Yes you would be able to substitute the =(note: should be == I apologize for the typo) with >=
            Cody B.NinjaTrader Customer Service

            Comment


              #7
              One last question: How can I modify the code to add in a condition to exit for a short as well?

              Thanks again

              Comment


                #8
                Hello,
                You would use ExitShort(); to submit an exit order to a short position.
                If you have not reviewed the order methods I would recommend to do so at the following link: http://ninjatrader.com/support/helpG...er_methods.htm
                Cody B.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by lorem, Today, 09:18 AM
                0 responses
                2 views
                0 likes
                Last Post lorem
                by lorem
                 
                Started by hazylizard, Today, 08:38 AM
                4 responses
                11 views
                0 likes
                Last Post hazylizard  
                Started by geddyisodin, Today, 05:20 AM
                2 responses
                20 views
                0 likes
                Last Post geddyisodin  
                Started by Max238, Today, 01:28 AM
                5 responses
                47 views
                0 likes
                Last Post Max238
                by Max238
                 
                Started by giulyko00, Yesterday, 12:03 PM
                3 responses
                13 views
                0 likes
                Last Post NinjaTrader_BrandonH  
                Working...
                X