Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SetProfitTarget only if I am in the position.

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

    SetProfitTarget only if I am in the position.

    I would like to set a profti target if the RSI(3,1)[0] >= 75. I tried:

    if (BarsSinceEntry() >= 1 && RSI(3, 1)[0] >= 75)

    {
    double gewinnlong = Close [0];
    SetProfitTarget ("", CalculationMode.Price, gewinnlong);
    }

    My problem is, it sets my profit target, somewhere else.

    #2
    Hi Ironman9973,

    SetProfitTarget() is more of a toggle than an order command. Whenever you have set a profit target, then it automatically submits a limit order upon entry execution. The value of the order will be the last value that was set, but they can't be unset.

    If you wanted to manually control when the order is submitted, you can use ExitLongLimit() or ExitShortLimit()


    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      I cannot use ExitLongLimit because I am using a Stoploss with SetStopLoss. So I have to finde a way set the order only if I am in the position.

      Comment


        #4
        I see. In that case you're right that you would be running into internal order handling rules. For this level of control you'll have to move away from the 'set' method completely, and submit stop orders with ExitLongStop() and ExitShortStop()


        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          I like the SetStopLoss methode much more, because if my system goes down, I have my StopLoss set.

          Is there a possibility to set my profit target only if I am in the position?

          Comment


            #6
            Originally posted by Ironman9973 View Post
            I like the SetStopLoss methode much more, because if my system goes down, I have my StopLoss set.

            Is there a possibility to set my profit target only if I am in the position?

            If not in position, you could set the profittaget to a value which is far above the market so it can never be filled.

            Code:
             
            if (Position.MarketPosition == MarketPosition.Long)
            SetProfitTarget("", CalculationMode.Price, gewinnlong)  // set profittarget for long position
            else
            SetProfitTarget("", CalculationMode.Price, 9999)            //reset profittarget

            Comment


              #7
              Thanks for sharing a possible work around, marcow.

              Ironman, the exit stop orders can work the same way as SetStopLoss(). The location of orders doesn't change with either approach. If you wanted to get the same timing on submission, you can submit ExitLongStop() in OnExecution(), following ideas in this reference sample.
              The OnOrderUpdate() and OnExecution() methods are reserved for experienced programmers. Instead of using Set() methods to submit stop-loss and profit target orders, you can submit and update them manually through the use of IOrder and IExecution objects in the OnOrderUpdate() and OnExecution() methods. The OnOrderUpdate()
              Ryan M.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              576 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              334 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              101 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              553 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              551 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X