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 NullPointStrategies, Today, 05:17 AM
      0 responses
      41 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
      64 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      41 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