Dukascopy Support Board
http://www.dukascopy.com/swiss/english/forex/jforex/forum/

Simple Indicator SMA shifted
http://www.dukascopy.com/swiss/english/forex/jforex/forum/viewtopic.php?f=200&t=51860
Page 1 of 1

Author:  Andres2012 [ Mon 10 Nov, 2014, 03:49 ]
Post subject:  Simple Indicator SMA shifted

Hello, I', just starting with jforex. When I try to make a simple SMA and print in the chart I must shift with -1 value to get adjust to native SMA. What am I doing wrong ?

public IndicatorResult calculate(int startIndex, int endIndex) {
        //calculating startIndex taking into account lookback value
        if (startIndex - getLookback() < 0) {
            startIndex -= startIndex - getLookback();
        }
        int i, j;
        for (i = startIndex, j = 0; i <= endIndex; i++, j++) {
           double value = 0;
           for (int k = timePeriod; k > 0; k--) {
              value += inputs[0][i - k];
           }
            outputs[0][j] = value/timePeriod;

        }
        return new IndicatorResult(startIndex, j);
    }


MySMA is green and native is blue.

Image

Thanks

  Page 1 of 1