Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Set Contract Amount - TP not reflecting the amount

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

    Set Contract Amount - TP not reflecting the amount

    As you can see in the picture Contract amount I set my contract amount to 2 contracts. Now that I have entered a trade, I see that I have a position with 2 contracts. Since I set a protective SL and TP, the next image shows the SL at 2 contracts and the TP at 1. Set 2 - NT8.jpg.
    When I switch the contracts to 1, the SL is now at 1 and the TP is 1. Set 1 - NT8.jpg

    Let me show you the code where the Protective settings are

    I feel like this code it making the TP stay at 1 and not 2 contracts.
    Code:
    // StopLoss & ProfitTarget
            protected override void OnExecutionUpdate( Cbi.Execution e, string executionId, double price, int quantity,
                                                       Cbi.MarketPosition marketPosition, string orderId, DateTime time )
            {            
                if( UseProtectiveStops )
                {
                    if( e.IsEntryStrategy )
                    {
                        if( e.Order.OrderAction == OrderAction.Buy )
                        {
                            // Set stop loss
                            double stopOrderPrice = e.Order.AverageFillPrice - StopLoss * TickSize;
                            ExitLongStopMarket( 0, true, 3, stopOrderPrice, "Stop loss", e.Order.FromEntrySignal );
    
                            // Set profit target 1
                            double profitTarget = e.Order.AverageFillPrice + ProfitTarget * TickSize;;
                            ExitLongLimit( 0, true, 1, profitTarget, "Profit target", e.Order.FromEntrySignal );                                            
                        }
                        if( e.Order.OrderAction == OrderAction.SellShort )
                        {
                            // Set stop loss
                            double stopOrderPrice = e.Order.AverageFillPrice + StopLoss * TickSize;
                            ExitShortStopMarket( 0, true, 3, stopOrderPrice, "Stop loss", e.Order.FromEntrySignal );
    
                            // Set profit target 1
                            double profitTarget = e.Order.AverageFillPrice - ProfitTarget * TickSize;;
                            ExitShortLimit( 0, true, 1, profitTarget, "Profit target", e.Order.FromEntrySignal );
                        }
                    }
                }​
    Attached Files

    #2
    Hello zayone,

    Thanks for your post.

    In the code you shared you are calling ExitLongStopMarket() and ExitShortStopMarket() with a specified quantity of 3. You are also calling ExitLongLimit() and ExitShortLimit() with a specified quantity of 1.

    If you want to submit a stop loss and profit target for the quantity of orders that were filled, you should use execution.Order.Filled for the quantity when calling your Exit methods in OnExecutionUpdate(). The reference sample called SampleOnOrderUpdate linked below demonstrates this.

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

    See the help guide documentation below for more information.

    OnExecutionUpdate(): https://ninjatrader.com/support/help...tionupdate.htm
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment


      #3
      Thank you, this updated code seemed to work

      Code:
      if( UseProtectiveStops )
                  {
                      if( e.IsEntryStrategy )
                      {
                          int filledQuantity = e.Order.Filled;
      
                          if( e.Order.OrderAction == OrderAction.Buy )
                          {
                              // Set stop loss
                              double stopOrderPrice = e.Order.AverageFillPrice - StopLoss * TickSize;
                              ExitLongStopMarket( 0, true, filledQuantity, stopOrderPrice, "Stop loss", e.Order.FromEntrySignal );
      
                              // Set profit target 1
                              double profitTarget = e.Order.AverageFillPrice + ProfitTarget * TickSize;;
                              ExitLongLimit( 0, true, filledQuantity, profitTarget, "Profit target", e.Order.FromEntrySignal );                                            
                          }
                          if( e.Order.OrderAction == OrderAction.SellShort )
                          {
                              // Set stop loss
                              double stopOrderPrice = e.Order.AverageFillPrice + StopLoss * TickSize;
                              ExitShortStopMarket( 0, true, filledQuantity, stopOrderPrice, "Stop loss", e.Order.FromEntrySignal );
      
                              // Set profit target 1
                              double profitTarget = e.Order.AverageFillPrice - ProfitTarget * TickSize;;
                              ExitShortLimit( 0, true, filledQuantity, profitTarget, "Profit target", e.Order.FromEntrySignal );
                          }
                      }
                  }​

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Mindset, 04-21-2026, 06:46 AM
      0 responses
      87 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by M4ndoo, 04-20-2026, 05:21 PM
      0 responses
      132 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by M4ndoo, 04-19-2026, 05:54 PM
      0 responses
      68 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by cmoran13, 04-16-2026, 01:02 PM
      0 responses
      118 views
      0 likes
      Last Post cmoran13  
      Started by PaulMohn, 04-10-2026, 11:11 AM
      0 responses
      67 views
      0 likes
      Last Post PaulMohn  
      Working...
      X