Adding amaSuperTrendU11 to custom strategy - compile error | Traders Hideout


futures.io - futures trading strategies, market news, trading charts and platforms


Traders Hideout


Discuss day trading practices and futures trading strategies on this forum for all markets. This forum is also for discussing and reviews for brokers, data feeds, and commercial or third party add-ons




 

Adding amaSuperTrendU11 to custom strategy - compile error

  #9 (permalink)

Denver colorado
 
Trading Experience: Intermediate
Platform: Nt
Favorite Futures: Es
 
Posts: 6 since Jan 2018
Thanks: 0 given, 2 received

help ninja script

I am trying to imply this indicator into the strategy builder NT8 but error coming.

namespace NinjaTrader.NinjaScript.Indicators.Sim22
{
/// <summary>
/// The Stochastic Oscillator is made up of two lines that oscillate between a vertical scale of 0 to 100. The %K is the main line and it is drawn as a solid line. The second is the %D line and is a moving average of %K. The %D line is drawn as a dotted line. Use as a buy/sell signal generator, buying when fast moves above slow and selling when fast moves below slow.
/// Sim22 May 2016 NT8b11.
/// Update V1.1: Moved input code to State.DataLoaded due to exceptions when placed in the market analyzer
/// </summary>
public class Sim22_DoubleStochastic_Colored_AnyInputGLV1 : Indicator
{
#region Variables


private double ob = 0.0;
private double os = 0.0;

private Series<double> KUpperBand;
private Series<double> KLowerBand;

private EMA emaP1;
private EMA emaP3;
private MIN minLow;
private MIN minP2;
private MAX maxHigh;
private MAX maxP2;
private Series<double> p1;
private Series<double> p2;
private Series<double> p3;
private int barNumberFromSessOpen;
private double gap = 0.0;
bool isPriceSeries = true;

Brush tempUpperBrush = Brushes.Transparent;
Brush tempLowerBrush = Brushes.Transparent;

#endregion

protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Name = "Sim22_DoubleStochastic_Colored_AnyInputGLV1.1";
Description = "Intraday Double Stochastics colored that ignores price gaps at the start of the intraday session. Use any input including indicators. Sim22 May 2016 NT8b10.";
IsOverlay = false;
DrawOnPricePanel = false;
Calculate = Calculate.OnPriceChange;
DrawKRegion = true;
OpacityKRegion = 30;
Period = 10;
UseGapless = true;
PlotPopsPoops = false;
PlotReversals = true;
ReverseColors = false;


AddPlot(new Stroke(Brushes.LimeGreen, DashStyleHelper.Solid, 2f), PlotStyle.Line, "KUpper");
AddPlot(new Stroke(Brushes.Gray, DashStyleHelper.Solid, 1f), PlotStyle.Line, "KMiddle");
AddPlot(new Stroke(Brushes.Red, DashStyleHelper.Solid, 2f), PlotStyle.Line, "KLower");

AddPlot(new Stroke(Brushes.Cyan, 4), PlotStyle.TriangleUp, "KReversalUp");
AddPlot(new Stroke(Brushes.Magenta, 4), PlotStyle.TriangleDown, "KReversalDown");

AddPlot(new Stroke(Brushes.LimeGreen, 4), PlotStyle.TriangleUp, "KPopUp");
AddPlot(new Stroke(Brushes.Red, 4), PlotStyle.TriangleDown, "KPoopDown");
///'K' is used for price markers only
AddPlot(new Stroke(Brushes.Gray, DashStyleHelper.Solid, 1f), PlotStyle.Line, "K-PriceMarker");

AddLine(new Stroke(Brushes.Red, DashStyleHelper.Dash, 1f), 10, "Lower");
AddLine(new Stroke(Brushes.LimeGreen, DashStyleHelper.Dash, 1f), 90, "Upper");

}
else if (State == State.Configure)
{
p1 = new Series<double>(this);
p2 = new Series<double>(this);
p3 = new Series<double>(this);

emaP1 = EMA(p1, 3);
emaP3 = EMA(p3, 3);
maxP2 = MAX(p2, Period);
minP2 = MIN(p2, Period);

KUpperBand = new Series<double>(this, MaximumBarsLookBack.Infinite);
KLowerBand = new Series<double>(this, MaximumBarsLookBack.Infinite);

///Set limitations for plots
ob = Plots[0].Min = Lines[1].Value;
Plots[1].Max = Lines[1].Value;
Plots[1].Min = Lines[0].Value;
os = Plots[2].Max = Lines[0].Value;

tempUpperBrush.Freeze();
tempLowerBrush.Freeze();

tempUpperBrush = Plots[0].Brush;
tempLowerBrush = Plots[2].Brush;

}
else if (State == State.DataLoaded)
{
////Update 1.1. Moved code here due to exceptions raised when placed in a market analyzer
///
/// Instrument price type
if (Input.GetType() == typeof(NinjaTrader.NinjaScript.PriceSeries))
{
isPriceSeries = true;
maxHigh = MAX(High, Period);
minLow = MIN(Low, Period);
}
else
/// Indicator
{
isPriceSeries = true;
UseGapless = false;
maxHigh = MAX(Input, Period);
minLow = MIN(Input, Period);

}

}
}

public override void OnCalculateMinMax()
{
/// Maintains a fixed scale to show full range of stochastic.
MinValue = 0.0;
MaxValue = 100.00;
if (PlotReversals)
{
MinValue -= Plots[3].Width * 2;
MaxValue += Plots[4].Width * 2;

}
}

public override string DisplayName
{
get { return String.Format("DStoch" + (UseGapless ? "'GL'" : "") + "({0})", Period); }
}


#region FormatNumberDecimalPlaces

Sim22_PriceFormatter.FormatNumberDecimalPlacesEnum dpEnum = Sim22_PriceFormatter.FormatNumberDecimalPlacesEnum.None;

public override string FormatPriceMarker(double value)
{
/* using static class Sim22_PriceFormatter in the Addons folder */
if (dpEnum == Sim22_PriceFormatter.FormatNumberDecimalPlacesEnum.SameAsInstrument)
return Sim22_PriceFormatter.FormatSameAsInstrumentPrice(value, TickSize);
else
return value.ToString("N" + Sim22_PriceFormatter.FormatNumberDecimalPlaces(dpEnum).ToString());
}

#endregion


protected override void OnBarUpdate()
{
try
{
double input = Input[0];

double partialGap = 0.0;

if (UseGapless && IsFirstTickOfBar)
{
if (Bars.IsFirstBarOfSession && CurrentBar > 0)
{
barNumberFromSessOpen = CurrentBar;
gap = Open[0] - Close[1];
}

if ((CurrentBar - barNumberFromSessOpen) < Period)
{
partialGap = gap * (Period - (CurrentBar - barNumberFromSessOpen + 1))/Period;
}
}

double maxHigh0 = maxHigh[0];
double minLow0 = minLow[0];
double r = maxHigh0 - minLow0;
r = r.ApproxCompare(0) == 0 ? 0 : r;

if (r == 0)
p1[0] = CurrentBar == 0 ? 50 : p1[1];
else
p1[0] = Math.Min(100, Math.Max(0, 100 * (input - minLow0 - 2 * partialGap) / (r - partialGap)));

p2[0] = emaP1[0];
double minP20 = minP2[0];
double s = maxP2[0] - minP20;
s = s.ApproxCompare(0) == 0 ? 0 : s;

if (s == 0)
p3[0] = CurrentBar == 0 ? 50 : p3[1];
else
p3[0] = Math.Min(100, Math.Max(0, 100 * (p2[0] - minP20) / s));

double k = emaP3[0];

KLower[0] = KMiddle[0] = KUpper[0] = k;

if (ReverseColors)
{
tempUpperBrush = PlotBrushes[0][0] = Plots[2].Brush;
tempLowerBrush = PlotBrushes[2][0] = Plots[0].Brush;
}

Lines[0].Brush = tempLowerBrush;
Lines[1].Brush = tempUpperBrush;

if (DrawKRegion)
{
KUpperBand[0] = KUpper[0] >= ob ? KUpper[0] : ob;
KLowerBand[0] = KLower[0] <= os ? KLower[0] : os;

Draw.Region(this,"upperK", CurrentBar, 0, KUpperBand, ob, tempUpperBrush, OpacityKRegion);
Draw.Region(this,"lowerK", CurrentBar, 0, KLowerBand, os, tempLowerBrush, OpacityKRegion);
}

if (PaintPriceMarkers && CurrentBar == (Bars.Count - 1))
{
K[0] = k;

if (K[0] >= ob)
PlotBrushes[7][0] = tempUpperBrush;
else if (K[0] <= os)
PlotBrushes[7][0] = tempLowerBrush;
else
PlotBrushes[7][0] = Plots[1].Brush;
}

if (base.IsFirstTickOfBar)
{
if (PlotReversals && CurrentBar > 3)
{
if ((IsRising(KLower)) && ((KLower[1]) < os) && (KLower[2]) >= (KLower[1]))
{
KReversalUp[1] = KUpper[1];
}

if ((IsFalling(KUpper)) && ((KUpper[1]) > ob) && (KUpper[2]) <= (KUpper[1]))
{
KReversalDown[1] = KLower[1];
}
}
}

if (PlotPopsPoops && CurrentBar > 3)
{
if (CrossAbove(KUpper, ob, 1))
{
KPopUp[0] = ob;
}

if (CrossBelow(KLower, os, 1))
{
KPoopDown[0] = os;
}
}
}
catch{}
}

#region Properties



[Browsable(false)]
[XmlIgnore()]
public Series<double> KUpper
{
get { return Values[0]; }
}

[Browsable(false)]
[XmlIgnore()]
public Series<double> KMiddle
{
get { return Values[1]; }
}

[Browsable(false)]
[XmlIgnore()]
public Series<double> KLower
{
get { return Values[2]; }
}

[Browsable(false)]
[XmlIgnore()]
public Series<double> KReversalUp
{
get { return Values[3]; }
}

[Browsable(false)]
[XmlIgnore()]
public Series<double> KReversalDown
{
get { return Values[4]; }
}

[Browsable(false)]
[XmlIgnore()]
public Series<double> KPopUp
{
get { return Values[5]; }
}

[Browsable(false)]
[XmlIgnore()]
public Series<double> KPoopDown
{
get { return Values[6]; }
}

[Browsable(false)]
[XmlIgnore()]
public Series<double> K
{
get { return Values[7]; }
}

[NinjaScriptProperty]
[Display(Name="Decimal Places", Description="", Order=0, GroupName="Set up")]
public Sim22_PriceFormatter.FormatNumberDecimalPlacesEnum DPEnum
{
get { return dpEnum; }
set { dpEnum = value; }
}

[NinjaScriptProperty]
[Display(ResourceType = typeof(Custom.Resource), Name = "(Intraday) Plot gapless?", GroupName = "NinjaScriptParameters", Order = 0)]
public bool UseGapless
{ get; set; }

[Range(1, int.MaxValue), NinjaScriptProperty]
[Display(ResourceType = typeof(Custom.Resource), Name = "Period", GroupName = "NinjaScriptParameters", Order = 2)]
public int Period
{ get; set; }

[NinjaScriptProperty]
[Display(Name = "Plot reversals?", Description = "Plot reversals?", GroupName = ".Plots", Order = 0)]
public bool PlotReversals
{ get; set; }

[NinjaScriptProperty]
[Display(Name = "Plot pops & poops?", Description = "Plot pops & poops?", GroupName = ".Plots", Order = 1)]
public bool PlotPopsPoops
{ get; set; }

[NinjaScriptProperty]
[Display(Name = "Reverse colors?", Description = "Reverse colors?", GroupName = ".Plots", Order = 2)]
public bool ReverseColors
{ get; set; }

[NinjaScriptProperty]
[Display(Name = "Shade K region?", Description = "Shade K region?", GroupName = ".Plots", Order = 5)]
public bool DrawKRegion
{ get; set; }

[Range(0, 100), NinjaScriptProperty]
[Display(Name = "K region opacity (0-100)", Description = "K region opacity (0-100)", GroupName = ".Plots", Order = 6)]
public int OpacityKRegion
{ get; set; }

#endregion
}
}

#region NinjaScript generated code. Neither change nor remove.

namespace NinjaTrader.NinjaScript.Indicators
{
public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
{
private Sim22.Sim22_DoubleStochastic_Colored_AnyInputGLV1[] cacheSim22_DoubleStochastic_Colored_AnyInputGLV1;
public Sim22.Sim22_DoubleStochastic_Colored_AnyInputGLV1 Sim22_DoubleStochastic_Colored_AnyInputGLV1(Sim22_PriceFormatter.FormatNumberDecimalPlacesEnum dPEnum, bool useGapless, int period, bool plotReversals, bool plotPopsPoops, bool reverseColors, bool drawKRegion, int opacityKRegion)
{
return Sim22_DoubleStochastic_Colored_AnyInputGLV1(Input, dPEnum, useGapless, period, plotReversals, plotPopsPoops, reverseColors, drawKRegion, opacityKRegion);
}

public Sim22.Sim22_DoubleStochastic_Colored_AnyInputGLV1 Sim22_DoubleStochastic_Colored_AnyInputGLV1(ISeries<double> input, Sim22_PriceFormatter.FormatNumberDecimalPlacesEnum dPEnum, bool useGapless, int period, bool plotReversals, bool plotPopsPoops, bool reverseColors, bool drawKRegion, int opacityKRegion)
{
if (cacheSim22_DoubleStochastic_Colored_AnyInputGLV1 != null)
for (int idx = 0; idx < cacheSim22_DoubleStochastic_Colored_AnyInputGLV1.Length; idx++)
if (cacheSim22_DoubleStochastic_Colored_AnyInputGLV1[idx] != null && cacheSim22_DoubleStochastic_Colored_AnyInputGLV1[idx].DPEnum == dPEnum && cacheSim22_DoubleStochastic_Colored_AnyInputGLV1[idx].UseGapless == useGapless && cacheSim22_DoubleStochastic_Colored_AnyInputGLV1[idx].Period == period && cacheSim22_DoubleStochastic_Colored_AnyInputGLV1[idx].PlotReversals == plotReversals && cacheSim22_DoubleStochastic_Colored_AnyInputGLV1[idx].PlotPopsPoops == plotPopsPoops && cacheSim22_DoubleStochastic_Colored_AnyInputGLV1[idx].ReverseColors == reverseColors && cacheSim22_DoubleStochastic_Colored_AnyInputGLV1[idx].DrawKRegion == drawKRegion && cacheSim22_DoubleStochastic_Colored_AnyInputGLV1[idx].OpacityKRegion == opacityKRegion && cacheSim22_DoubleStochastic_Colored_AnyInputGLV1[idx].EqualsInput(input))
return cacheSim22_DoubleStochastic_Colored_AnyInputGLV1[idx];
return CacheIndicator<Sim22.Sim22_DoubleStochastic_Colored_AnyInputGLV1>(new Sim22.Sim22_DoubleStochastic_Colored_AnyInputGLV1(){ DPEnum = dPEnum, UseGapless = useGapless, Period = period, PlotReversals = plotReversals, PlotPopsPoops = plotPopsPoops, ReverseColors = reverseColors, DrawKRegion = drawKRegion, OpacityKRegion = opacityKRegion }, input, ref cacheSim22_DoubleStochastic_Colored_AnyInputGLV1);
}
}
}

namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
{
public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
{
public Indicators.Sim22.Sim22_DoubleStochastic_Colored_AnyInputGLV1 Sim22_DoubleStochastic_Colored_AnyInputGLV1(Sim22_PriceFormatter.FormatNumberDecimalPlacesEnum dPEnum, bool useGapless, int period, bool plotReversals, bool plotPopsPoops, bool reverseColors, bool drawKRegion, int opacityKRegion)
{
return indicator.Sim22_DoubleStochastic_Colored_AnyInputGLV1(Input, dPEnum, useGapless, period, plotReversals, plotPopsPoops, reverseColors, drawKRegion, opacityKRegion);
}

public Indicators.Sim22.Sim22_DoubleStochastic_Colored_AnyInputGLV1 Sim22_DoubleStochastic_Colored_AnyInputGLV1(ISeries<double> input , Sim22_PriceFormatter.FormatNumberDecimalPlacesEnum dPEnum, bool useGapless, int period, bool plotReversals, bool plotPopsPoops, bool reverseColors, bool drawKRegion, int opacityKRegion)
{
return indicator.Sim22_DoubleStochastic_Colored_AnyInputGLV1(input, dPEnum, useGapless, period, plotReversals, plotPopsPoops, reverseColors, drawKRegion, opacityKRegion);
}
}
}

namespace NinjaTrader.NinjaScript.Strategies
{
public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
{
public Indicators.Sim22.Sim22_DoubleStochastic_Colored_AnyInputGLV1 Sim22_DoubleStochastic_Colored_AnyInputGLV1(Sim22_PriceFormatter.FormatNumberDecimalPlacesEnum dPEnum, bool useGapless, int period, bool plotReversals, bool plotPopsPoops, bool reverseColors, bool drawKRegion, int opacityKRegion)
{
return indicator.Sim22_DoubleStochastic_Colored_AnyInputGLV1(Input, dPEnum, useGapless, period, plotReversals, plotPopsPoops, reverseColors, drawKRegion, opacityKRegion);
}

public Indicators.Sim22.Sim22_DoubleStochastic_Colored_AnyInputGLV1 Sim22_DoubleStochastic_Colored_AnyInputGLV1(ISeries<double> input , Sim22_PriceFormatter.FormatNumberDecimalPlacesEnum dPEnum, bool useGapless, int period, bool plotReversals, bool plotPopsPoops, bool reverseColors, bool drawKRegion, int opacityKRegion)
{
return indicator.Sim22_DoubleStochastic_Colored_AnyInputGLV1(input, dPEnum, useGapless, period, plotReversals, plotPopsPoops, reverseColors, drawKRegion, opacityKRegion);
}
}
}

#endregion

Reply With Quote