View Full Version : Multiple Line Plots
jerryvellutini
11-11-2009, 03:58 PM
I'm trying to develop an indicator with three line plots. I followed the steps in the Level 2 tutorial and created Plot0, Plot1 and Plot2. When I compile, I get:
"The name Plot1 does not exist in the current context."
"The name Plot2 does not exist in the current context."
NinjaTrader_Ray
11-11-2009, 04:04 PM
I believe somehow you might have accidentally deleted the properties Plot1 and Plot2 inadvertently. Try replacing Plot1 and Plot2 with Values[0] and Values[1] and see if that works?
jerryvellutini
11-11-2009, 04:39 PM
I'm lost. I tried to delete the file and try over again. I get:
"This file is likely referenced by other Ninja script files and these dependencies need to be removed first."
jerryvellutini
11-11-2009, 05:16 PM
Ray,
You're right. I can't re Compile indicators that use Plot1. I get error CS1002 in the plot0 line
NinjaTrader_Bertrand
11-12-2009, 04:36 AM
Jerry, if you post the code we can take a look - have you ended the statement offending properly with a semicolon? http://www.ninjatrader-support.com/HelpGuideV6/CS1002.html
jerryvellutini
11-12-2009, 06:02 AM
How do I post it?
NinjaTrader_Bertrand
11-12-2009, 06:09 AM
Open the code in the editor and then copy the relevant parts into here and then put code tags around it, the little romb icon whe you post here...
jerryvellutini
11-12-2009, 06:56 AM
I can't find the ode tags. Get:
"The name Plot1 does not exist in the current context."
"The name Plot2 does not exist in the current context."
// 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 GVsTry3Plots : Indicator
{
#region Variables
// Wizard generated variables
// User defined variables (add any user defined variables below)
#endregion
/// <summary>
/// This method is used to configure the indicator and is called once before any bar data is loaded.
/// </summary>
protected override void Initialize()
{
Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
Add(new Plot(Color.FromKnownColor(KnownColor.White), PlotStyle.Line, "Plot1"));
Add(new Plot(Color.FromKnownColor(KnownColor.White), PlotStyle.Line, "Plot2"));
CalculateOnBarClose = true;
Overlay = false;
PriceTypeSupported = false;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Use this method for calculating your indicator values. Assign a value to each
// plot below by replacing 'Close[0]' with your own formula.
Plot0.Set(Close[0]);
Plot1.Set(Close[0]);
Plot2.Set(Close[0]);
}
#region Properties
[Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
[XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
public DataSeries Plot0
{
get { return Values[0]; }
}
[Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
[XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
public DataSeries Plot1
{
get { return Values[1]; }
}
[Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
[XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
public DataSeries Plot2
{
get { return Values[2]; }
}
#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 GVsTry3Plots[] cacheGVsTry3Plots = null;
private static GVsTry3Plots checkGVsTry3Plots = new GVsTry3Plots();
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
public GVsTry3Plots GVsTry3Plots()
{
return GVsTry3Plots(Input);
}
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
public GVsTry3Plots GVsTry3Plots(Data.IDataSeries input)
{
if (cacheGVsTry3Plots != null)
for (int idx = 0; idx < cacheGVsTry3Plots.Length; idx++)
if (cacheGVsTry3Plots[idx].EqualsInput(input))
return cacheGVsTry3Plots[idx];
GVsTry3Plots indicator = new GVsTry3Plots();
indicator.BarsRequired = BarsRequired;
indicator.CalculateOnBarClose = CalculateOnBarClose;
indicator.Input = input;
indicator.SetUp();
GVsTry3Plots[] tmp = new GVsTry3Plots[cacheGVsTry3Plots == null ? 1 : cacheGVsTry3Plots.Length + 1];
if (cacheGVsTry3Plots != null)
cacheGVsTry3Plots.CopyTo(tmp, 0);
tmp[tmp.Length - 1] = indicator;
cacheGVsTry3Plots = tmp;
Indicators.Add(indicator);
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.GVsTry3Plots GVsTry3Plots()
{
return _indicator.GVsTry3Plots(Input);
}
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
public Indicator.GVsTry3Plots GVsTry3Plots(Data.IDataSeries input)
{
return _indicator.GVsTry3Plots(input);
}
}
}
// 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.GVsTry3Plots GVsTry3Plots()
{
return _indicator.GVsTry3Plots(Input);
}
/// <summary>
/// Enter the description of your new custom indicator here
/// </summary>
/// <returns></returns>
public Indicator.GVsTry3Plots GVsTry3Plots(Data.IDataSeries input)
{
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.GVsTry3Plots(input);
}
}
}
#endregion
NinjaTrader_Bertrand
11-12-2009, 07:04 AM
Hmm and you are sure you get this error for the code you posted? Please double click on the error at the bottom to see exactly where those offending lines were found and in which script - NinjaTrader would compile all scrips all the time, so all need to be conflict free.
jerryvellutini
11-12-2009, 07:14 AM
They are in another indicator where I tried to lot straight lines:
Plot1.Set(50);
Plot2.Set(-50);
NinjaTrader_Bertrand
11-12-2009, 08:03 AM
Ok, then please ensure you have defined those Plots in the properties in the related indicator code.
jerryvellutini
11-12-2009, 08:09 AM
Not clear. I didn't do anything for Plot1.
#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;
#endregion
// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
/// <summary>
/// Plot Woodie's CCI
/// </summary>
[Description("Plot Woodie's CCI")]
public class GVsWoodiesCCI : Indicator
{
#region Variables
// Wizard generated variables
private int period = 20; // Default setting for Period
// User defined variables (add any user defined variables below)
#endregion
/// <summary>
/// This method is used to configure the indicator and is called once before any bar data is loaded.
/// </summary>
protected override void Initialize()
{
Add(new Plot(Color.FromKnownColor(KnownColor.Red), PlotStyle.Line, "Plot0"));
Plots[0].Pen.Width = 2;
Period = 20;
Add(new Plot(Color.FromKnownColor(KnownColor.White), PlotStyle.Line, "Plot1"));
Plots[1].Pen.Width = 2;
Period = 20;
Add(new Plot(Color.FromKnownColor(KnownColor.White), PlotStyle.Line, "Plot2"));
Plots[2].Pen.Width = 2;
Period = 20;
CalculateOnBarClose = true;
Overlay = true;
PriceTypeSupported = true;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Use this method for calculating your indicator values. Assign a value to each
// plot below by replacing 'Close[0]' with your own formula.
//Plot0.Set(Close[0]);
// Do not calculate if we don't have enough bars
if (CurrentBar < Period) return;
double myCCIVal = WoodiesCCI(2, 5, 14, 34, 25, 6, 60, 100, 2)[0];
Plot0.Set(myCCIVal);
Plot1.Set(50);
Plot2.Set(-50);
}
#region Properties
[Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
[XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
public DataSeries Plot0
{
get { return Values[0]; }
}
[Description("Number of periods")]
[Category("Parameters")]
public int Period
{
get { return period; }
set { period = Math.Max(1, 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 GVsWoodiesCCI[] cacheGVsWoodiesCCI = null;
private static GVsWoodiesCCI checkGVsWoodiesCCI = new GVsWoodiesCCI();
/// <summary>
/// Plot Woodie's CCI
/// </summary>
/// <returns></returns>
public GVsWoodiesCCI GVsWoodiesCCI(int period)
{
return GVsWoodiesCCI(Input, period);
}
/// <summary>
/// Plot Woodie's CCI
/// </summary>
/// <returns></returns>
public GVsWoodiesCCI GVsWoodiesCCI(Data.IDataSeries input, int period)
{
checkGVsWoodiesCCI.Period = period;
period = checkGVsWoodiesCCI.Period;
if (cacheGVsWoodiesCCI != null)
for (int idx = 0; idx < cacheGVsWoodiesCCI.Length; idx++)
if (cacheGVsWoodiesCCI[idx].Period == period && cacheGVsWoodiesCCI[idx].EqualsInput(input))
return cacheGVsWoodiesCCI[idx];
GVsWoodiesCCI indicator = new GVsWoodiesCCI();
indicator.BarsRequired = BarsRequired;
indicator.CalculateOnBarClose = CalculateOnBarClose;
indicator.Input = input;
indicator.Period = period;
indicator.SetUp();
GVsWoodiesCCI[] tmp = new GVsWoodiesCCI[cacheGVsWoodiesCCI == null ? 1 : cacheGVsWoodiesCCI.Length + 1];
if (cacheGVsWoodiesCCI != null)
cacheGVsWoodiesCCI.CopyTo(tmp, 0);
tmp[tmp.Length - 1] = indicator;
cacheGVsWoodiesCCI = tmp;
Indicators.Add(indicator);
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>
/// Plot Woodie's CCI
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.GVsWoodiesCCI GVsWoodiesCCI(int period)
{
return _indicator.GVsWoodiesCCI(Input, period);
}
/// <summary>
/// Plot Woodie's CCI
/// </summary>
/// <returns></returns>
public Indicator.GVsWoodiesCCI GVsWoodiesCCI(Data.IDataSeries input, int period)
{
return _indicator.GVsWoodiesCCI(input, period);
}
}
}
// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
public partial class Strategy : StrategyBase
{
/// <summary>
/// Plot Woodie's CCI
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.GVsWoodiesCCI GVsWoodiesCCI(int period)
{
return _indicator.GVsWoodiesCCI(Input, period);
}
/// <summary>
/// Plot Woodie's CCI
/// </summary>
/// <returns></returns>
public Indicator.GVsWoodiesCCI GVsWoodiesCCI(Data.IDataSeries input, int period)
{
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.GVsWoodiesCCI(input, period);
}
}
}
#endregion
NinjaTrader_Bertrand
11-12-2009, 08:14 AM
Jerry, you copied in the Add Plot1 and Plot2 statement, this way the indicator wizard did not generate the needed code lines in the properties section, you would need to add here -
#region Properties
[Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
[XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
public DataSeries Plot1
{
get { return Values[1]; }
}
#region Properties
[Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
[XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
public DataSeries Plot2
{
get { return Values[2]; }
}
jerryvellutini
11-12-2009, 08:39 AM
Thank You,
I don't completely understand but I learned a lot from this.
NinjaTrader_Bertrand
11-12-2009, 08:41 AM
You're welcome - this should help clarify - http://www.ninjatrader-support.com/HelpGuideV6/Add.html