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:
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;
}
}
#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
}
}
Thank you very much!

Comment