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

Making An EMA Of An Indicator
http://www.dukascopy.com/swiss/english/forex/jforex/forum/viewtopic.php?f=65&t=57500
Page 1 of 1

Author:  Vien [ Tue 15 Dec, 2020, 12:07 ]
Post subject:  Making An EMA Of An Indicator

Hello,

In order to write an EMA of an Instrument, we write;

double ema50 = indicators.ema(myInstrument, myPeriod, myOfferSide, IIndicators.AppliedPrice.CLOSE, 50, 0);


And we can declare a Price Oscillator of an Instrument just as;

double POSC = indicators.ppo(myInstrument, myPeriod, myOfferSide, IIndicators.AppliedPrice.CLOSE, 2, 26,IIndicators.MaType.EMA, 1);


So my question here is, how can i create, let's say an EMA of 10 and 20 of the Price Oscillator Indicator in Strategy Tester?

Author:  itmurkel [ Mon 11 Jan, 2021, 21:40 ]
Post subject:  Re: Making An EMA Of An Indicator

Hello,

A small function, I hope it will help.

double[] getMaFromArray(double[] valArray, IIndicators.MaType matype, int timePeriod) {
       
        IIndicator ma;
        ma = indicators.getIndicator("ma");
       
        //inputs
        ma.setInputParameter(0, valArray); //Value Array
        ma.setOptInputParameter(0, timePeriod);//Time Period
        ma.setOptInputParameter(1, matype.ordinal()); //MA Type
       
        //outputs
        int length = valArray.length - timePeriod+1; //Calculation Length of Result
       
        double[] result = new double[length];
        ma.setOutputParameter(0,result);
        ma.calculate(0, valArray.length-1);
       
        return result;
    }

  Page 1 of 1