I am developing EMA predictor. I need to obtain value of EMA 34 (204) when I change Close[0] by 1 tick, 2 ticks, 3 ticks.....30ticks
I have this code:
DataSeries data = new DataSeries(this);
.
.
.
// **** fill dataseries *****
for(int i = 204; i >= 0; i--){
data.Set(i + 1, Close); // position 0 is now not filled
}
data.Set(0, 0) // fill data[0] by some default value
.
.
.
// *** count EMA values ******
for(int i = 0; i <= 30; i++){
double value = Close[0] - i*TickSize;
data.Set(0, value);
Print("Data[0] value = " + data[0]);
Print("EMA value = " + Math.Round(EMA(data, 34)[0], 2));
Print("");
}
The result is:
Data[0] value = 1598
EMA value = 1596.53
Data[0] value = 1597.75
EMA value = 1596.53
.
.
.
Data[0] value = 1590.75
EMA value = 1596.53
Data[0] value = 1590.5
EMA value = 1596.53
The problem is that if I changed last value in dataseries, EMA(data, 34)[0] is not recalculated. It seems that result is somewhere cached from the first calculation (the result from the first calculate is correct)
I have found one possibility when it is working well:
for(int i = 0; i <= 30; i++){
data = new DataSeries(this);
// fill dataseries again
for(int i = 204; i >= 0; i--){
data.Set(i + 1, Close ); // position 0 is now not filled
}
data.Set(0, 0) // fill data[0] by some default value
.
.
.
}
In this case results are correct. But it is unacceptable because of long duration of operation - it is counted for every bar in the chart.....
So how to resolve this problem?
Thank you
maitreja
Comment