I have no coding experience whatsoever. I need some help if possible.
I am trying to covert a few of my favorite indicators and keep getting the same error even after corrections. Can't get it to compile without errors. This is a price channel %PC indicator. Similar to this https://help.tradestation.com/10_00/...indicator_.htm
Hoping someone can help me fix the errors.
Thanks!
region Using declarations
using System;
using System.ComponentModel;
using System.Windows.Media;
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;
#endregion
// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Indicators
{
public class PriceChannelPctNinja : Indicator
{
private Brush backgroundColorAlertCell;
private bool colorPercentP;
private Brush percentPHighColor;
private Brush percentPLowColor;
private Brush percentPVeryHighColor;
private Brush percentPVeryLowColor;
private double lowerBand;
private double upperBand;
private double percentP;
private double scaledPercentP;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"The Price Channel % PC indicator calculates the percent change of the price channel.";
Name = "PriceChannelPctNinja";
Calculate = Calculate.OnPriceChange;
IsOverlay = true;
DisplayInDataBox = true;
DrawOnPricePanel = true;
DrawHorizontalGridLines = true;
DrawVerticalGridLines = true;
PaintPriceMarkers = true;
ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
length = 20;
colorPercentP = true;
percentPVeryHighColor = Brushes.Yellow;
percentPHighColor = Brushes.Red;
percentPLowColor = Brushes.Magenta;
percentPVeryLowColor = Brushes.Cyan;
backgroundColorAlertCell = Brushes.DarkGray;
AddPlot(Brushes.Cyan, "%P");
AddLine(Brushes.DarkGreen, 100, "Upper Band");
AddLine(Brushes.DarkGreen, 50, "Middle Band");
AddLine(Brushes.DarkGreen, 0, "Lower Band");
}
else if (State == State.Configure)
{
}
}
protected override void OnBarUpdate()
{
lowerBand = MIN(Low, length)[1];
upperBand = MAX(High, length)[1];
percentP = (upperBand != lowerBand) ? (Close[0] - lowerBand) / (upperBand - lowerBand) : 0;
scaledPercentP = 100 * percentP;
Plot[0].Values[0] = scaledPercentP;
PlotBrushes[0][0] = (colorPercentP) ?
(scaledPercentP > 100 ? percentPVeryHighColor :
(scaledPercentP >= 50 ? percentPHighColor :
(scaledPercentP > 0 ? percentPLowColor : percentPVeryLowColor)))
: Brushes.Cyan;
double upperLine = MAX(High, length)[0];
double lowerLine = MIN(Low, length)[0];
if (Close[0] > upperLine)
{
BackBrush = backgroundColorAlertCell;
Alert("Price making new high", Priority.High, "Price making new high");
}
else if (Close[0] < lowerLine)
{
BackBrush = backgroundColorAlertCell;
Alert("Price making new low", Priority.High, "Price making new low");
}
else
{
BackBrush = null;
}
}
region Properties
[Browsable(false)]
[XmlIgnore()]
region NinjaScript generated code. Neither change nor remove.
namespace NinjaTrader.NinjaScript.Indicators
{
public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
{
private PriceChannelPctNinja[] cachePriceChannelPctNinja;
public PriceChannelPctNinja PriceChannelPctNinja()
{
return PriceChannelPctNinja(Input);
}
public PriceChannelPctNinja PriceChannelPctNinja(ISeries<double> input)
{
if (cachePriceChannelPctNinja != null)
for (int idx = 0; idx < cachePriceChannelPctNinja.Length; idx++)
if (cachePriceChannelPctNinja[idx] != null && cachePriceChannelPctNinja[idx].EqualsInput(input))
return cachePriceChannelPctNinja[idx];
return CacheIndicator<PriceChannelPctNinja>(new PriceChannelPctNinja(), input, ref cachePriceChannelPctNinja);
}
}
}
namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
{
public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
{
public Indicators.PriceChannelPctNinja PriceChannelPctNinja()
{
return indicator.PriceChannelPctNinja(Input);
}
public Indicators.PriceChannelPctNinja PriceChannelPctNinja(ISeries<double> input )
{
return indicator.PriceChannelPctNinja(input);
}
}
}
namespace NinjaTrader.NinjaScript.Strategies
{
public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
{
public Indicators.PriceChannelPctNinja PriceChannelPctNinja()
{
return indicator.PriceChannelPctNinja(Input);
}
public Indicators.PriceChannelPctNinja PriceChannelPctNinja(ISeries<double> input )
{
return indicator.PriceChannelPctNinja(input);
}
}
}
#endregion
Here are the errors.
Error | Code | Line | Column |
#endregion directive expected | CS1038 | 160 | 1 |
Type expected | CS1031 | 106 | 1 |
Invalid token 'namespace' in class, struct, or interface member declaration | CS1519 | 106 | 1 |
Invalid token '{' in class, struct, or interface member declaration | CS1519 | 107 | 1 |
} expected | CS1513 | 157 | 2 |
Class member declaration expected. | 99 | 21 | |
Class member declaration expected. | 105 | 44 | |
'}' expected. | 156 | 1 |
Comment