I have a strategy which adds an additional 30min data series and my custom indicator which should consume that data series. The problem is now, that the plot of my indicator "falls" behind of chart.
Here is my simple test strategy:
public class MyTestStrategy : Strategy
{
private MyTestIndicator myTestIndicator;
private const int Secondary = 1;
protected override void OnStateChange()
{[INDENT]if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Strategy here.";
Name = "MyTestStrategy";
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;[/INDENT]
}
else if (State == State.Configure)
{[INDENT]AddDataSeries(BarsPeriodType.Minute, 30);[/INDENT]
}
else if (State == State.DataLoaded)
{
myTestIndicator = MyTestIndicator(BarsArray[Secondary]);
AddChartIndicator(myTestIndicator);
}
}
protected override void OnBarUpdate()
{
//Add your custom strategy logic here.
if (BarsInProgress == 0 && CurrentBar < BarsRequiredToPlot) return;
if(BarsInProgress == Secondary)
{
var result = myTestIndicator[0];
}
}
}
public class MyTestIndicator : Indicator
{
private SMA sma10;
private double _result = 0;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Indicator here.";
Name = "MyTestIndicator";
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, "TestPlot");
AddLine(Brushes.DarkCyan, 0.5, "Strong Buy");
AddLine(Brushes.DarkCyan, 0.1, "Buy");
AddLine(Brushes.DarkCyan, -0.1, "Sell");
AddLine(Brushes.DarkCyan, -0.5, "Strong sell");
}
else if (State == State.Configure)
{
}
else if (State == State.DataLoaded)
{
sma10 = SMA(10);
}
}
protected override void OnBarUpdate()
{
//Add your custom indicator logic here.
TestPlot[0] = _result;
if (CurrentBar < 2)
{
return;
}
var signals = new List<double>
{
GetMovingAverageSignal(sma10[0]),
};
_result = signals.Average();
}
private int GetMovingAverageSignal(double value)
{
if (value < Close[0]) return 1;
if (value > Close[0]) return -1;
return 0;
}
public override void OnCalculateMinMax()
{
MinValue = -1;
MaxValue = 1;
}
#region Properties
[Browsable(false)]
[XmlIgnore]
public Series<double> TestPlot
{
get { return Values[0]; }
}
#endregion
}
}
How could I fix this?
Thx,
Sven

Comment