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

Can you Cancel a Profit Target

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

    Can you Cancel a Profit Target

    from the State.DataLoaded I have this ProfitTarget

    SetProfitTarget(CalculationMode.Ticks, ProfitTicks);

    Is it possible to create a condition set in OnBarUpdate region to cancel this order when a condition set is met

    Example: Position is taken, a StopLoss order and the ProfitTarget order are sent

    IF at that time or anytime during this position being Open if the condition set is met to cancel then a Cancel statement of some kind will Cancel the Profit Target order

    (I already have other Exit methods in place that will Close the Position (sometimes before the profit target is met) they will be the planned exit method after the ProfitTarget order is cancelled.

    Thanks

    #2
    If you have used SetProfitTarget, you can't then "unset" the profit target - but you can move it further away e.g. 1000 ticks out so it doesn't get hit. If you need to be able to "cancel" it I would suggest that you instead don't use SetProfitTarget and SetStopLoss, and instead use ExitLongLimit and ExitLongStop etc.
    Bruce DeVault
    QuantKey Trading Vendor Services
    NinjaTrader Ecosystem Vendor - QuantKey

    Comment


      #3
      Thanks for the reply - I did consider ExitLongLimit and ExitLongStop but I did not want to get involved in that much recoding if there was a simpler approach

      Moving it further away is excellent approach and accomplishes the same thing. I would assume you can move the StopLoss closer as well with a similar method.

      How do I move it further away

      Thanks

      Comment


        #4
        Hi, You can move the stop or target further away by calling SetStopLoss/SetProfitTarget again with updated parameters, using the same "FromEntrySignal" string.
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          The help guide is pretty vague about updating the parameters and not sure if you are still thinking I am trying to update

          SetProfitTarget(CalculationMode.Ticks, ProfitTicks);

          that I used in State.DataLoaded

          Thanks

          Comment


            #6
            Hi, You will need to call this dynamically in OnBarUpdate to change the stop at a later time. You can call SetProfitTarget() initially in State.DataLoaded, but if you want to change its value later in time you will need to call SetProfitTarget() in OnBarUpdate.
            Chris L.NinjaTrader Customer Service

            Comment


              #7
              so original data loaded

              SetProfitTarget(CalculationMode.Ticks, ProfitTicks);

              NOW something like this

              if ((Position.MarketPosition == MarketPosition.Long)

              && (BarsSinceEntryExecution(0, "", 0) > 3)

              && (xyz condition)

              && (Close[0] > Open[0]))
              {
              SetProfitTarget(CalculationMode.Ticks, 600);/// this will update the existing order
              }

              Comment


                #8
                That is correct.
                Chris L.NinjaTrader Customer Service

                Comment


                  #9
                  Thanks Bruce and ChrisL

                  Comment


                    #10
                    Additional Question: After implementing the Code in Post Visitor Messages and conditions are true and Profit Target is Updated to 600 ticks

                    Then the Condtion set changes and is NO LONGER True,

                    I assume the changes have been made and if not modified again with a different condition set the Change to 600 ticks will remain in Effect.

                    Is this correct?

                    Thanks

                    Comment


                      #11
                      If SetProfitTarget does not get called, it will not change again, so if your condition:

                      if ((Position.MarketPosition == MarketPosition.Long)

                      && (BarsSinceEntryExecution(0, "", 0) > 3)

                      && (xyz condition)

                      && (Close[0] > Open[0]))

                      does not become true, the stop will not be changed. If you want to set it at 600 ticks, then never set it again, use an extra boolean variable in the condition to use as a flag. e.g.

                      //class level
                      private bool MyFlag = false;

                      //OnBarUpdate

                      if ((Position.MarketPosition == MarketPosition.Long)

                      && (BarsSinceEntryExecution(0, "", 0) > 3)

                      && (xyz condition)

                      && (Close[0] > Open[0])

                      && !MyFlag)
                      {
                      SetProfitTarget(CalculationMode.Ticks, 600);
                      MyFlag = true;
                      }​​
                      Chris L.NinjaTrader Customer Service

                      Comment


                        #12
                        ok I added the flag. Not sure what is happening, I have a bool as well stating to use this modification condition set or NOT

                        In back testing when NOT using the modification my Largest trade is equal to my Profit Target default. When I select to use the modification set then I have many trades at my profit target as expected and I have many greater than my default profit target SO this seems to be working as expected.

                        But in actual live trading it does NOT. The profit Target is sent at the 600 ticks immediately when a new position is taken.
                        does not wait on && (BarsSinceEntryExecution(0, "", 0) > 3) and does not sent the default Profit target order immediately as it should

                        thanks
                        BELOW IS MY ACTUAL CODE - I DO HAVE THE /// class private bool as
                        private bool MyProfitTargetFlag = false;



                        // Set 58
                        if ((Position.MarketPosition == MarketPosition.Long)
                        && (LongTrades == true)

                        && (UseProfitTargetCancelOverride == true)
                        && (BarsSinceEntryExecution(0, "", 0) > 3)

                        /// Conditions for Override

                        && (xyz condition)


                        && (Close[0] > Open[0])

                        && !MyProfitTargetFlag)
                        {
                        SetProfitTarget(CalculationMode.Ticks, 600);/// this will update the existing order
                        MyProfitTargetFlag = true;
                        }


                        // Set 60
                        if ((Position.MarketPosition == MarketPosition.Short)
                        && (ShortTrades == true)

                        && (UseProfitTargetCancelOverride == true)
                        && (BarsSinceEntryExecution(0, "", 0) > 3)

                        /// Conditions for Override

                        && (xyz condition)


                        && (Close[0] < Open[0])

                        && !MyProfitTargetFlag)
                        {
                        SetProfitTarget(CalculationMode.Ticks, 600);/// this will update the existing order
                        MyProfitTargetFlag = true;
                        }​
                        Last edited by DTSSTS; 05-11-2023, 12:10 PM.

                        Comment


                          #13
                          HOLD not sure that is Correct above, ON my Strat from control center seems correct and on the strat applied directly to chart it is the one with the 600 profit target
                          LET ME UPDATE THIS IN A FEW

                          Comment


                            #14
                            One thing to think about is if you are plotting the orders e.g. Chart Trader, and you put it 600 ticks away, it may distort your scale.
                            Bruce DeVault
                            QuantKey Trading Vendor Services
                            NinjaTrader Ecosystem Vendor - QuantKey

                            Comment


                              #15
                              Seems to ignore whether I am Long Or short when looking at the condtion sets

                              CAN I have more that ONE SetProfitTarget(CalculationMode.Ticks, 600);

                              for example

                              SetProfitTargetLong(CalculationMode.Ticks, 600);
                              SetProfitTargetShort(CalculationMode.Ticks, 600);

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by StockTrader88, 03-06-2021, 08:58 AM
                              44 responses
                              3,966 views
                              3 likes
                              Last Post jhudas88  
                              Started by rbeckmann05, Today, 06:48 PM
                              0 responses
                              4 views
                              0 likes
                              Last Post rbeckmann05  
                              Started by rhyminkevin, Today, 04:58 PM
                              4 responses
                              55 views
                              0 likes
                              Last Post dp8282
                              by dp8282
                               
                              Started by iceman2018, Today, 05:07 PM
                              0 responses
                              6 views
                              0 likes
                              Last Post iceman2018  
                              Started by lightsun47, Today, 03:51 PM
                              0 responses
                              8 views
                              0 likes
                              Last Post lightsun47  
                              Working...
                              X