Write in Excel (DDE)

A strategy updates Excel. Once the bar is completed, you will get a new line in your sheet. You can adjust the strategy according to your needs and update any cells in your Excel files.

Pretty Tools JDDE 2.1.0

Steps to run the strategy:

  1. Put the jar file in the folder "JForex\Strategies\files"
  2. Put the dll file in the system32 folder
  3. Keep Excel opened

Notice: if you stop the strategy, you need to restart the platform to ensure dll file is loaded accordingly.

package com.dukascopy;

import com.dukascopy.api.*;
import com.dukascopy.api.Configurable;
import com.dukascopy.api.IAccount;
import com.dukascopy.api.IBar;
import com.dukascopy.api.IConsole;
import com.dukascopy.api.IContext;
import com.dukascopy.api.IMessage;
import com.dukascopy.api.IStrategy;
import com.dukascopy.api.ITick;
import com.dukascopy.api.Instrument;
import com.dukascopy.api.JFException;
import com.dukascopy.api.Period;
import com.pretty_tools.dde.client.DDEClientConversation;
import com.pretty_tools.dde.DDEException;

@Library("pretty-tools-JDDE-2.1.0.jar")

@RequiresFullAccess
public class UpdateExcel implements IStrategy {

    @Configurable("CCY")
    public Instrument insturment = Instrument.EURUSD;

    @Configurable("Period")
    public Period period = Period.TEN_SECS;

    @Configurable("Select the starting row")
    public int row = 1;
    @Configurable("Select the starting column")
    public int column = 1;
    @Configurable("Type sheet name")
    public String  sheetName = "Sheet1";

    private DDEClientConversation conversation; 
    private IConsole console;
    private int counter;

    @Override
    public void onStart(IContext context) throws JFException {

        conversation = new DDEClientConversation(); 
        console = context.getConsole();
        counter = 0;

        try {
            conversation.connect("Excel", sheetName);

        } catch (DDEException e) {
            print(e.toString());
        }

    }

    public synchronized void onBar(Instrument instrument, Period period, IBar askBar,
            IBar bidBar) throws JFException {

        if (instrument == this.insturment && period == this.period) {

            try {
                conversation.poke(getCell(0),String.valueOf(bidBar.getOpen()));
                conversation.poke(getCell(1),String.valueOf(bidBar.getHigh()));
                conversation.poke(getCell(2),String.valueOf(bidBar.getLow()));
                conversation.poke(getCell(3),String.valueOf(bidBar.getClose()));
                conversation.poke(getCell(4),String.valueOf(bidBar.getVolume()));
                conversation.poke(getCell(5),String.valueOf(bidBar.getTime()));

            } catch (DDEException e) {

                print(e.toString());
            }                    

            counter++;

        }

    }

    @Override
    public void onTick(Instrument instrument, ITick tick) throws JFException {

    }

    @Override
    public void onAccount(IAccount account) throws JFException {

    }

    @Override
    public void onMessage(IMessage message) throws JFException {

    }

    @Override
    public void onStop() throws JFException {

    }

    public void print(String str) {

        console.getOut().println(str);

    }

    public String getCell(int num) {

        String str = "R" +(row+counter) + "C" + (column+num);

        return str;
    }
}

UpdateExcel.java

The information on this web site is provided only as general information, which may be incomplete or outdated. Click here for full disclaimer.