Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

On Update() method and Windows Form

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

    On Update() method and Windows Form

    Hello everybody!

    I have written a indicator for controlling a single windows form so it has a TrackBar control that when is sliding, as well a horizontal line (DrawHorizontalLine method) is sliding. I need to use update() method because OnBarUpdate() method need to be called every time TrackBar.Value change, reglardless a new tick income.

    This is my purpose but the code doesn´t work. I think it is because Update() method is not working.

    Here is the Windows form code:

    Code:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    
    namespace TestFormNT
    {
        public partial class FormTrading : Form
        {
            public int ActualValue
            {
                get { return trackBar1.Value; }
            }
    
            public FormTrading()
            {
                InitializeComponent();
            }
    
            private void trackBar1_ValueChanged(object sender, EventArgs e)
            {
                if (OnNewValue != null)
                    OnNewValue(this, new EventArgs());
            }
    
            // Event to notify NinjTrader that SL range has been changed.
            public event EventHandler OnNewValue;
        }
    }
    And here is the indicator code:

    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.Gui.Chart;
    // Added to allow use of the Visual Studio Form dll.
    using TestFormNT;
    using System.Windows.Forms;
    #endregion
    
    // This namespace holds all indicators and is required. Do not change it.
    namespace NinjaTrader.Indicator
    {
        /// <summary>
        /// Not description
        /// </summary>
        [Description("Not description")]
        public class MyTestFormTrading : Indicator
        {
            #region Variables
            // Wizard generated variables
                private int myInput0 = 1; // Default setting for MyInput0
            // User defined variables (add any user defined variables below)
    		private bool firstTime = true;
    		private double incremento = 0;
    		public int aux = 0;
    		FormTrading Trading = new FormTrading();
            #endregion
    
            /// <summary>
            /// This method is used to configure the indicator and is called once before any bar data is loaded.
            /// </summary>
            protected override void Initialize()
            {
                Overlay				= false;
            }
    		
    		private void OnNewValueHandler(object sender, EventArgs e)
    		{
    			Trading.Controls["textBox1"].Text = Convert.ToString(Trading.ActualValue);
    			Update();
    		}
    
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
    			if (FirstTime)
    			{
    				Trading.Show();
    				FirstTime = false;
    				
    				Trading.OnNewValue += new EventHandler(OnNewValueHandler);
    			}
    			
    			incremento = Convert.ToDouble(Trading.ActualValue);
    			
    			DrawHorizontalLine("last", true, Close[0] + incremento * 0.0001, Color.Orange, DashStyle.Solid, 2);
            }
    
            #region Properties
    		public bool FirstTime
    		{
    			get { return firstTime; }
    			set { firstTime = value; }
    		}
    		
            [Description("")]
            [GridCategory("Parameters")]
            public int MyInput0
            {
                get { return myInput0; }
                set { myInput0 = Math.Max(1, value); }
            }
            #endregion
        }
    }
    How do I update OnBarUpdate() when I slide trackBar?

    Thank you very much!

    #2
    Hello,

    Thank you for the question.

    OnBarUpdate is an Override method meaning that it gets called by internal processes. You can create a void method of your own to call but OnBarUpdate is only called internally by market data or bar closes. The chart would not update based on a slider event, but would need to wait for the internal logic to call it.

    Generally Update() is called when you need to update information in an indicator that is being called by another indicator or strategy. this is not necessarily the case in your situation, you are looking to actually re paint the chart it seems.

    This type of item would be considered unsupported so because of this I can not really provide any other information, if any other users have any insight on this they can certainly post their comments to this as well.

    Please let me know if I may be of additional assistance.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    558 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    324 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    101 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    545 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    547 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X