region Using declarations
using System;
using System.ComponentModel;
using System.Drawing;
using NinjaTrader.Data;
using NinjaTrader.Gui.Chart;
#endregion
namespace NinjaTrader.NinjaScript.Indicators
{
[Description("Calculates the size of a candle on any timeframe")]
public class CandleSize : Indicator
{
private double candleSize;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Calculates the size of a candle on any timeframe";
Name = "CandleSize";
Calculate = Calculate.OnBarClose;
IsOverlay = false;
DisplayInDataBox = true;
DrawOnPricePanel = false;
DrawHorizontalGridLines = true;
DrawVerticalGridLines = true;
PaintPriceMarkers = true;
ScaleJustification = ScaleJustification.Right;
IsSuspendedWhileInactive = true;
AddLine(Brushes.DarkCyan, 25, NinjaTrader.Custom.Resource.NinjaScriptIndicatorLo wer);
AddLine(Brushes.DarkCyan, 40, NinjaTrader.Custom.Resource.NinjaScriptIndicatorUp per);
}
else if (State == State.Configure)
{
AddPlot(new Stroke(Brushes.DodgerBlue, 2), PlotStyle.Bar, "CandleSize");
}
}
protected override void OnBarUpdate()
{
if (CurrentBars[0] == 0)
{
return;
}
double high = High[0];
double low = Low[0];
candleSize = Math.Abs(high - low);
CandleSizePlot[0] = candleSize / TickSize;
}
region Properties
[Browsable(false)]
[XmlIgnore()]
public Series<double> CandleSizePlot
{
get { return Values[0]; }
}
#endregion
}
}
Comment