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.

Simple Strategy to BUY all USD pairs
 Post subject: Simple Strategy to BUY all USD pairs Post rating: 0   New post Posted: Mon 15 Jul, 2013, 12:46 

User rating: 0
Joined: Mon 15 Jul, 2013, 12:30
Posts: 2
Hello,

I am new to jforex platform, I have knowledge with metatrader and mq4 coding


How can I create a simple strategy for buying all USD pairs and set a total loss in account currency?

for example:

AUDUSD sell
NZDUSD sell
EURUSD sell
GBPUSD sell
USDCHF buy
USDCAD buy
USDJPY buy


 
 Post subject: Re: Simple Strategy to BUY all USD pairs Post rating: 0   New post Posted: Mon 15 Jul, 2013, 12:50 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Start here:
https://www.dukascopy.com/wiki/#Strategy_API
deval wrote:
How can I create a simple strategy for buying all USD pairs and set a total loss in account currency?
See:
https://www.dukascopy.com/wiki/#Set_Market_Order
and
https://www.dukascopy.com/wiki/#Order_Management/Position_aggregated_profit/loss


 
 Post subject: Re: Simple Strategy to BUY all USD pairs Post rating: 0   New post Posted: Mon 15 Jul, 2013, 16:14 

User rating: 0
Joined: Mon 15 Jul, 2013, 12:30
Posts: 2
thanks API support,

I tried the following code for buying all USD pairs but it gives me errors when compiling.

This is the complete strategy:

package jforex;

import java.util.*;

import com.dukascopy.api.*;

public class USDbuy implements IStrategy {
    private IEngine engine;
    private IConsole console;
    private IHistory history;
    private IContext context;
    private IIndicators indicators;
    private IUserInterface userInterface;
       
   
   
    @Configurable("Amount")
    public double amount = 0.002;
    @Configurable("Price")
    public double price = 0;
    @Configurable("Slippage")
    public double slippage = 2;
   
   
    private int counter = 0;
   
    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();
       
       
        Set<Instrument> instruments = new HashSet<Instrument>();
        instruments.add(Instrument.AUDUSD);
        instruments.add(Instrument.EURUSD);
        instruments.add(Instrument.GBPUSD);
        instruments.add(Instrument.NZDUSD);
        instruments.add(Instrument.USDCAD);
        instruments.add(Instrument.USDCHF);
        instruments.add(Instrument.USDJPY);

        context.setSubscribedInstruments(instruments);
        try {
            Thread.sleep(1000);
        } catch (InterruptedException ex) {
        }
       
        engine.submitOrder("AUDUSD", Instrument.AUDUSD, OrderCommand.SELL, amount, price, slippage);
        engine.submitOrder("EURUSD", Instrument.EURUSD, OrderCommand.SELL, amount, price, slippage);
        engine.submitOrder("GBPUSD", Instrument.GBPUSD, OrderCommand.SELL, amount, price, slippage);
        engine.submitOrder("NZDUSD", Instrument.NZDUSD, OrderCommand.SELL, amount, price, slippage);
        engine.submitOrder("USDCAD", Instrument.USDCAD, OrderCommand.BUY, amount, price, slippage);
        engine.submitOrder("USDCHF", Instrument.USDCHF, OrderCommand.BUY, amount, price, slippage);
        engine.submitOrder("USDJPY", Instrument.USDJPY, OrderCommand.BUY, amount, price, slippage);
       
        context.stop();
    }
   
   
    private String getLabel(Instrument instr) {
        String label = instr.name();
        label = label + (counter++);
        label = label.toUpperCase();
        return label;
    }

    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 {
    }
}


the problem seems to be in the following piece of code:

        engine.submitOrder("AUDUSD", Instrument.AUDUSD, OrderCommand.SELL, amount, price, slippage);
        engine.submitOrder("EURUSD", Instrument.EURUSD, OrderCommand.SELL, amount, price, slippage);
        engine.submitOrder("GBPUSD", Instrument.GBPUSD, OrderCommand.SELL, amount, price, slippage);
        engine.submitOrder("NZDUSD", Instrument.NZDUSD, OrderCommand.SELL, amount, price, slippage);
        engine.submitOrder("USDCAD", Instrument.USDCAD, OrderCommand.BUY, amount, price, slippage);
        engine.submitOrder("USDCHF", Instrument.USDCHF, OrderCommand.BUY, amount, price, slippage);
        engine.submitOrder("USDJPY", Instrument.USDJPY, OrderCommand.BUY, amount, price, slippage);


 
 Post subject: Re: Simple Strategy to BUY all USD pairs Post rating: 0   New post Posted: Tue 16 Jul, 2013, 07:20 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
You can avoid compile-time errors by using an IDE like Eclipse or NetBeans.


 

Jump to:  

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