I am using an AddDataSeries, but I am filtering out events that don't match what is on the chart.
I am using the Playback
Here are my results printed in the output window
Ind High: 2687.25 // Correct
Ind Value: 2687.12467370361 // Correct
Inst: ES 03-19 Globex // Correct
Str BarCount: 330 // Correct
Str High: 2687.25 // Correct
Str aaEMAHigh0: 2686.52547760308 //WRONG, should be 2687.12467370361
The Indicator (Ind) is displaying the correct values.
This is the High of the current bar being passed in to the indicator and these values are being displayed from the indicator
NinjaTrader.Code.Output.Process("Ind High: " + Input[0].ToString(), PrintTo.OutputTab1);
The indicator value is correct when being displayed from the indictor into the Output window. The value also correctly shows on the chart:
NinjaTrader.Code.Output.Process("Ind Value: " + dsEMA[0].ToString(), PrintTo.OutputTab1);
In the Strategy, High or the current bar is correct and matches the value from the indicator.
But the Strategy Value of the EMA is incorrect.
Code:
Indicator:
OnBarUpdate (set to Calculate.OnEachTick)
if (BarsInProgress == 1 ) return; // Using this to make sure I'm not having any conflicts.
Values[0][0] = (CurrentBar == 0 ? Input[0] : Input[0] * (2.0 / (1 + Period)) + (1 - (2.0 / (1 + Period))) * Values[0][1]);
dsEMA[0] = (CurrentBar == 0 ? Input[0] : Input[0] * (2.0 / (1 + Period)) + (1 - (2.0 / (1 + Period))) * dsEMA[1]);
NinjaTrader.Code.Output.Process("Ind High: " + Input[0].ToString(), PrintTo.OutputTab1);
NinjaTrader.Code.Output.Process("Ind Value: " + dsEMA[0].ToString(), PrintTo.OutputTab1);
[Browsable(false)]
[XmlIgnore()]
public Series<double> EMAValue
{
get { return dsEMA; }
}
Strategy Code
Set to Calculate.OnBarClose // I have tried to set this to OnEachTick and move the code into OnBarUpdate, but it still doesn't work
protected override void OnMarketData(MarketDataEventArgs e)
{
if(e.MarketDataType != MarketDataType.Last) {return;}
if (e.Instrument.ToString().StartsWith("ES") ) {} else {return;} // Just making sure I'm using the ES values.
NinjaTrader.Code.Output.Process("Inst: " + e.Instrument.ToString(), PrintTo.OutputTab1);
// High[0] doesn't work, it shows the last bars
try
{
if (e.Last > currentBarsHigh[0]) { currentBarsHigh[0] = e.Last; }
}
catch { currentBarsHigh[0] = e.Last; }
try
{
if (e.Last < currentBarsLow[0]) { currentBarsLow[0] = e.Last; }
}
catch { currentBarsLow[0] = e.Last; }
NinjaTrader.Code.Output.Process("Str BarCount: " + iBar.ToString(), PrintTo.OutputTab1);
NinjaTrader.Code.Output.Process("Str High: " + currentBarsHigh[0].ToString(), PrintTo.OutputTab1);
WHY DOESN'T THIS WORK!
NinjaTrader.Code.Output.Process("Str aaEMAHigh0: " + aaEMA3(currentBarsHigh, 3).EMAValue[0].ToString(), PrintTo.OutputTab1);
Any help would be greatly appreciate.
Comment