Dukascopy
 
 
Wiki JStore Search Login

Simple Indicator SMA shifted
 Post subject: Simple Indicator SMA shifted Post rating: 0   New post Posted: Mon 10 Nov, 2014, 03:49 
User avatar

User rating: 0
Joined: Mon 10 Nov, 2014, 03:23
Posts: 7
Location: Spain, Madrid
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


 

Jump to:  

  © 1998-2024 Dukascopy® Bank SA
On-line Currency forex trading with Swiss Forex Broker - ECN Forex Brokerage,
Managed Forex Accounts, introducing forex brokers, Currency Forex Data Feed and News
Currency Forex Trading Platform provided on-line by Dukascopy.com