Dukascopy
 
 
Wiki JStore Search Login

Attention! Read the forum rules carefully before posting a topic.

    Try to find an answer in Wiki before asking a question.
    Submit programming questions in this forum only.
    Off topics are strictly forbidden.

Any topics which do not satisfy these rules will be deleted.

indicator values don't match (customData VS JForexFeed)
 Post subject: indicator values don't match (customData VS JForexFeed) Post rating: 0   New post Posted: Thu 12 Jan, 2017, 13:41 
User avatar

User rating: 0
Joined: Mon 12 Mar, 2012, 18:23
Posts: 9
I tried to calculate indicator values on custom data as described in the Wiki. But the values do not match with the ones on the chart(same filter). Can you figure what have I done wrong? Jforex API version is v2.13.25
code output:
Quote:
12:36:10 resultArr JforexFeed: [0] 0.00246; [1] 0.00255; [2] 0.00250; [3] 0.00248; [4] 0.00241; [5] 0.00244;
12:36:10 resultArr CustomData: [0] 0.00239; [1] 0.00248; [2] 0.00243; [3] 0.00242; [4] 0.00235; [5] 0.00238;
12:36:10 look back: 14, look forward: 0


code:
package jforex;

import com.dukascopy.api.*;
import com.dukascopy.api.indicators.IIndicator;
import java.text.DecimalFormat;
import java.util.*;

public class indicatorTest implements IStrategy {
    private IEngine engine;
    private IConsole console;
    private IHistory history;
    private IContext context;
    private IIndicators indicators;
    private IUserInterface userInterface;
    public static DecimalFormat df = new DecimalFormat("0.00000");
   
    public void onStart(IContext context) throws JFException {
        this.engine = context.getEngine();
        this.console = context.getConsole();
        this.history = context.getHistory();
        this.context = context;
        this.indicators = context.getIndicators();
        this.userInterface = context.getUserInterface();
       
        atrIndicatorTest();
        context.stop();
    }
   
    void atrIndicatorTest()throws JFException{
        IIndicator atrIndicator = indicators.getIndicator("ATR");
        atrIndicator.setOptInputParameter(0, 14);

        int barsToLoad = 20;
        Instrument instrument = Instrument.EURUSD;
        Period period = Period.ONE_HOUR;
        long currentBarTime = history.getBarStart(period,history.getLastTick(instrument).getTime());
        List<IBar> bars = history.getBars(instrument,period,OfferSide.BID,Filter.WEEKENDS,barsToLoad,currentBarTime,0);
        //console.getOut().println(bars.toString());
        double [][] arr = new double[5][barsToLoad];
        for (int i = 0; i < barsToLoad; i++) {
            //open=0, close=1, high=2, low=3, volume=4
            IBar bar = bars.get(i);
            arr[0][i] = bar.getOpen();
            arr[1][i] = bar.getClose();
            arr[2][i] = bar.getHigh();
            arr[3][i] = bar.getLow();
            arr[4][i] = bar.getVolume();
        }       
        atrIndicator.setInputParameter(0, arr);
       
        //set outputs
        double [] resultArr = new double [barsToLoad-atrIndicator.getLookback()];
        atrIndicator.setOutputParameter(0, resultArr);
       
        console.getOut().format("look back: %d, look forward: %d", atrIndicator.getLookback(), atrIndicator.getLookforward()).println();

        //calculate indicator values on custon data
        atrIndicator.calculate(atrIndicator.getLookback(), barsToLoad - 1);
       
        //print results
        console.getOut().println("resultArr CustomData: " + arrayToString(resultArr));
       
        //print indicator values calculate on jforex feed
        console.getOut().println("resultArr JforexFeed: " + arrayToString(indicators.atr(instrument, period, OfferSide.BID, 14, Filter.WEEKENDS, barsToLoad-atrIndicator.getLookback(), currentBarTime, 0)));
    }


    public static String arrayToString(double[] arr) {
        String str = "";
        for (int r = 0; r < arr.length; r++) {
            str += "[" + r + "] " + df.format(arr[r]) + "; ";
        }
        return str;
    }
    public void onAccount(IAccount account) throws JFException {
    }

    public void onMessage(IMessage message) throws JFException {
    }

    public void onStop() throws JFException {
    }

    public void onTick(Instrument instrument, ITick tick) throws JFException {
    }
   
    public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
    }
}


Attachments:
indicatorTest.java [3.28 KiB]
Downloaded 77 times
DISCLAIMER: Dukascopy Bank SA's waiver of responsability - Documents, data or information available on this webpage may be posted by third parties without Dukascopy Bank SA being obliged to make any control on their content. Anyone accessing this webpage and downloading or otherwise making use of any document, data or information found on this webpage shall do it on his/her own risks without any recourse against Dukascopy Bank SA in relation thereto or for any consequences arising to him/her or any third party from the use and/or reliance on any document, data or information found on this webpage.
 
 Post subject: Re: indicator values don't match (customData VS JForexFeed) Post rating: 0   New post Posted: Tue 24 Jan, 2017, 16:05 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Please try the following:
1) open chart
2) add the desired indicator
3) run the attached strategy to compare the outputs


Attachments:
IndChartVsApi.java [16.31 KiB]
Downloaded 73 times
DISCLAIMER: Dukascopy Bank SA's waiver of responsability - Documents, data or information available on this webpage may be posted by third parties without Dukascopy Bank SA being obliged to make any control on their content. Anyone accessing this webpage and downloading or otherwise making use of any document, data or information found on this webpage shall do it on his/her own risks without any recourse against Dukascopy Bank SA in relation thereto or for any consequences arising to him/her or any third party from the use and/or reliance on any document, data or information found on this webpage.
 

Jump to:  

  © 1998-2025 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