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

Multiple bar printing help

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

    Multiple bar printing help

    Hello,

    I am trying to figure out to print the current bar number on each bar. I put 50 in barAgo and it still prints the current bar number on the last bar only. Will you please shed some light on this?

    Many thanks,
    -traderjh

    Code:
    #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>
        /// 
        /// </summary>
        [Description("")]
        public class ShowData : 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;
            }
    
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
    		DrawText("mybar", false, "#"+CurrentBar, Time[0], High[0], 50, Color.Yellow, new Font("Arial", 10), StringAlignment.Center, Color.Black, Color.Black, 10);
            }
    
            #region Properties
            [Description("")]
            [GridCategory("Parameters")]
            public int MyInput0
            {
                get { return myInput0; }
                set { myInput0 = Math.Max(1, value); }
            }
            #endregion
        }
    }

    #2
    You will want to assign a unique string to each instance of "mybar":

    Code:
    DrawText([B]"mybar"+CurrentBa[/B]r, false, "#"+CurrentBar, Time[0], High[0], 50, Color.Yellow, new Font("Arial", 10), StringAlignment.Center, Color.Black, Color.Black, 10);
    MatthewNinjaTrader Product Management

    Comment


      #3
      Trying to find correct lowest price in session

      Thanks for the answer.

      Another question if its ok with you.

      I am trying to get the correct lowest price of the session. This code only picks up the low price of the same bar with the highest price. What do I need to correct?

      Thanks again,
      -traderjh

      Code:
      #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>
          /// 
          /// </summary>
          [Description("")]
          public class ShowMinuteBarData : Strategy
          {
              #region Variables
              // Wizard generated variables
              // 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;
              }
      
              /// <summary>
              /// Called on each bar update event (incoming tick)
              /// </summary>
              protected override void OnBarUpdate()
              {
      			double myHi = MAX(High, 22)[0];
      			[B]double myLo = MAX(Low, 22)[0];[/B]
      			
      			DrawTextFixed("Show data", 
      			myHi
      			+ "\n" + myLo
      			+ "\n" + HighestBar(Close, Bars.BarsSinceSession - 1).ToString()
      			+ "\n" + LowestBar(Close, Bars.BarsSinceSession - 1).ToString()
      			,TextPosition.TopLeft,Color.Black,new Font("Arial", 9),Color.Black,Color.Orange,10);
      			DrawText("upperbar"+CurrentBar,true, "#"+CurrentBar+"\n"+High[0], Time[0], High[0], 24, Color.Yellow, new Font("Arial", 8), StringAlignment.Center, Color.Black, Color.Black, 10);
      			DrawText("lowerbar"+CurrentBar,true, "\n"+Low[0], Time[0], Low[0], 0, Color.Yellow, new Font("Arial", 8), StringAlignment.Center, Color.Black, Color.Black, 10);
      		}
      
              #region Properties
              #endregion
          }
      }
      Attached Files

      Comment


        #4
        You're going to want to use Min for the low value, as Max is going to find the Highest low value.

        double myLo = Min(Low, 22)[0];
        MatthewNinjaTrader Product Management

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Rapine Heihei, Today, 08:25 PM
        0 responses
        2 views
        0 likes
        Last Post Rapine Heihei  
        Started by Rapine Heihei, Today, 08:19 PM
        0 responses
        1 view
        0 likes
        Last Post Rapine Heihei  
        Started by f.saeidi, Today, 08:01 PM
        1 response
        4 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by Rapine Heihei, Today, 07:51 PM
        0 responses
        5 views
        0 likes
        Last Post Rapine Heihei  
        Started by frslvr, 04-11-2024, 07:26 AM
        5 responses
        96 views
        1 like
        Last Post caryc123  
        Working...
        X