I am trying to implement a Point of Control value into a custom strategy. There has been an indicator created by another forum called SimplePOC. This indicator functions fine as an indicator, however, if I try to reference it in a strategy it throws an error, saying the color is not defined and also that the color is acting as a variable. Is there any way I can resolve this?
Code below for the original SimplePOC indicator.
#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;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
#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 SimplePOC : Indicator
{
private Color clr=Color.Blue;
private Dictionary<double, double> vol_price = new Dictionary<double, double>();
private Dictionary<Int32, double> poc_list = new Dictionary<Int32, double>();
public override void Plot(Graphics graphics, Rectangle bounds, double min, double max)
{
for (int i=ChartControl.FirstBarPainted;i<=ChartControl.LastBarPainted;i++)
{
if (i>=0 && i<=BarsArray[0].Count-1)
{
int x=ChartControl.GetXByBarIdx(BarsArray[0],i)-ChartControl.BarWidth;
int y=ChartControl.GetYByValue(BarsArray[0],poc_list[i]);
graphics.DrawLine(new Pen(new SolidBrush(clr),2),x-4,y,x+6+ChartControl.BarWidth*2,y);
}
}
}
protected override void Initialize()
{
Overlay = true;
CalculateOnBarClose=false;
Add(PeriodType.Tick,1);
}
protected override void OnBarUpdate()
{
if (BarsInProgress==1)
{
if (!vol_price.ContainsKey(Closes[1][0]))
vol_price.Add(Closes[1][0],Volumes[1][0]);
else
vol_price[Closes[1][0]]+=Volumes[1][0];
}
if (BarsInProgress==0)
{
if (FirstTickOfBar)
{
double poc_price=0;
double poc_vol=0;
foreach(KeyValuePair<double, double> kvp in vol_price.OrderByDescending(key => key.Value))
{
poc_price=kvp.Key;
poc_vol=kvp.Value;
break;
}
poc_list.Add(CurrentBar,poc_price);
vol_price.Clear();
}
if (!Historical)
{
double poc_price2=0;
double poc_vol2=0;
foreach(KeyValuePair<double, double> kvp in vol_price.OrderByDescending(key => key.Value))
{
poc_price2=kvp.Key;
poc_vol2=kvp.Value;
break;
}
poc_list[CurrentBar]=poc_price2;
}
}
}
#region Properties
[Gui.Design.DisplayName("Color for POC line")]
[GridCategory("Parameters")]
public Color Clr
{
get { return clr ; }
set { clr = value; }
}
[Browsable(false)]
public string clrSerialize
{
get { return NinjaTrader.Gui.Design.SerializableColor.ToString(clr ); }
set { clr = NinjaTrader.Gui.Design.SerializableColor.FromString(value); }
}
#endregion
}
}
#region NinjaScript generated code. Neither change nor remove.
// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
public partial class Indicator : IndicatorBase
{
private SimplePOC[] cacheSimplePOC = null;
private static SimplePOC checkSimplePOC = new SimplePOC();
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
public SimplePOC SimplePOC(Color clr)
{
return SimplePOC(Input, clr);
}
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
public SimplePOC SimplePOC(Data.IDataSeries input, Color clr)
{
if (cacheSimplePOC != null)
for (int idx = 0; idx < cacheSimplePOC.Length; idx++)
if (cacheSimplePOC[idx].Clr == clr && cacheSimplePOC[idx].EqualsInput(input))
return cacheSimplePOC[idx];
lock (checkSimplePOC)
{
checkSimplePOC.Clr = clr;
clr = checkSimplePOC.Clr;
if (cacheSimplePOC != null)
for (int idx = 0; idx < cacheSimplePOC.Length; idx++)
if (cacheSimplePOC[idx].Clr == clr && cacheSimplePOC[idx].EqualsInput(input))
return cacheSimplePOC[idx];
SimplePOC indicator = new SimplePOC();
indicator.BarsRequired = BarsRequired;
indicator.CalculateOnBarClose = CalculateOnBarClose;
#if NT7
indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
indicator.MaximumBarsLookBack = MaximumBarsLookBack;
#endif
indicator.Input = input;
indicator.Clr = clr;
Indicators.Add(indicator);
indicator.SetUp();
SimplePOC[] tmp = new SimplePOC[cacheSimplePOC == null ? 1 : cacheSimplePOC.Length + 1];
if (cacheSimplePOC != null)
cacheSimplePOC.CopyTo(tmp, 0);
tmp[tmp.Length - 1] = indicator;
cacheSimplePOC = tmp;
return indicator;
}
}
}
}
// This namespace holds all market analyzer column definitions and is required. Do not change it.
namespace NinjaTrader.MarketAnalyzer
{
public partial class Column : ColumnBase
{
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.SimplePOC SimplePOC(Color clr)
{
return _indicator.SimplePOC(Input, clr);
}
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
public Indicator.SimplePOC SimplePOC(Data.IDataSeries input, Color clr)
{
return _indicator.SimplePOC(input, clr);
}
}
}
// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
public partial class Strategy : StrategyBase
{
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.SimplePOC SimplePOC(Color clr)
{
return _indicator.SimplePOC(Input, clr);
}
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
public Indicator.SimplePOC SimplePOC(Data.IDataSeries input, Color clr)
{
if (InInitialize && input == null)
throw new ArgumentException("You only can access an indicator with the default input/bar series from within the 'Initialize()' method");
return _indicator.SimplePOC(input, clr);
}
}
}
#endregion
thanks,
Nick

Comment