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 CarlTrading, 03-31-2026, 09:41 PM
      1 response
      81 views
      1 like
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      42 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      64 views
      2 likes
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      66 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      54 views
      0 likes
      Last Post CarlTrading  
      Working...
      X