sorry for my English
here is the script
#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;
#endregion
// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
[Description("Enter the description of your new custom indicator here")]
public class T2 : Indicator
{
#region Variables
// Wizard generated variables
private string second_instr = @"6E 09-15"; // Default setting for Second_instr
private int periodSMA = 20; // Default setting for PeriodSMA
private int BP = 100;
// User defined variables (add any user defined variables below)
#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()
{
Add(Second_instr,BarsPeriod.Id, BarsPeriod.Value);
Add(new Plot(Color.FromKnownColor(KnownColor.Red), PlotStyle.Line, "Posa"));
Add(new Plot(Color.FromKnownColor(KnownColor.Blue), PlotStyle.Line, "Posb"));
Overlay = false;
CalculateOnBarClose = false;
BarsRequired = periodSMA;
}
/// <summary>
/// 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
if (BarsInProgress != 0) return;
if(Closes[0][0]<=0 || Closes[1][0]<=0) return;
if(CurrentBar < 100) return;
Vola.Set(Math.Sign((Highs[0][0]-Lows[0][0])-1)*100);
Volb.Set(Math.Sign((Highs[1][0]-Lows[1][0])-1)*100);
Moving_Average.Set(SMA(Vola,periodSMA)[0]);
Moving_Average.Set(SMA(Volb,periodSMA)[0]);
Posa.Set(BP/SMA(Vola,periodSMA)[0]/Closes[0][0]);
Posb.Set(BP/SMA(Volb,periodSMA)[0]/Closes[1][0]);
// plot below by replacing 'Close[0]' with your own formula.
}
#region Properties
[Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
[XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
public DataSeries Vola
{
get { return Values[0]; }
}
[Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
[XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
public DataSeries Volb
{
get { return Values[1]; }
}
[Description("")]
[GridCategory("Parameters")]
public string Second_instr
{
get { return second_instr; }
set { second_instr = value; }
}
[Description("")]
[GridCategory("Parameters")]
public int PeriodSMA
{
get { return periodSMA; }
set { periodSMA = Math.Max(1, value); }
}
[Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
[XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
public DataSeries Moving_Average
{
get { return Values[2]; }
}
[Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
[XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
public DataSeries Posa
{
get { return Values[3]; }
}
[Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
[XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
public DataSeries Posb
{
get { return Values[4]; }
}
#endregion
}
}
Comment