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.

Problem with JForex SDK in Netbeans 8.2
 Post subject: Problem with JForex SDK in Netbeans 8.2 Post rating: 0   New post Posted: Wed 29 Mar, 2017, 07:19 

User rating: 0
Joined: Tue 26 Aug, 2014, 19:18
Posts: 23
Location: Russian Federation,
Hello Support, please help me with one question.
I try to use custom time zone for candles EET (UTC +2) but it doesn't work (tester load candles and indicator from gmt(utc) time zone), but custom time period for testing works properly. it's strange becouse one thing (time period for testing) work, the second (custom time zone) doesn't.
i use jforex-3-sdk package, netbeans 8.2
my current program "TesterMainCustomReport.java", the strategy "NewClass.java" was formed in Visual JForex and uses pivot indicator.
rows from 148 to 158 where i try to use custom timezone
package singlejartest;

import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Future;

import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.dukascopy.api.IChart;
import com.dukascopy.api.Instrument;
import com.dukascopy.api.LoadingProgressListener;
import com.dukascopy.api.OfferSide;
import com.dukascopy.api.Period;
import com.dukascopy.api.system.ISystemListener;
import com.dukascopy.api.system.ITesterClient;
import com.dukascopy.api.system.ITesterClient.DataLoadingMethod;
import com.dukascopy.api.system.TesterFactory;
import com.dukascopy.api.system.tester.ITesterExecution;
import com.dukascopy.api.system.tester.ITesterExecutionControl;
import com.dukascopy.api.system.tester.ITesterGui;
import com.dukascopy.api.system.tester.ITesterUserInterface;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;
import newpackage.NewClass;

/**
 * This small program demonstrates how to initialize Dukascopy tester and start a strategy in GUI mode
 */
@SuppressWarnings("serial")
public class TesterMainGUIMode extends JFrame implements ITesterUserInterface, ITesterExecution {
    private static final Logger LOGGER = LoggerFactory.getLogger(TesterMainGUIMode.class);

    private final int frameWidth = 1000;
    private final int frameHeight = 600;
    private final int controlPanelHeight = 40;
   
    private JPanel currentChartPanel = null;
    private ITesterExecutionControl executionControl = null;
   
    private JPanel controlPanel = null;
    private JButton startStrategyButton = null;
    private JButton pauseButton = null;
    private JButton continueButton = null;
    private JButton cancelButton = null;
   
   //url of the DEMO jnlp
    private static String jnlpUrl = "https://platform.dukascopy.com/demo/jforex.jnlp";
    //user name
    private static String userName = "UserName";
   // password
    private static String password = "Password";
   
    private Instrument instrument = Instrument.EURUSD;
   
    public TesterMainGUIMode(){
       setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));
    }
   
    @Override
    public void setChartPanels(Map<IChart, ITesterGui> chartPanels) {
        for(Map.Entry<IChart, ITesterGui> entry : chartPanels.entrySet()){
            IChart chart = entry.getKey();
            JPanel chartPanel = entry.getValue().getChartPanel();
            if(chart.getFeedDescriptor().getInstrument().equals(instrument)){
                setTitle(chart.getFeedDescriptor().toString());   
                addChartPanel(chartPanel);
                break;
            }
        }
    }

   @Override
   public void setExecutionControl(ITesterExecutionControl executionControl) {
      this.executionControl = executionControl;
   }
   
    public void startStrategy() throws Exception {
        //get the instance of the IClient interface
        final ITesterClient client = TesterFactory.getDefaultInstance();
        //set the listener that will receive system events
        client.setSystemListener(new ISystemListener() {
            @Override
            public void onStart(long processId) {
                LOGGER.info("Strategy started: " + processId);
                updateButtons();
            }

            @Override
            public void onStop(long processId) {
                LOGGER.info("Strategy stopped: " + processId);
                resetButtons();
               
                File reportFile = new File("C:\\report.html");
                try {
                    client.createReport(processId, reportFile);
                } catch (Exception e) {
                    LOGGER.error(e.getMessage(), e);
                }
                if (client.getStartedStrategies().size() == 0) {
                    //Do nothing
                }
            }

            @Override
            public void onConnect() {
                LOGGER.info("Connected");
            }

            @Override
            public void onDisconnect() {
                //tester doesn't disconnect
            }
        });

        LOGGER.info("Connecting...");
        //connect to the server using jnlp, user name and password
        //connection is needed for data downloading
        client.connect(jnlpUrl, userName, password);

        //wait for it to connect
        int i = 10; //wait max ten seconds
        while (i > 0 && !client.isConnected()) {
            Thread.sleep(1000);
            i--;
        }
        if (!client.isConnected()) {
            LOGGER.error("Failed to connect Dukascopy servers");
            System.exit(1);
        }

        // custom historical data
      String dateFromStr = "05/25/2016 00:00:00";
      String dateToStr = "05/26/2016 00:00:00";

      final SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
      dateFormat.setTimeZone(TimeZone.getTimeZone("UTC+2"));

      Date dateFrom = dateFormat.parse(dateFromStr);
      Date dateTo = dateFormat.parse(dateToStr);

      client.setDataInterval(DataLoadingMethod.ALL_TICKS, dateFrom.getTime(),
            dateTo.getTime());
       
        //set instruments that will be used in testing
        final Set<Instrument> instruments = new HashSet<>();
        instruments.add(instrument);
       
        LOGGER.info("Subscribing instruments...");
        client.setSubscribedInstruments(instruments);
        //setting initial deposit
        client.setInitialDeposit(Instrument.EURUSD.getSecondaryJFCurrency(), 50000);
        //load data
        LOGGER.info("Downloading data");
        Future<?> future = client.downloadData(null);
        //wait for downloading to complete
        future.get();
        //start the strategy
        LOGGER.info("Starting strategy");

        client.startStrategy(
          new NewClass(),
          new LoadingProgressListener() {
             @Override
             public void dataLoaded(long startTime, long endTime, long currentTime, String information) {
                LOGGER.info(information);
             }

             @Override
             public void loadingFinished(boolean allDataLoaded, long startTime, long endTime, long currentTime) {
             }

             @Override
             public boolean stopJob() {
                return false;
             }
          }, this, this
        );
        //now it's running
    }
   
   /**
    * Center a frame on the screen
    */
   private void centerFrame(){
      Toolkit tk = Toolkit.getDefaultToolkit();
       Dimension screenSize = tk.getScreenSize();
       int screenHeight = screenSize.height;
       int screenWidth = screenSize.width;
       setSize(screenWidth / 2, screenHeight / 2);
       setLocation(screenWidth / 4, screenHeight / 4);
   }
   
   /**
    * Add chart panel to the frame
    */
   private void addChartPanel(JPanel chartPanel) {
      removecurrentChartPanel();
      
      this.currentChartPanel = chartPanel;
      chartPanel.setPreferredSize(new Dimension(frameWidth, frameHeight - controlPanelHeight));
      chartPanel.setMinimumSize(new Dimension(frameWidth, 200));
      chartPanel.setMaximumSize(new Dimension(Short.MAX_VALUE, Short.MAX_VALUE));
      getContentPane().add(chartPanel);
      this.validate();
      chartPanel.repaint();
   }

   /**
    * Add buttons to start/pause/continue/cancel actions
    */
   private void addControlPanel() {
      controlPanel = new JPanel();
      FlowLayout flowLayout = new FlowLayout(FlowLayout.LEFT);
      controlPanel.setLayout(flowLayout);
      controlPanel.setPreferredSize(new Dimension(frameWidth, controlPanelHeight));
      controlPanel.setMinimumSize(new Dimension(frameWidth, controlPanelHeight));
      controlPanel.setMaximumSize(new Dimension(Short.MAX_VALUE, controlPanelHeight));

      startStrategyButton = new JButton("Start strategy");
      startStrategyButton.addActionListener(new ActionListener() {
         @Override
         public void actionPerformed(ActionEvent e) {
            startStrategyButton.setEnabled(false);
            Runnable r = new Runnable() {
               public void run() {
                  try {
                     startStrategy();
                  } catch (Exception e2) {
                     LOGGER.error(e2.getMessage(), e2);
                     e2.printStackTrace();
                     resetButtons();
                  }
               }
            };
            Thread t = new Thread(r);
            t.start();
         }
      });
      
      pauseButton = new JButton("Pause");
      pauseButton.addActionListener(new ActionListener() {
         @Override
         public void actionPerformed(ActionEvent e) {
            if(executionControl != null){
               executionControl.pauseExecution();
               updateButtons();
            }
         }
      });
      
      continueButton = new JButton("Continue");
      continueButton.addActionListener(new ActionListener() {
         @Override
         public void actionPerformed(ActionEvent e) {
            if(executionControl != null){
               executionControl.continueExecution();
               updateButtons();
            }
         }
      });
      
      cancelButton = new JButton("Cancel");
      cancelButton.addActionListener(new ActionListener() {
         @Override
         public void actionPerformed(ActionEvent e) {
            if(executionControl != null){
               executionControl.cancelExecution();
               updateButtons();
            }
         }
      });
      
      controlPanel.add(startStrategyButton);
      controlPanel.add(pauseButton);
      controlPanel.add(continueButton);
      controlPanel.add(cancelButton);
      getContentPane().add(controlPanel);
      
      pauseButton.setEnabled(false);
      continueButton.setEnabled(false);
      cancelButton.setEnabled(false);
   }

   private void updateButtons(){
      if(executionControl != null){
         startStrategyButton.setEnabled(executionControl.isExecutionCanceled());
         pauseButton.setEnabled(!executionControl.isExecutionPaused() && !executionControl.isExecutionCanceled());
         cancelButton.setEnabled(!executionControl.isExecutionCanceled());
         continueButton.setEnabled(executionControl.isExecutionPaused());
      }
   }

   private void resetButtons(){
        startStrategyButton.setEnabled(true);
        pauseButton.setEnabled(false);
        continueButton.setEnabled(false);
        cancelButton.setEnabled(false);
   }
   
    private void removecurrentChartPanel(){
      if(this.currentChartPanel != null){
         try {
            SwingUtilities.invokeAndWait(new Runnable() {
               @Override
               public void run() {
                  TesterMainGUIMode.this.getContentPane().remove(TesterMainGUIMode.this.currentChartPanel);
                  TesterMainGUIMode.this.getContentPane().repaint();
               }
            });            
         } catch (Exception e) {
            LOGGER.error(e.getMessage(), e);
         }
      }
    }

   public void showChartFrame(){
      setSize(frameWidth, frameHeight);
      centerFrame();
      addControlPanel();
      setVisible(true);
   }
   
    public static void main(String[] args) throws Exception {
       TesterMainGUIMode testerMainGUI = new TesterMainGUIMode();
       testerMainGUI.showChartFrame();
    }
}


 
 Post subject: Re: Problem with JForex SDK in Netbeans 8.2 Post rating: 0   New post Posted: Tue 04 Apr, 2017, 18:41 

User rating: 0
Joined: Tue 26 Aug, 2014, 19:18
Posts: 23
Location: Russian Federation,
Support, please, answer something


 
 Post subject: Re: Problem with JForex SDK in Netbeans 8.2 Post rating: 0   New post Posted: Fri 07 Apr, 2017, 16:28 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
This should not be done from IClient. It can be done by subscribing to custom feed in IStrategy.
Please see the strategy in the attachment.


Attachments:
Strategy.java [2.24 KiB]
Downloaded 111 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: Problem with JForex SDK in Netbeans 8.2 Post rating: 0   New post Posted: Sat 15 Apr, 2017, 18:15 

User rating: 0
Joined: Tue 26 Aug, 2014, 19:18
Posts: 23
Location: Russian Federation,
I put part of your code to the strategy but it doent work (test starts, but it open trades by UTC time zone and draw indicator by UTC).
the main problem is Pivot indicator (Daily) draws on the following sheme:
sunday from 23.00 till 01.00 EET (daily indicator draws by 3 hours)
monday from 02.00 till 01.00
...
friday 02.00 till 23.00
this is wrong.

Image
Image


Attachments:
UTC Start day.jpg [352.56 KiB]
Downloaded 444 times
EET Start day.jpg [336.17 KiB]
Downloaded 282 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: Problem with JForex SDK in Netbeans 8.2 Post rating: 0   New post Posted: Mon 01 May, 2017, 12:10 

User rating: 0
Joined: Tue 26 Aug, 2014, 19:18
Posts: 23
Location: Russian Federation,
no answer =(


 
 Post subject: Re: Problem with JForex SDK in Netbeans 8.2 Post rating: 0   New post Posted: Tue 09 May, 2017, 08:44 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Setting timezone in Chart tab will change only what time zone is shown on chart. It will not change day start time for the Pivot indicator.
To change when day starts for pivot indicator please change timezone of whole platform. That is done from Settings > Preferences > General > Platform time zone.


 
 Post subject: Re: Problem with JForex SDK in Netbeans 8.2 Post rating: 0   New post Posted: Tue 09 May, 2017, 16:43 

User rating: 0
Joined: Tue 26 Aug, 2014, 19:18
Posts: 23
Location: Russian Federation,
Yes, but it was an EXAMPLE in JForex.
I want to change timezone in IStrategy, your last answer with adding JFTimezone in method "on start" doesn't work!

in other way starting strategy in strategy tester in JForex with parametres you writed doesn't change anything.


 
 Post subject: Re: Problem with JForex SDK in Netbeans 8.2 Post rating: 0   New post Posted: Fri 26 May, 2017, 16:41 

User rating: 0
Joined: Tue 26 Aug, 2014, 19:18
Posts: 23
Location: Russian Federation,
Question is still actual


 

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