Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 martin70, 03-24-2023, 04:58 AM
        15 responses
        114 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by The_Sec, Today, 02:29 PM
        1 response
        5 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by jeronymite, 04-12-2024, 04:26 PM
        2 responses
        30 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Started by Mindset, 05-06-2023, 09:03 PM
        10 responses
        265 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Started by michi08, 10-05-2018, 09:31 AM
        5 responses
        743 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Working...
        X