Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SetProfitTarget Does Not Execute

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

    SetProfitTarget Does Not Execute

    I am in the midst of changing up the code of my automated strategy and I can't get the SetProfitTarget to work. In the earlier working version, I had the SetStopLoss included under the condition State == State.DataLoaded but now I'm adding SetStopLoss and SetProfitTarget under trade condition match... right after EnterLong or EnterShort. What am I doing wrong? When conditions match the SetStopLoss works correctly but the profit target does not get set. SL0 and TargetTick1 are provided by the user during strategy activation.
    Please advise.
    Thanks.

    EnterLong(Qty, "Long");
    SetProfitTarget("Long", CalculationMode.Ticks, TargetTick1);
    SetStopLoss("Long", CalculationMode.Ticks, SL0, false);​

    #2
    Any suggestions?

    Comment


      #3
      Hello givemefood,

      I have moved this thread to the Strategy Development section of the forums as this is a question about NinjaScript programming.

      Note, always call Set methods before calling the entry order method, not after.

      That said, what is the value of TargetTick1?

      How do you know the limit order for the target is not being submitted?
      Are you reviewing the output from TraceOrders and seeing the stop loss trace message but not the profit target?
      Are you reviewing output from printing the order object in OnOrderUpdate()?

      Please include the debugging output saved to a text file so that I may assist with analyzing the behavior.

      Chelsea B.NinjaTrader Customer Service

      Comment


        #4
        I re-ordered per your suggestion and moved the set methods to earlier and that worked!
        Thank you

        Comment


          #5
          ChelseaB, I'm wondering if I'm having a similar issue with the order of operations but let me explain a few additional details that may also contribute to my issue.
          • My strategy works during Playback mode and partially works during live sessions.
          • In Playback, my entry order gets executed when I click a custom button and the set stop and take profit orders post on the chart.
          • In Live mode, my entry order get executed but the stop and take profit orders don't get applied.
          • My entries are located in OnBarUpdate. I send the entry name to a method/function in order to set the stop and take profit. The method is located in the OnStateChange section.
          • Do I have a sequence issue? I thought I would need to enter the trade first then set the stop and tp based on my entry price.
          • Do I have some other structural issue using a method outside OnBarUpdate?


          if (tradecount == 0)
          {
          EnterLong(MaxContracts, "MyEntryLongInstant");
          StopandTargetInstant("MyEntryLongInstant");

          }

          if (tradecount == 1)
          {
          EnterLong(MaxContracts, "MyEntryLongInstant2");
          StopandTargetInstant("MyEntryLongInstant2");

          }​

          void StopandTargetInstant(string tradename)
          {
          if (Position.MarketPosition == MarketPosition.Long)

          {
          ExitLongStopMarket(0, true, Position.Quantity, Position.AveragePrice - Stop_ticks * TickSize, tradename, tradename);
          ExitLongLimit(0, true, Position.Quantity, Position.AveragePrice + Target_ticks * TickSize, tradename, tradename);

          }

          if (Position.MarketPosition == MarketPosition.Short)
          {
          ExitShortStopMarket(0, true, Position.Quantity, Close[0] + Stop_ticks * TickSize, tradename, tradename);
          ExitShortLimit(0, true, Position.Quantity, Close[0] - Target_ticks * TickSize, tradename, tradename);

          }
          return;
          }​
          Last edited by tak145; 10-15-2023, 05:58 AM.

          Comment


            #6
            Hello tak145,

            With Exit methods, submit these from OnExecutionUpdate() when the entry order fills.


            The ProfitChaseStopTrailExitOrdersExample example provides an example.


            Trying to submit an exit order when the order has not had time to fill and the position has not yet changed will result in the order being ignored.
            Chelsea B.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

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