Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Stop Sell and Stop Buy orders at the same time

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

    Stop Sell and Stop Buy orders at the same time

    Hi,

    I am trying to test a simple strategy in Market Replay, that opens 1 stop buy order and 1 stop sell order at the same time (it is not 2 orders in the same direction), but the strategy opens only one of them, never opens both orders as expected.

    The code is the following:

    #region Using declarations
    using System;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Data;
    using NinjaTrader.Indicator;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Strategy;
    #endregion

    // This namespace holds all strategies and is required. Do not change it.
    namespace NinjaTrader.Strategy
    {
    /// <summary>
    /// Enter the description of your strategy here
    /// </summary>
    [Description("Enter the description of your strategy here")]
    public class ordensimple2 : Strategy
    {
    #region Variables
    // Wizard generated variables
    private int sL = 20; // Default setting for SL
    private int tP = 20; // Default setting for TP
    // User defined variables (add any user defined variables below)
    #endregion

    /// <summary>
    /// This method is used to configure the strategy and is called once before any strategy method is called.
    /// </summary>
    protected override void Initialize()
    {
    SetProfitTarget("", CalculationMode.Ticks, TP);
    SetStopLoss("", CalculationMode.Ticks, SL, false);

    CalculateOnBarClose = false;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    // Condition set 1
    if (ToTime(Time[1]) == ToTime(3, 30, 0))
    {
    EnterShortStop(DefaultQuantity, Low[1] + -5 * TickSize, "StopSell");
    EnterLongStop(DefaultQuantity, High[1] + 10 * TickSize, "StopBuy");
    }

    }

    #region Properties
    [Description("")]
    [GridCategory("Parameters")]
    public int SL
    {
    get { return sL; }
    set { sL = Math.Max(1, value); }
    }

    [Description("")]
    [GridCategory("Parameters")]
    public int TP
    {
    get { return tP; }
    set { tP = Math.Max(1, value); }
    }
    #endregion
    }
    }


    Please let me know where is wrong handling orders in this strategy.

    Thanks in advance,
    Federico

    #2
    Originally posted by federicoo View Post
    Hi,

    I am trying to test a simple strategy in Market Replay, that opens 1 stop buy order and 1 stop sell order at the same time (it is not 2 orders in the same direction), but the strategy opens only one of them, never opens both orders as expected.

    The code is the following:

    #region Using declarations
    using System;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Data;
    using NinjaTrader.Indicator;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Strategy;
    #endregion

    // This namespace holds all strategies and is required. Do not change it.
    namespace NinjaTrader.Strategy
    {
    /// <summary>
    /// Enter the description of your strategy here
    /// </summary>
    [Description("Enter the description of your strategy here")]
    public class ordensimple2 : Strategy
    {
    #region Variables
    // Wizard generated variables
    private int sL = 20; // Default setting for SL
    private int tP = 20; // Default setting for TP
    // User defined variables (add any user defined variables below)
    #endregion

    /// <summary>
    /// This method is used to configure the strategy and is called once before any strategy method is called.
    /// </summary>
    protected override void Initialize()
    {
    SetProfitTarget("", CalculationMode.Ticks, TP);
    SetStopLoss("", CalculationMode.Ticks, SL, false);

    CalculateOnBarClose = false;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    // Condition set 1
    if (ToTime(Time[1]) == ToTime(3, 30, 0))
    {
    EnterShortStop(DefaultQuantity, Low[1] + -5 * TickSize, "StopSell");
    EnterLongStop(DefaultQuantity, High[1] + 10 * TickSize, "StopBuy");
    }

    }

    #region Properties
    [Description("")]
    [GridCategory("Parameters")]
    public int SL
    {
    get { return sL; }
    set { sL = Math.Max(1, value); }
    }

    [Description("")]
    [GridCategory("Parameters")]
    public int TP
    {
    get { return tP; }
    set { tP = Math.Max(1, value); }
    }
    #endregion
    }
    }


    Please let me know where is wrong handling orders in this strategy.

    Thanks in advance,
    Federico


    Same question: same answer.

    Comment


      #3
      federicoo, welcome to our forums - koganam's correct here, in the managed approach this would be expected, as you run a high risk in those situations to end up with an undesired position it would not be allowed by our internal order handling rules.

      In contrast our unmanaged mode would not be imposing any such rules but allow ultimate flexibility.



      Generally a valuable debug tool for order submission in strategies would be the TraceOrders - http://www.ninjatrader.com/support/f...ead.php?t=3627

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      648 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      369 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      108 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      572 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      573 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X