Since IsOverlay isn't dynamic, I am trying to develop an indicator that takes a double value in a method ("UpdatePlot") and plots the value. This way, I figure I can plot the things that I want with an Overlay using "AddPlot", and the things I want in a separate window using this indicator called "PlotValue". I come up with the following code for my indicator:
namespace NinjaTrader.NinjaScript.Indicators
{
public class PlotValue : Indicator
{
private Series<double> plotValue;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Plots the value given to it in an extra Method UpdatePlot";
Name = "PlotValue";
Calculate = Calculate.OnBarClose;
IsOverlay = false;
DisplayInDataBox = true;
DrawOnPricePanel = true;
DrawHorizontalGridLines = true;
DrawVerticalGridLines = true;
PaintPriceMarkers = true;
ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
//Disable this property if your indicator requires custom values that cumulate with each new market data event.
//See Help Guide for additional information.
IsSuspendedWhileInactive = true;
AddPlot(Brushes.Orange, "Value");
}
else if (State == State.Configure)
{
}
else if (State == State.DataLoaded)
{
plotValue = new Series<double>(this);
}
}
public void UpdatePlot(double input){
plotValue[0] = input;
}
protected override void OnBarUpdate()
{
Value[0] = plotValue[0];
}
#region Properties
[Browsable(false)]
[XmlIgnore]
public Series<double> Value
{
get { return Values[0]; }
}
#endregion
}
}
I try to test this indicator in a strategy "TestStrategy" using Close[0] as my argument input:
namespace NinjaTrader.NinjaScript.Strategies
{
public class TestStrategy : Strategy
{
private PlotValue PlotValue1;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Strategy here.";
Name = "TestStrategy";
Calculate = Calculate.OnBarClose;
EntriesPerDirection = 1;
EntryHandling = EntryHandling.AllEntries;
IsExitOnSessionCloseStrategy = true;
ExitOnSessionCloseSeconds = 30;
IsFillLimitOnTouch = false;
MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
OrderFillResolution = OrderFillResolution.Standard;
Slippage = 0;
StartBehavior = StartBehavior.WaitUntilFlat;
TimeInForce = TimeInForce.Gtc;
TraceOrders = false;
RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
StopTargetHandling = StopTargetHandling.PerEntryExecution;
BarsRequiredToTrade = 20;
// Disable this property for performance gains in Strategy Analyzer optimizations
// See the Help Guide for additional information
IsInstantiatedOnEachOptimizationIteration = true;
}
else if (State == State.Configure)
{
}
else if (State == State.DataLoaded)
{
PlotValue1 = PlotValue();
AddChartIndicator(PlotValue1);
}
}
protected override void OnBarUpdate()
{
PlotValue1.UpdatePlot(Close[0]);
}
}
}
My indicator seems to work, but only for the last couple of bars. "Earlier" I seem to get the same data, repeated cyclically.
I wonder if anyone has any clue why this might happen? What are some steps I can take to solve it? Is there a better way for me to do this?
Sincerely,
Axel



Comment