Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

time based simple strategy

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

    time based simple strategy

    I am running this ultra basic strategy (enter a limit order at a specific time):
    #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>
    /// orden limit
    /// </summary>
    [Description("orden limit")]
    public class ordenlimitV2 : Strategy
    {
    #region Variables
    // Wizard generated variables
    private int time = 93000;
    private int takeP = 10; // Default setting for TakeP
    private int stopL = 10; // Default setting for StopL
    private int desplazamiento = 10; // Default setting for Desplazamiento
    // 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("ShortLimitOrder", CalculationMode.Ticks, TakeP);
    SetStopLoss("ShortLimitOrder", CalculationMode.Ticks, StopL, false);

    CalculateOnBarClose = true;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    // Condition set 1
    if (ToTime(Time[0]) >= time)
    {
    EnterShortLimit(1, GetCurrentAsk() + Desplazamiento * TickSize, "ShortLimitOrder");
    }
    }

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

    [Description("")]
    [GridCategory("Parameters")]
    public int StopL
    {
    get { return stopL; }
    set { stopL = Math.Max(1, value); }
    }

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

    This strategy does not work backtesting in strategy analyzer with 1 range bars type. It seems as it enters the limit order but is canceled immediately, not letting the price touch the limit price to fill this order. The situation is different when I try time based bars type, but I'm interested in range bars.

    Thanks

    #2
    Hello federicoo,
    Thanks for your post.
    • Do you receive an error on screen? Are there errors on the Log tab of the Control Center? If so, what do these errors report?
    • Who are you connected to? This is displayed in green on lower left corner of the Control Center window.
    • What is the output you get when you add TraceOrders to your strategies code?

    Help Guide - TraceOrders
    Help Guide - Understanding TraceOrders Output
    Josh G.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_JoshG View Post
      Hello federicoo,
      Thanks for your post.
      • Do you receive an error on screen? Are there errors on the Log tab of the Control Center? If so, what do these errors report?
      • Who are you connected to? This is displayed in green on lower left corner of the Control Center window.
      • What is the output you get when you add TraceOrders to your strategies code?

      Help Guide - TraceOrders
      Help Guide - Understanding TraceOrders Output
      Hello, I did some little changes in code, the new one is this:

      #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>
      /// orden limit
      /// </summary>
      [Description("orden limit")]
      public class ordenlimitV2 : Strategy
      {
      #region Variables
      // Wizard generated variables
      private int timeE = 93001;
      private int takeP = 10; // Default setting for TakeP
      private int stopL = 10; // Default setting for StopL
      private int desplazamiento = 10; // Default setting for Desplazamiento
      // 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("OrdenVenta", CalculationMode.Ticks, TakeP);
      SetStopLoss("OrdenVenta", CalculationMode.Ticks, StopL, false);
      CalculateOnBarClose = true;
      TraceOrders = true;
      }

      /// <summary>
      /// Called on each bar update event (incoming tick)
      /// </summary>
      protected override void OnBarUpdate()
      {
      // Condition set 1
      if (ToTime(Time[0]) == TimeE)
      {
      EnterShortLimit(1, GetCurrentAsk() + Desplazamiento * TickSize, "OrdenVenta");
      }
      }

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

      [Description("")]
      [GridCategory("Parameters")]
      public int StopL
      {
      get { return stopL; }
      set { stopL = Math.Max(1, value); }
      }

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



      And these are the answers:[*]Do you receive an error on screen? Are there errors on the Log tab of the Control Center? If so, what do these errors report? NO ERRORS RECEIVED
      [*]Who are you connected to? This is displayed in green on lower left corner of the Control Center window. I TRIED IB AND AMP
      [*]What is the output you get when you add TraceOrders to your strategies code?[/LIST]

      5/9/2018 09:30:01 Entered internal PlaceOrder() method at 5/9/2018 09:30:01: BarsInProgress=0 Action=SellShort OrderType=Limit Quantity=1 LimitPrice=71.20 StopPrice=0 SignalName='OrdenVenta' FromEntrySignal=''
      5/9/2018 09:30:01 Entered internal PlaceOrder() method at 5/9/2018 09:30:01: BarsInProgress=0 Action=SellShort OrderType=Limit Quantity=1 LimitPrice=71.20 StopPrice=0 SignalName='OrdenVenta' FromEntrySignal=''
      5/9/2018 09:30:01 Ignore order amendment: Action=SellShort OrderType=Limit Quantity=1 LimitPrice=71.20 StopPrice=0 SignalName=OrdenVenta' FromEntrySignal='' Reason='Order already has this stop price/limit price/quantity'
      5/9/2018 09:30:01 Entered internal PlaceOrder() method at 5/9/2018 09:30:01: BarsInProgress=0 Action=SellShort OrderType=Limit Quantity=1 LimitPrice=71.19 StopPrice=0 SignalName='OrdenVenta' FromEntrySignal=''
      5/9/2018 09:30:01 Amended open order: Action=SellShort OrderType=Limit Quantity=1 LimitPrice=71.19 StopPrice=0 SignalName=OrdenVenta' FromEntrySignal=''
      5/9/2018 09:30:01 Entered internal PlaceOrder() method at 5/9/2018 09:30:01: BarsInProgress=0 Action=SellShort OrderType=Limit Quantity=1 LimitPrice=71.18 StopPrice=0 SignalName='OrdenVenta' FromEntrySignal=''
      5/9/2018 09:30:01 Amended open order: Action=SellShort OrderType=Limit Quantity=1 LimitPrice=71.18 StopPrice=0 SignalName=OrdenVenta' FromEntrySignal=''
      5/9/2018 09:30:01 Entered internal PlaceOrder() method at 5/9/2018 09:30:01: BarsInProgress=0 Action=SellShort OrderType=Limit Quantity=1 LimitPrice=71.18 StopPrice=0 SignalName='OrdenVenta' FromEntrySignal=''
      5/9/2018 09:30:01 Ignore order amendment: Action=SellShort OrderType=Limit Quantity=1 LimitPrice=71.18 StopPrice=0 SignalName=OrdenVenta' FromEntrySignal='' Reason='Order already has this stop price/limit price/quantity'
      5/9/2018 09:30:01 Entered internal PlaceOrder() method at 5/9/2018 09:30:01: BarsInProgress=0 Action=SellShort OrderType=Limit Quantity=1 LimitPrice=71.17 StopPrice=0 SignalName='OrdenVenta' FromEntrySignal=''
      5/9/2018 09:30:01 Amended open order: Action=SellShort OrderType=Limit Quantity=1 LimitPrice=71.17 StopPrice=0 SignalName=OrdenVenta' FromEntrySignal=''

      And then it repeats each OnBarUpdate loop until change time + 1 sec...

      Thanks

      Comment


        #4
        Hello Josh, I already fixed this issue, thank you!

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        630 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        364 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        105 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        566 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        568 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X