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

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 fx.practic, 10-15-2013, 12:53 AM
              5 responses
              5,404 views
              0 likes
              Last Post Bidder
              by Bidder
               
              Started by Shai Samuel, 07-02-2022, 02:46 PM
              4 responses
              95 views
              0 likes
              Last Post Bidder
              by Bidder
               
              Started by DJ888, Yesterday, 10:57 PM
              0 responses
              7 views
              0 likes
              Last Post DJ888
              by DJ888
               
              Started by MacDad, 02-25-2024, 11:48 PM
              7 responses
              159 views
              0 likes
              Last Post loganjarosz123  
              Started by Belfortbucks, Yesterday, 09:29 PM
              0 responses
              8 views
              0 likes
              Last Post Belfortbucks  
              Working...
              X