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

Adding a daily period type to a minutes period type strategy code

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

    Adding a daily period type to a minutes period type strategy code

    I know this problem has been treated millions of times but I really can't figure out and I apologize.

    I would add a daily period type indicator to my minutes based strategy but, simply adding the row code in the initialization, the strategy doesn't do trades anymore. Why?!

    What follows is the code:


    {
    /// <summary>
    /// Enter the description of your strategy here
    /// </summary>
    [Description("Enter the description of your strategy here")]
    public class BuyHold : Strategy
    {
    #region Variables
    // Wizard generated variables
    private int myInput0 = 1; // Default setting for MyInput0
    // 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()
    {
    CalculateOnBarClose = true;
    Add(PeriodType.Day, 247);
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    if (ToTime(Time[0]) == ToTime(10, 0, 0))
    EnterLong(1, "");
    }

    #region Properties
    [Description("")]
    [GridCategory("Parameters")]
    public int MyInput0
    {
    get { return myInput0; }
    set { myInput0 = Math.Max(1, value); }
    }
    #endregion
    }
    }
    Last edited by Quikito; 05-04-2020, 04:30 AM.

    #2
    Hello Quikito,

    Thanks for your post.

    It looks like you are specifying to add a daily bar of 247 daily bars. Please try Add(PeriodType.Day, 1);

    The Add() will bring in the number of daily bars according to the charts data series "Days to load" setting. If your chart's data series has 5 days to load then when the script is run it will add 5 daily bars.

    When you apply a strategy, one of the parameters is the "Min number of bars required" which is set to 20, you may need to lower this value as otherwise your strategy would need 20 daily bars loaded before placing a trade.

    We highly recommend reviewing the help guide section on Multi time frame and Instrument scripts as there are a number of considerations for correctly coding in this environment. For your convienicne here is a direct link to that section: https://ninjatrader.com/support/help...nstruments.htm

    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Great! The problem was the min number of bars required as you said. Now I fixed it and it works great!
      Thank you!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by futtrader, 04-21-2024, 01:50 AM
      4 responses
      41 views
      0 likes
      Last Post futtrader  
      Started by Option Whisperer, Today, 09:55 AM
      1 response
      11 views
      0 likes
      Last Post bltdavid  
      Started by port119, Today, 02:43 PM
      0 responses
      3 views
      0 likes
      Last Post port119
      by port119
       
      Started by Philippe56140, Today, 02:35 PM
      0 responses
      4 views
      0 likes
      Last Post Philippe56140  
      Started by 00nevest, Today, 02:27 PM
      0 responses
      2 views
      0 likes
      Last Post 00nevest  
      Working...
      X