Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

problems getting OnBarUpdate() calls - NT 7

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

    problems getting OnBarUpdate() calls - NT 7

    Hi,

    I may be missing something obvious, but I want a strategy that prints out the current price (for now - it's going to be developed into something else eventually).

    OnBarUpdate() never seems to get called. I started it with Tick as the type and 1 as the value. I only want current data - no history. I get the 'starting' message output, , but that's all.

    Thanks

    #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 WritePrice : 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 = false;
    Print("starting");
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    // current data only
    if (Historical)
    return;

    Print("" + Close[0]);
    Print(base.Bars.Instrument.FullName.Substring(0, 2).ToLower());

    }

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

    #2
    I have a similar issue. CalculateOnBarClose is FALSE.

    For me, the print statements successfully print to the output window several times in the first two seconds when I ENABLE the strategy through NinjaTrader. However as subsequent ticks happen nothing gets printed. Code is below.

    protected override void OnBarUpdate()
    {
    Print("Bar Update...");
    double currentEMA;

    currentEMA = EMA(13)[0];

    Print("DATE: " + DateTime.Now);
    Print("--------------------------");
    Print("CurrentEMA(13): " + currentEMA);
    Print("");
    }

    Comment


      #3
      andrewbee, perhaps you're trying to load too much data and your computer is being overwhelmed. If you want to ignore historical data, please add this line to the very beginning of your OnBarUpdate(): if (Historical) return;

      That will skip over all of the historical bars and will force your script to work on real-time data only.

      How are you guys running your scripts? They should be printing every bar. Are there any errors in the logs (right-most tab of Control Center)? Is the session set to something that will display when you're running the script?
      AustinNinjaTrader Customer Service

      Comment


        #4
        I added the Ignore Historical but now it never reaches the print statements at all. It doesn't print even once. It's like it's doing nothing after loading historical data.

        I simplified my code per the below:

        /// <summary>
        /// This method is used to configure the strategy and is called once before any strategy method is called.
        /// </summary>
        protected override void Initialize()
        {
        Add(SMA(Fast));
        Add(SMA(Slow));

        CalculateOnBarClose = false;
        }

        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
        if (Historical) return;

        // Prints the current bar SMA value to the output window
        Print("DATE: " + DateTime.Now);

        }

        Comment


          #5
          What kind of session template are you using? Per default for NT7 R2 you would use the instrument's RTH hours, so if the current time would not fit within those hours you would see no OnBarUpdate() calls then. I would suggest trying the same on a chart using the ETH or Default named templates including overnight data as well then.

          Comment


            #6
            That worked! Thanks Bertrand.

            Comment


              #7
              Yes, it worked for me too. I was outside of RTH at the time.

              Thanks

              Comment

              Latest Posts

              Collapse

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