Upperband=SMA(H*(1+4*(H - L) / (H + L)),20);
Lowerband= SMA(L*(1-4*(H - L)/ (H + L)),20);
namespace NinjaTrader.NinjaScript.Indicators
{
/// <summary>
/// Keltner Channel code converted to Acceleration Bands.
/// </summary>
public class AccelerationBands : Indicator
{
//private Series<double> diff;
private Series<double> diffU;
private Series<double> diffL;
//private SMA smaDiff;
private SMA smaDiffU;
private SMA smaDiffL;
//private SMA smaTypical;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = NinjaTrader.Custom.Resource.NinjaScriptIndicatorDe scriptionKeltnerChannel;
Name = "AccelerationBands";
Period = 20;
IsOverlay = true;
IsSuspendedWhileInactive = true;
OffsetMultiplier = 1.0;
AddPlot(Brushes.DodgerBlue, NinjaTrader.Custom.Resource.NinjaScriptIndicatorUp per);
AddPlot(Brushes.DodgerBlue, NinjaTrader.Custom.Resource.NinjaScriptIndicatorLo wer);
}
else if (State == State.DataLoaded)
{
diffU = new Series<double>(this);
smaDiffU = SMA(diffU, Period);
diffL = new Series<double>(this);
smaDiffL = SMA(diffL, Period);
//smaTypical = SMA(Typical, Period);
}
}
protected override void OnBarUpdate()
{
diffU[0] = High[0]*(1+4*(High[0] - Low[0]) / (High[0] + Low[0]));
diffL[0] = Low[0]*(1+4*(High[0] - Low[0]) / (High[0] + Low[0]));
double upper = smaDiffU[0];
double lower = smaDiffL[0];
Upper[0] = upper;
Lower[0] = lower;
}
Comment