I am having trouble with a DataSeries Object that holds Close prices. I hope that somebody can help.
In a strategy, I Set the prices in each OnBarUpdate() . At various times I perform a While loop which adjusts and resets the most current price in the DataSeries Object. The purpose of the loop is to adjust the price until an indicator which is based on the price changes to a known value. Once that happens I then have the price at which the indicator will have the specified value in the future. I intend to use the resultant price as the trigger point for a future trade.
I can correctly extract the prices while in the strategy. The problem occurs when I call an indicator using the prices in the DataSeries Object. It appears that the indicator uses only the first price entered for the current bar and not any of the subsequent prices that replace it, so returning the same values on every call in the loop.
The following code illustrates the problem.
#region Variables
private DataSeries closePrice;
#endregion
protected override void Initialize()
{
closePrice = new DataSeries(this);
}
protected override void OnBarUpdate()
{
if (CurrentBars[0] <= BarsRequired) return;
closePrice.Set(Close[0]);
if (CurrentBar != 10) return; // Only do the test for bar 10
Print(closePrice[0].ToString("0.0000")+", EMA value = "+
EMA(closePrice,5)[0].ToString()); // Use a simple EMA as example
closePrice.Set(Close[0]+1.0); // Save and print for a different price value
Print(closePrice[0].ToString("0.0000")+", EMA value = "+
EMA(closePrice,5)[0].ToString());
}
Output file contains
1.0609, EMA value = 1.0646201198249
2.0609, EMA value = 1.0646201198249
Any suggestions would be most welcome. Thanks, John
Comment