region Variables
private ToolStrip toolStripForm = null;
private ToolStripButton Engage_Button = null;
private int ct = 0;
private int Bias = -1;
const int NONE = -1;
const int SHORT = 0;
const int LONG = 1;
private Color upColor = Color.Green;
private Color downColor = Color.Red;
private Color neutralColor = Color.DimGray;
private bool border_On = true; // left or right
private int vsma = 255;
private int upOpaclevel = 254;
private int downOpaclevel = 254;
private int widthStrip = 10;
#endregion
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"LeftMarginStripe";
Name = "LeftMarginStripe";
Calculate = Calculate.OnBarClose;
IsOverlay = true;
DisplayInDataBox = true;
DrawOnPricePanel = true;
DrawHorizontalGridLines = true;
DrawVerticalGridLines = true;
PaintPriceMarkers = true;
ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
//Disable this property if your indicator requires custom values that cumulate with each new market data event.
//See Help Guide for additional information.
IsSuspendedWhileInactive = true;
UpBrush = Brushes.Honeydew;
DownBrush = Brushes.MistyRose;
}
region Tool Bar Control
}
protected override void OnBarUpdate()
{
}
region Tool Bar Control
protected override void OnStartUp()
{
if (toolStripForm==null)
{
if (border_On)
toolStripForm= new ToolStrip() {Dock=DockStyle.Right, Name="ToolStripFormeSenderReceiever", Visible=true};
else if (!border_On)
toolStripForm= new ToolStrip() {Dock=DockStyle.Left, Name="ToolStripFormeSenderReceiever", Visible=true};
toolStripForm.AutoSize = false;
toolStripForm.CanOverflow = false;
ChartControl.Controls.Add(toolStripForm);
this.toolStripForm.BackColor = Color.Gray;
this.toolStripForm.Width = widthStrip;
Engage_Button = new ToolStripButton("Switch");
Engage_Button.Enabled = true;
Engage_Button.Name = "Switch";
Engage_Button.Text = "";
Engage_Button.Click += button1_Click;
Engage_Button.AutoSize = false;
toolStripForm.Items.Add(Engage_Button);
toolStripForm.Resize += toolStripForm_Resize;
toolStripForm_Resize(null,null);
}
return;
}
private void toolStripForm_Resize(object sender, System.EventArgs e)
{
this.Engage_Button.Height = 50;
this.Engage_Button.Width = 15 ;
this.Engage_Button.Invalidate();
}
private void button1_Click(object sender, EventArgs e)
{
ct = ct + 1;
switch (ct)
{
case 1:
this.toolStripForm.BackBrushColor = Brushes.Black;
break;
case 2:
this.toolStripForm.BackBrushColor = Brushes.DarkOrange;
break;
case 3:
{
ct = 0;
this.toolStripForm.BackBrushColor = Brushes.Gray;
}
break;
}
return;
}
#endregion
/// <summary>
///
/// </summary>
protected void Calculate_Bias()
{
if (Rising(SMA(BarsArray[0],vsma)))
{Bias = LONG;return;}
if (Falling(SMA(BarsArray[0],vsma)))
{Bias = SHORT;return;}
Bias = NONE;
return;
}
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Use this method for calculating your indicator values. Assign a value to each
// plot below by replacing 'Close[0]' with your own formula.
if(BarsInProgress != 0) {return;}
if (CurrentBars[0] < BarsRequired) {return;}
if(Historical) {return;}
Calculate_Bias();
{
switch (Bias)
{
case NONE:
{
this.toolStripForm.BackBrush = neutralBrushes;
}
break;
case LONG:
{
this.toolStripForm.BackBrushColor = Brushes.FromArgb(upOpaclevel, upBrushes); //BrushesColor
}
break;
case SHORT:
{
this.toolStripForm.BackBrushColor = Brushes.FromArgb(downOpaclevel, downBrushes); //BrushesColor;
}
break;
}
}
}
// This is called to shut down the form
region Termination
protected override void OnTermination()
{
if ( toolStripForm != null )
{
toolStripForm.Resize -= toolStripForm_Resize;
if ( Engage_Button != null )
toolStripForm.Items.Remove(Engage_Button);
toolStripForm.Dispose();
toolStripForm = null;
Engage_Button = null;
}
}
#endregion
region Properties
// Create our user definable color input
[XmlIgnore()]
[ Description ("Color for Up.")]
[GridCategory("Stripe")]
public Brush UpBrush
{ get; set; }
// Serialize our Color object
[Browsable(false)]
public string UpBrushSerialize
{
get { return Serialize.BrushToString(UpBrush); }
set { UpBrush = Serialize.StringToBrush(value); }
}
[XmlIgnore()]
[ Description ("Color for Down.")]
[GridCategory("Stripe")]
public Brush DownBrush
{ get; set; }
[Browsable(false)]
public string DownBrushSerialize
{
get { return Serialize.BrushToString(DownBrush); }
set { DownBrush = Serialize.StringToBrush(value); }
}
[XmlIgnore()]
[ Description ("Color for Neutral.")]
[GridCategory("Stripe")]
public Brush NeutralBrush
{ get; set; }
[Browsable(false)]
public string DownBrushSerialize
{
get { return Serialize.BrushToString(NeutralBrush); }
set { NeutralBrush = Serialize.StringToBrush(value); }
}
/// </summary>
[Description("Chosen value of SMA.")]
[Category("Parameters")]
public int Vsma
{
get { return vsma; }
set { vsma = Math.Max(1, value); }
}
[Description("True: Right sided stripe. False: Left sided stripe.")]
[GridCategory("Stripe")]
public bool Border_On
{
get { return border_On; }
set { border_On = value; }
}
/// </summary>
[Description("Width of stripe.")]
[GridCategory("Parameters")]
public int WidthStrip
{
get { return widthStrip; }
set { widthStrip = Math.Max(1, value); }
}
/// </summary>
[Description("Opacity Level for Up. 1-254.")]
[GridCategory("Stripe")]
public int UpOpaclevel
{
get { return upOpaclevel; }
set { upOpaclevel = Math.Max(1, value); }
}
/// </summary>
[Description("Opacity Level for Down. 1-254.")]
[GridCategory("Stripe")]
public int DownOpaclevel
{
get { return downOpaclevel; }
set { downOpaclevel = Math.Max(1, value); }
}
#endregion
}
}
Comment