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 mattbsea, Today, 05:44 PM
                0 responses
                2 views
                0 likes
                Last Post mattbsea  
                Started by RideMe, 04-07-2024, 04:54 PM
                6 responses
                31 views
                0 likes
                Last Post RideMe
                by RideMe
                 
                Started by tkaboris, Today, 05:13 PM
                0 responses
                2 views
                0 likes
                Last Post tkaboris  
                Started by GussJ, 03-04-2020, 03:11 PM
                16 responses
                3,281 views
                0 likes
                Last Post Leafcutter  
                Started by WHICKED, Today, 12:45 PM
                2 responses
                19 views
                0 likes
                Last Post WHICKED
                by WHICKED
                 
                Working...
                X