region Using declarations
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Gui;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Gui.SuperDom;
using NinjaTrader.Gui.Tools;
using NinjaTrader.Data;
using NinjaTrader.NinjaScript;
using NinjaTrader.Core.FloatingPoint;
using NinjaTrader.NinjaScript.DrawingTools;
#endregion
//This namespace holds Indicators in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Indicators {
public class LeftRightMargin: Indicator {
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 bool border_On = true; // left or right
private int vSMA = 255;
private int upOpaclevel = 254;
private int downOpaclevel = 254;
private int widthStrip = 10;
protected override void OnStateChange() {
if (State == State.SetDefaults) {
Description = @"LeftRightMargin";
Name = "LeftRightMargin";
Calculate = Calculate.OnBarClose;
IsOverlay = false;
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.Green;
DownBrush = Brushes.Red;
NeutralBrush = Brushes.DimGray;
}
else if (State == State.Configure) {}
}
protected override void OnBarUpdate() {
//Add your custom indicator logic here.
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 = Brushes.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;
}
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;
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;
}
}
}
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;
}
}
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 NeutralBrushSerialize {
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
}
}
This is the file LeftRightMargin.cs also version 7 can be found here https://ninjatraderecosystem.com/use...margin-stripe/