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.

multiple pairs strategy
 Post subject: multiple pairs strategy Post rating: 0   New post Posted: Sun 11 Jun, 2017, 17:23 
User avatar

User rating: 1
Joined: Tue 24 Feb, 2015, 22:29
Posts: 15
Location: Egypt, Cairo
hi everyone
I want to trade a lot of pairs at once.
for simplicity suppose they are only three GBPUSD , EURUSD , USDJPY
I want to choose the tradable pairs by a Boolean variable .see the following image

Image

my question is how to use this Boolean variable as a real filter to choose tradable pairs
consider this code
public class   multi_pairs implements IStrategy {
 @Configurable("EURUSD")
    public boolean  EURUSD = false;
    @Configurable("GBPUSD")
    public boolean  GBPUSD = true;
    @Configurable("USDJPY")
    public boolean  USDJPY = false;

    public Instrument instrument1 = Instrument.EURUSD;
    public Instrument instrument1 = Instrument.GBPUSD;
    public Instrument instrument3 = Instrument.USDJPY;
    public  Instrument[] my_instrument={instrument1, instrument2, instrument3};

  public void onStart(IContext context) throws JFException {
Set<Instrument> instruments = new HashSet<Instrument>();
     instruments.add(instrument1);
     instruments.add(instrument2);
     instruments.add(instrument3);
 context.setSubscribedInstruments(instruments);
for (int i = 0; i <  my_instrument.length; i++)
        {
         
//here comes the question how to code this : if(my_instrument[i] Boolean box is checked to be traded && other conditions)

        submitOrder(my_instrument[i],BUY,0);

        }
 

if you can also shorten my code regarding subscribing instruments and the my_instrument array it will be great


Attachments:
pairs.png [1.03 KiB]
Downloaded 297 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: multiple pairs strategy Post rating: 1   New post Posted: Wed 30 Aug, 2017, 14:46 
User avatar

User rating: 7
Joined: Thu 05 Sep, 2013, 12:43
Posts: 56
Location: Russian Federation, Tomsk
Hi brilliant,
There is universal way to solve your problem, see code below
package test;

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.IEngine;
import com.dukascopy.api.IHistory;
import com.dukascopy.api.IIndicators;
import com.dukascopy.api.IMessage;
import com.dukascopy.api.IStrategy;
import com.dukascopy.api.ITick;
import com.dukascopy.api.IUserInterface;
import com.dukascopy.api.Instrument;
import com.dukascopy.api.JFException;
import com.dukascopy.api.Period;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

public class InstrumentSet implements IStrategy {
   
    @Configurable("Instruments")
    public Set<Instrument> instruments = new HashSet<Instrument>(
            Arrays.asList(new Instrument[] {Instrument.EURUSD, Instrument.GBPUSD, Instrument.USDJPY})
    );
   
    private IEngine engine;
    private IConsole console;
    private IHistory history;
    private IContext context;
    private IIndicators indicators;
    private IUserInterface userInterface;

    @Override
    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();
       
        context.setSubscribedInstruments(instruments);
    }

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

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

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

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

    @Override
    public void onStop() throws JFException {
    }
}


Attachments:
InstrumentSet.java [2.05 KiB]
Downloaded 166 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