Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to move a Profit Target

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

    How to move a Profit Target

    When using an ATM for Stop Loss and Profit Target with you Strategy position you can hold the Profit Target order on the chart and move it to a New Value and it will remain at the new value as the bars progress

    When creating an exit plan within the the strategy if you move the Profit Target on the chart, when the next bar closes the Profit Target moves itself back to the original value

    IS THERE AWAY to be able to adjust the profit target and it remain at the new level?

    I am using the below method to send my stoploss and profit target as soon as my new position is created

    // stop loss and profit target submit
    if ((High[0] != Close[0])
    && (Position.MarketPosition == MarketPosition.Long)
    && (UsePivotsForExit == true))
    {
    ExitLongStopMarket(Convert.ToInt32(Position.Quanti ty), (Position.AveragePrice + (-StopLoss * TickSize)), @"ProgStopLoss", "");
    ExitLongLimit(Convert.ToInt32(DefaultQuantity), (Position.AveragePrice + (ProfitTarget * TickSize)) , @"ProgProfitT", "");
    }

    is there anything i can add to achieve the desired result

    Thanks

    #2
    Hello DTSSTS,

    Thanks for your post.

    It doesn't look like you are using the IsLiveUntilCancelled overloads, so the strategy logic will have to keep calling your order methods to keep the order alive. So whenever OnBarUpdate processes this logic, the method is called again, and then the order is moved back to Position.AveragePrice + (-StopLoss * TickSize).

    If you use the IsLiveUntilCancelled overloads, then you only have to call the method once, the order will stay active, and you can avoid calling the order method again to keep the order alive. This will prevent the order from moving because you would not be calling the order method again which sets it back to that price level. You could use a bool to control calling the order methods once.

    IsLiveUntilCancelled - https://ninjatrader.com/support/help...ancelledOrders

    The ExitLongLimit and ExitLongStopMarket syntax for these overloads are as follows:

    ExitLongLimit(int barsInProgressIndex, bool isLiveUntilCancelled, int quantity, double limitPrice, string signalName, string fromEntrySignal)

    ExitLongStopMarket(int barsInProgressIndex, bool isLiveUntilCancelled, int quantity, double stopPrice, string signalName, string fromEntrySignal)

    We look forward to being of further assistance.

    Comment


      #3
      this is likely over my programming abilities but lets see

      ExitLongStopMarket(Convert.ToInt32(Position.Quanti ty), (Position.AveragePrice + (-StopLoss * TickSize)), @"ProgStopLoss", "");
      ExitLongLimit(Convert.ToInt32(DefaultQuantity), (Position.AveragePrice + (ProfitTarget * TickSize)) , @"ProgProfitT", "");

      the above are my current syntax

      below are your examples

      ExitLongLimit(int barsInProgressIndex, bool isLiveUntilCancelled, int quantity, double limitPrice, string signalName, string fromEntrySignal)

      ExitLongStopMarket(int barsInProgressIndex, bool isLiveUntilCancelled, int quantity, double stopPrice, string signalName, string fromEntrySignal)

      (NOTE THE link really does not include other items that probably need to be included in other areas such as variables and onbarupdate script areas
      SO EVEN if i get the exit lines correct they likely will not work?

      ***************************** ARE THE BELOW CORRECT Syntax ??

      ExitLongStopMarket(int barsInProgressIndex, bool isLiveUntilCancelled, Convert.ToInt32(Position.Quantity), (Position.AveragePrice + (-StopLoss * TickSize)), @"ProgStopLoss", "");
      ExitLongLimit(int barsInProgressIndex, bool isLiveUntilCancelled, Convert.ToInt32(DefaultQuantity), (Position.AveragePrice + (ProfitTarget * TickSize)) , @"ProgProfitT", "");

      Comment


        #4
        THIS IS WHAT I have now


        ExitLongStopMarket(0, true, Convert.ToInt32(Position.Quantity), (Position.AveragePrice + (-StopLoss * TickSize)), @"ProgStopLoss", "");
        ExitLongLimit(0, true, Convert.ToInt32(DefaultQuantity), (Position.AveragePrice + (ProfitTarget * TickSize)) , @"ProgProfitT", "");

        }

        but when i move the ProgProfitT (ExitLongLimit) order once the next bar close it still moves back

        i have not done anything but modify the Order
        so i believe below is what i am still missing in the code

        you wrote: " You could use a bool to control calling the order methods once."

        thanks

        Comment


          #5
          Hello DTSSTS,

          Yes, if the order is moving back it is likely because the strategy logic is calling that method to move it back to that price level. You would need to add code to ensure that the logic to submit the target/stop only gets called once. This could be done using a bool. A publicly available resource on bools is linked below.



          You may also observe this is happening by placing a print next to the order methods. If you see a print in the output window when the stop/target move back to an original evel, this will confirm that the logic is allowing the order methods to be reached again and move the order back.

          We look forward to assisting.

          Comment


            #6
            so just this code

            private bool isLiveUntilCancelled;

            or More required

            Comment


              #7
              Hello DTSSTS,

              No, the bool will need to be used to control your logic. Simply creating a bool will not have any affect on your logic.

              Please consider the following. You would be taking a similar approach to ensure the target and stop order methods are called once. You would need to set this bool back to true when the strategy is back to a flat position.

              Code:
              private bool doOnce = true;
              protected override void OnBarUpdate()
              {
                  if(doOnce)
                  {
                      // Do Something...
                      doOnce = false;
                  }
              }
              Making Position Comparisons - https://ninjatrader.com/support/help...ionComparisons

              Please let me know if you have any questions.

              Comment


                #8
                still not quite clear on where to put what, i under stand the True and false part

                private bool doOnce = true; so i start with doOnce = true; and when the Profit target order is sent then do once will be a condition,

                then if position is flat doOnce equals true again

                I TRIED THE BELOW


                if (Position.MarketPosition == MarketPosition.Flat)
                {
                // when Flat doOnce resets to true
                doOnce = true;
                }

                AND INCLUDED that doOnce had to be true when the profit target was sent but when i manually moved the profit target when the next bar close it recalulated back to the orginal value

                i also deleted the profit target order and on the next bar open it resent the order

                thanks
                Last edited by DTSSTS; 02-04-2020, 06:56 PM.

                Comment


                  #9
                  Hello DTSSTS,

                  I have created a demonstration, please see below.



                  Please let me know if you see different behavior testing the same.

                  Comment


                    #10
                    thanks for the video



                    I have enter all the code but i place my doOnce true and false in the areas of my actually order conditions in the code

                    BUT WHEN I MOVE THE PROFIT TARGET ORDER it just moves back to original value onbarclose

                    i have the area for State.Historical as well

                    if ((State == State.Historical)
                    && (AttachATM == true))
                    return;

                    // do once orders


                    if (Position.MarketPosition == MarketPosition.Flat)
                    {
                    // when Flat doOnce resets to true
                    doOnce = true;
                    }
                    else if (doOnce)
                    {
                    doOnce = false;
                    }
                    // end area

                    // entry conditions above THEN ORDERS BELOW

                    {
                    if (AttachATM == true)
                    CreateUniqueATMStrategy((int)Signals.BollingerShor t);
                    else if ((doOnce)
                    && (Position.MarketPosition != MarketPosition.Long))
                    doOnce = true;
                    EnterShort(Convert.ToInt32(DefaultQuantity), @"TrendLineBreakShort");
                    }

                    EXIT ORDERS THERE // stop loss

                    if ((Position.MarketPosition == MarketPosition.Short)
                    && (UseRSICrossForExit == true))
                    {
                    doOnce = false;
                    ExitShortStopMarket(0, true. Convert.ToInt32(Position.Quantity), (Position.AveragePrice + (StopLoss * TickSize)), @"ProgStopLoss", "");
                    ExitShortLimit(0,true, Convert.ToInt32(DefaultQuantity), (Position.AveragePrice + (-ProfitTarget * TickSize)) , @"ProgProfitT", "");
                    }

                    Comment


                      #11
                      also having an issue with the last part in previous post sending on entry of the short position
                      my orders are waiting until bar close to send so if the entry bar its my stop i do not have a stop

                      Comment


                        #12
                        Hello DTSSTS,

                        If you want to submit orders upon the fill of an entry order, please use OnExecutionUpdate. Our SampleOnOrderUpdate strategy demonstrates this.

                        SampleOnOrderUpdate - https://ninjatrader.com/support/help...and_onexec.htm

                        I suggest testing exactly as I have so you know how to use a bool to restrict logic from being reached more than once. You mention the following: "BUT WHEN I MOVE THE PROFIT TARGET ORDER it just moves back to original value onbarclose" This means that your logic is calling the exit method again, and the doOnce bool is not being utilized. Debugging prints will show that logic controlling the order submission is still becoming true and allowing the order method to be reached.

                        Debugging tips - https://ninjatrader.com/support/help...script_cod.htm

                        As you see with my video, the print is seen just once, because the doOnce bool is true only once when the order is submitted, and then set to false in the condition which submits the target and stop. My code only submits the stop/target if doOnce is true. Your code is not checking if doOnce is true when you are submitting your target and stop orders: the bool is not controlling your logic.

                        I look forward to assisting.

                        Comment


                          #13
                          if ((Position.MarketPosition == MarketPosition.Short)
                          && (doOnce = true)
                          && (UseRSICrossForExit == true))
                          {
                          doOnce = false;
                          ExitShortStopMarket(0, true. Convert.ToInt32(Position.Quantity), (Position.AveragePrice + (StopLoss * TickSize)), @"ProgStopLoss", "");
                          ExitShortLimit(0,true, Convert.ToInt32(DefaultQuantity), (Position.AveragePrice + (-ProfitTarget * TickSize)) , @"ProgProfitT", "");
                          }

                          Comment


                            #14
                            Hello DTSSTS,

                            if ((Position.MarketPosition == MarketPosition.Short)
                            && (doOnce = true)
                            && (UseRSICrossForExit == true))
                            {
                            This snippet is using the assignment operator '=' I believe you mean to use the equality operator '=='

                            I look forward to assisting.

                            Comment


                              #15
                              yes i did

                              Will that fix my issue to be able to move the Profit Target?

                              an on execution update
                              protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time)
                              {


                              }

                              I SEE THE above but will need more example than that for it to work

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by NullPointStrategies, Today, 05:17 AM
                              0 responses
                              52 views
                              0 likes
                              Last Post NullPointStrategies  
                              Started by argusthome, 03-08-2026, 10:06 AM
                              0 responses
                              130 views
                              0 likes
                              Last Post argusthome  
                              Started by NabilKhattabi, 03-06-2026, 11:18 AM
                              0 responses
                              70 views
                              0 likes
                              Last Post NabilKhattabi  
                              Started by Deep42, 03-06-2026, 12:28 AM
                              0 responses
                              44 views
                              0 likes
                              Last Post Deep42
                              by Deep42
                               
                              Started by TheRealMorford, 03-05-2026, 06:15 PM
                              0 responses
                              49 views
                              0 likes
                              Last Post TheRealMorford  
                              Working...
                              X