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 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
      41 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