Hello,
I am new here and maybe my questions is stupid but I have not founded the answer and would like to ask community.
I am trying to use SMA and would like to get predictable result.
The values of the SMA in code are different from the visual graph. Maybe I use SMA in code not right. Please help me with it. I would like to get the same result from code and from visual graph. Also I tryed to implement it by myself.
public Instrument instrument = Instrument.EURUSD;
public Period selectedPeriod = Period.FOUR_HOURS;
//....
//-------- 1 use standart implementation
IBar prevBar = history.getBar(instrument, selectedPeriod, OfferSide.BID, 1);
double sma = indicators.sma(instrument, selectedPeriod, OfferSide.BID, AppliedPrice.CLOSE, 15, indicatorFilter, 1, prevBar.getTime(), 0)[1];
//....
//-------- 2 use own implementation
Double smaOpen = 0.0;
Double smaClose = 0.0;
for(int i = 1; i <= 15; i++ ){
IBar bar = history.getBar(instrument, selectedPeriod, OfferSide.BID, i);
smaOpen += bar.getOpen();
smaClose += bar.getClose();
}
smaOpen = smaOpen / 15;
smaClose = smaClose / 15;
console.getOut().println("SMA = " + smaClose);
Could me explain where is my error? Thank you in advance