Dukascopy
 
 
Wiki JStore Search Login

VJF:How can I use getDownloadableStrategies()?
 Post subject: VJF:How can I use getDownloadableStrategies()? Post rating: 0   New post Posted: Mon 01 Jul, 2013, 13:30 
User avatar

User rating: 7
Joined: Tue 28 Feb, 2012, 09:45
Posts: 45
Location: JapanJapan
Dear support team,
I can't use a IDownloadableStrategy.ComponentType.BLOCK_OWN_STRATEGY.
How can I?
Thanks.

sample code(Line 86 has a problem):
package com.dukascopy.visualforex.MobNaga;

import java.util.*;
import com.dukascopy.api.*;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.concurrent.CopyOnWriteArrayList;
import java.lang.reflect.*;
import java.math.BigDecimal;


/*
 * Created by VisualJForex Generator, version 1.21
 * Date: 01.07.2013 12:06
 */
public class SimpleBB_Counter02 implements IStrategy {

    private CopyOnWriteArrayList<TradeEventAction> tradeEventActions = new CopyOnWriteArrayList<TradeEventAction>();
    private static final String DATE_FORMAT_NOW = "yyyyMMdd_HHmmss";
    private IEngine engine;
    private IConsole console;
    private IHistory history;
    private IContext context;
    private IIndicators indicators;
    private IUserInterface userInterface;

    @Configurable("defaultSlippage:")
    public int defaultSlippage = 5;
    @Configurable("defaultTakeProfit:")
    public int defaultTakeProfit = 50;
    @Configurable("defaultTradeAmount:")
    public double defaultTradeAmount = 0.0010;
    @Configurable("defaultPeriod:")
    public Period defaultPeriod = Period.TEN_MINS;
    @Configurable("defaultStopLoss:")
    public int defaultStopLoss = 25;
    @Configurable("defaultInstrument:")
    public Instrument defaultInstrument = Instrument.EURUSD;
    List<ISignal> listSignals10 = new ArrayList<ISignal>();
    IDownloadableStrategy strategy10 = null;

    private double UseofLeverage;
    private String AccountCurrency = "";
    private List<IOrder> PendingPositions =  null ;
    private double Leverage;
    private List<IOrder> AllPositions =  null ;
    private Candle LastAskCandle =  null ;
    private int MarginCutLevel;
    private int OverWeekendEndLeverage;
    private Tick LastTick =  null ;
    private boolean GlobalAccount;
    private List<IOrder> OpenPositions =  null ;
    private IMessage LastTradeEvent =  null ;
    private Candle LastBidCandle =  null ;
    private String AccountId = "";
    private double Equity;


    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();

        subscriptionInstrumentCheck(defaultInstrument);

        ITick lastITick = context.getHistory().getLastTick(defaultInstrument);
        LastTick = new Tick(lastITick, defaultInstrument);

        IBar bidBar = context.getHistory().getBar(defaultInstrument, Period.ONE_MIN, OfferSide.BID, 1);
        IBar askBar = context.getHistory().getBar(defaultInstrument, Period.ONE_MIN, OfferSide.ASK, 1);
        LastAskCandle = new Candle(askBar, Period.ONE_MIN, defaultInstrument, OfferSide.ASK);
        LastBidCandle = new Candle(bidBar, Period.ONE_MIN, defaultInstrument, OfferSide.BID);

        HashMap<String, Object> map10 = new HashMap<String, Object>();
        map10.put("defaultSlippage", 5);
        map10.put("defaultTakeProfit", 10);
        map10.put("fastPeriod", 9);
        map10.put("slowPeriod", 26);
        map10.put("defaultPeriod", Period.ONE_HOUR);
        map10.put("defaultTradeAmount", 4.0);
        map10.put("defaultStopLoss", 100);
        map10.put("defaultInstrument", Instrument.EURUSD);
        strategy10 = context.getDownloadableStrategies().init("721","SimpleBB_Counter", context, IDownloadableStrategy.ComponentType.BLOCK_OWN_STRATEGY, IEngine.StrategyMode.INDEPENDENT, map10);
        subscriptionInstrumentCheck(Instrument.fromString("EUR/USD"));

        subscriptionInstrumentCheck(Instrument.fromString("EUR/USD"));

    }

    public void onAccount(IAccount account) throws JFException {
        AccountCurrency = account.getCurrency().toString();
        Leverage = account.getLeverage();
        AccountId= account.getAccountId();
        Equity = account.getEquity();
        UseofLeverage = account.getUseOfLeverage();
        OverWeekendEndLeverage = account.getOverWeekEndLeverage();
        MarginCutLevel = account.getMarginCutLevel();
        GlobalAccount = account.isGlobal();
    }

    private void updateVariables() {
        try {
            AllPositions = engine.getOrders(defaultInstrument);
            List<IOrder> listMarket = new ArrayList<IOrder>();
            for (IOrder order: AllPositions) {
                if (order.getState().equals(IOrder.State.FILLED)){
                    listMarket.add(order);
                }
            }
            List<IOrder> listPending = new ArrayList<IOrder>();
            for (IOrder order: AllPositions) {
                if (order.getState().equals(IOrder.State.OPENED)){
                    listPending.add(order);
                }
            }
            OpenPositions = listMarket;
            PendingPositions = listPending;
        } catch(JFException e) {
            e.printStackTrace();
        }
    }

    public void onMessage(IMessage message) throws JFException {
        if (message.getOrder() != null && message.getOrder().getInstrument().equals(defaultInstrument)) {
            updateVariables();
            LastTradeEvent = message;
            for (TradeEventAction event :  tradeEventActions) {
                IOrder order = message.getOrder();
                if (order != null && event != null && message.getType().equals(event.getMessageType())&& order.getLabel().equals(event.getPositionLabel())) {
                    Method method;
                    try {
                        method = this.getClass().getDeclaredMethod(event.getNextBlockId(), Integer.class);
                        method.invoke(this, new Integer[] {event.getFlowId()});
                    } catch (SecurityException e) {
                            e.printStackTrace();
                    } catch (NoSuchMethodException e) {
                          e.printStackTrace();
                    } catch (IllegalArgumentException e) {
                        e.printStackTrace();
                    } catch (IllegalAccessException e) {
                        e.printStackTrace();
                    } catch (InvocationTargetException e) {
                        e.printStackTrace();
                    }
                    tradeEventActions.remove(event);
                }
            }   
        }
    }

    public void onStop() throws JFException {
    }

    public void onTick(Instrument instrument, ITick tick) throws JFException {
        if (instrument.equals(defaultInstrument)) {
            LastTick = new Tick(tick, defaultInstrument);
            updateVariables();

        }
    }

    public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
     if (instrument.equals(defaultInstrument)) {
            LastAskCandle = new Candle(askBar, period, instrument, OfferSide.ASK);
            LastBidCandle = new Candle(bidBar, period, instrument, OfferSide.BID);
            updateVariables();
            SimpleBB_Counter_block_10(1);
        }
    }

    public void subscriptionInstrumentCheck(Instrument instrument) {
        try {
              if (!context.getSubscribedInstruments().contains(instrument)) {
                  Set<Instrument> instruments = new HashSet<Instrument>();
                  instruments.add(instrument);
                  context.setSubscribedInstruments(instruments, true);
                  Thread.sleep(100);
              }
          } catch (InterruptedException e) {
              e.printStackTrace();
          }
        }

    public double round(double price, Instrument instrument) {
        BigDecimal big = new BigDecimal("" + price);
        big = big.setScale(instrument.getPipScale() + 1, BigDecimal.ROUND_HALF_UP);
        return big.doubleValue();
    }

    public ITick getLastTick(Instrument instrument) {
        try {
            return (context.getHistory().getTick(instrument, 0));
        } catch (JFException e) {
             e.printStackTrace(); 
         }
         return null;
    }

    private  void SimpleBB_Counter_block_10(Integer flow) {
        try {
            List<ISignal> signals10 = null;
            switch (flow) {
                case 0:
                    signals10 = strategy10.onTick(defaultInstrument, LastTick.getTick());
                    break;
                case 1:
                    signals10 = strategy10.onBar(defaultInstrument, LastAskCandle.getPeriod(), LastAskCandle.getBar(), LastBidCandle.getBar());
                    break;
                case 2:
                    signals10 = strategy10.onMessage(LastTradeEvent);
                    break;
                default:
                    signals10 = strategy10.onTick(defaultInstrument, LastTick.getTick());
                    break;
            }
        } catch (JFException e) {
            e.printStackTrace();
        }
    }

class Candle  {

    IBar bar;
    Period period;
    Instrument instrument;
    OfferSide offerSide;

    public Candle(IBar bar, Period period, Instrument instrument, OfferSide offerSide) {
        this.bar = bar;
        this.period = period;
        this.instrument = instrument;
        this.offerSide = offerSide;
    }

    public Period getPeriod() {
        return period;
    }

    public void setPeriod(Period period) {
        this.period = period;
    }

    public Instrument getInstrument() {
        return instrument;
    }

    public void setInstrument(Instrument instrument) {
        this.instrument = instrument;
    }

    public OfferSide getOfferSide() {
        return offerSide;
    }

    public void setOfferSide(OfferSide offerSide) {
        this.offerSide = offerSide;
    }

    public IBar getBar() {
        return bar;
    }

    public void setBar(IBar bar) {
        this.bar = bar;
    }

    public long getTime() {
        return bar.getTime();
    }

    public double getOpen() {
        return bar.getOpen();
    }

    public double getClose() {
        return bar.getClose();
    }

    public double getLow() {
        return bar.getLow();
    }

    public double getHigh() {
        return bar.getHigh();
    }

    public double getVolume() {
        return bar.getVolume();
    }
}
class Tick {

    private ITick tick;
    private Instrument instrument;

    public Tick(ITick tick, Instrument instrument){
        this.instrument = instrument;
        this.tick = tick;
    }

    public Instrument getInstrument(){
       return  instrument;
    }

    public double getAsk(){
       return  tick.getAsk();
    }

    public double getBid(){
       return  tick.getBid();
    }

    public double getAskVolume(){
       return  tick.getAskVolume();
    }

    public double getBidVolume(){
        return tick.getBidVolume();
    }

   public long getTime(){
       return  tick.getTime();
    }

   public ITick getTick(){
       return  tick;
    }
}

public class AssertException extends RuntimeException {

    public AssertException(Object primary, Object compared) {
        super("Primary object : " + primary.toString() + " is different from " + compared.toString());
    }
}
    protected String getLabel() {
        String label;
        label = "IVF" + getCurrentTime(LastTick.getTime()) + generateRandom(10000) + generateRandom(10000);
        return label;
    }

    private String getCurrentTime(long time) {
        SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW);
        return sdf.format(time);
    }

    private static String generateRandom(int n) {
        int randomNumber = (int) (Math.random() * n);
        String answer = "" + randomNumber;
        if (answer.length() > 3) {
            answer = answer.substring(0, 4);
        }
        return answer;
    }

    class TradeEventAction {
        private IMessage.Type messageType;
        private String nextBlockId = "";
        private String positionLabel = "";
        private int flowId = 0;

        public IMessage.Type getMessageType() {
            return messageType;
        }

        public void setMessageType(IMessage.Type messageType) {
            this.messageType = messageType;
        }

        public String getNextBlockId() {
            return nextBlockId;
        }

        public void setNextBlockId(String nextBlockId) {
            this.nextBlockId = nextBlockId;
        }
        public String getPositionLabel() {
            return positionLabel;
       }

        public void setPositionLabel(String positionLabel) {
            this.positionLabel = positionLabel;
        }
        public int getFlowId() {
            return flowId;
        }
        public void setFlowId(int flowId) {
            this.flowId = flowId;
        }
    }
}


Attachments:
File comment: error sample
SimpleBB_Counter02.java [12.43 KiB]
Downloaded 236 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: VJF:How can I use getDownloadableStrategies()? Post rating: 1   New post Posted: Tue 02 Jul, 2013, 09:06 
Visual JForex expert at Dukascopy
User avatar

User rating:
Joined: Mon 22 Apr, 2013, 11:30
Posts: 604
Location: UkraineUkraine
Hello.

I think you have to ask this in other part of forum:
viewforum.php?f=65


 
 Post subject: Re: VJF:How can I use getDownloadableStrategies()? Post rating: 0   New post Posted: Tue 02 Jul, 2013, 11:10 
User avatar

User rating: 7
Joined: Tue 28 Feb, 2012, 09:45
Posts: 45
Location: JapanJapan
Hi, vadim_berezhnoj.
thanks for your advices.
OK, I give up the VJF.
And I Return to Eclipse...


Attachments:
File comment: VJF is too difficult than normal text editor....
SimpleBB_Counter.vfs [41.16 KiB]
Downloaded 254 times
File comment: This can't run. I don't know Why....
SimpleBB_Counters.vfs [26.9 KiB]
Downloaded 252 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: VJF:How can I use getDownloadableStrategies()? Post rating: 0   New post Posted: Tue 02 Jul, 2013, 16:48 
Visual JForex expert at Dukascopy
User avatar

User rating: 4
Joined: Fri 06 Feb, 2009, 16:34
Posts: 130
MobNaga wrote:
Dear support team,
I can't use a IDownloadableStrategy.ComponentType.BLOCK_OWN_STRATEGY.
How can I?
Thanks.

Hello MobNaga,
You can use the IDownloadableStrategy interface, but you need to set the correct ID.
Can you be more specific and describe the problem which you have with IDownloadableStrategy?
It compiles successfully, we can't check it in runtime due that we havent access to your own strategy.


 
 Post subject: Re: VJF:How can I use getDownloadableStrategies()? Post rating: 0   New post Posted: Wed 03 Jul, 2013, 12:17 
User avatar

User rating: 7
Joined: Tue 28 Feb, 2012, 09:45
Posts: 45
Location: JapanJapan
Quote:
Hello MobNaga,
You can use the IDownloadableStrategy interface, but you need to set the correct ID.
Can you be more specific and describe the problem which you have with IDownloadableStrategy?
It compiles successfully, we can't check it in runtime due that we havent access to your own strategy.


Hello Visual Support, How do you do?
I started a SimpleBB_Counters.vfs on Strategy-Contest in this month.
But, I can't....
This is error messages on Strategy-Log.
INFO
01.07.2013 01:02:19   Strategy is terminated by Failed to connect because of authorization failure, most likely strategy is already stopped
INFO
01.07.2013 01:02:10   Strategy "SimpleBB_Counters" is stopped at 2013-07-01 01:02:10.913 GMT on the remote server with parameters "defaultSlippage:"=[5], "defaultTakeProfit:"=[10], "fastPeriod:"=[9], "slowPeriod:"=[26], "subInstrument1:"=[USD/JPY], "subInstrument2:"=[GBP/USD], "subInstrument3:"=[AUD/USD], "defaultPeriod:"=[15 Mins], "defaultTradeAmount:"=[4.0], "defaultStopLoss:"=[100], "defaultInstrument:"=[EUR/USD]. Reason: Stopped by Engine
INFO
01.07.2013 01:02:10   Strategy is terminated by Strategy stopped itself
INFO
01.07.2013 01:02:10   Stopping "SimpleBB_Counters" strategy at 2013-07-01 01:02:10.396 GMT on the remote server
ERROR
01.07.2013 01:02:10   java.security.PrivilegedActionException: com.dukascopy.api.JFException: No response from server @ com.dukascopy.visualforex.MobNaga.SimpleBB_Counters.onStart(SimpleBB_Counters.java:106)
ERROR
01.07.2013 01:02:10    ... 14 more
ERROR
01.07.2013 01:02:10    at com.dukascopy.api.impl.util.CompiledComponentDownloader.downloadFile(CompiledComponentDownloader.java:28)
ERROR
01.07.2013 01:02:10    at com.dukascopy.api.impl.util.AbstractComponentDownloader.readComponentAsByteFromServer(AbstractComponentDownloader.java:104)
ERROR
01.07.2013 01:02:10    at com.dukascopy.api.impl.util.AbstractComponentDownloader.checkResponseCode(AbstractComponentDownloader.java:64)
ERROR
01.07.2013 01:02:10   Caused by: com.dukascopy.api.JFException: No response from server
ERROR
01.07.2013 01:02:10    ... 12 more
ERROR
01.07.2013 01:02:10    at java.security.AccessController.doPrivileged(Native Method)
ERROR
01.07.2013 01:02:10   Caused by: java.security.PrivilegedActionException: com.dukascopy.api.JFException: No response from server
ERROR
01.07.2013 01:02:10    at java.lang.Thread.run(Thread.java:619)
ERROR
01.07.2013 01:02:10    at com.dukascopy.api.impl.execution.ScienceThreadPoolExecutor$Worker.run(ScienceThreadPoolExecutor.java:926)
ERROR
01.07.2013 01:02:10    at com.dukascopy.api.impl.execution.ScienceThreadPoolExecutor$Worker.runTask(ScienceThreadPoolExecutor.java:904)
ERROR
01.07.2013 01:02:10    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
ERROR
01.07.2013 01:02:10    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
ERROR
01.07.2013 01:02:10    at com.dukascopy.api.impl.execution.TaskCustom.call(TaskCustom.java:34)
ERROR
01.07.2013 01:02:10    at com.dukascopy.api.impl.connect.JForexTaskManager$1.call(JForexTaskManager.java:569)
ERROR
01.07.2013 01:02:10    at com.dukascopy.api.impl.connect.JForexTaskManager$1.call(JForexTaskManager.java:605)
ERROR
01.07.2013 01:02:10    at com.dukascopy.api.impl.connect.StrategyProcessor.onStart(StrategyProcessor.java:147)
ERROR
01.07.2013 01:02:10    at com.dukascopy.api.impl.execution.TaskStart.call(TaskStart.java:27)
ERROR
01.07.2013 01:02:10    at com.dukascopy.visualforex.MobNaga.SimpleBB_Counters.onStart(SimpleBB_Counters.java:106)
ERROR
01.07.2013 01:02:10    at com.dukascopy.api.impl.DownloadableStrategies.init(DownloadableStrategies.java:18)
ERROR
01.07.2013 01:02:10    at com.dukascopy.api.impl.DownloadableStrategy.start(DownloadableStrategy.java:134)
ERROR
01.07.2013 01:02:10   java.lang.RuntimeException: java.security.PrivilegedActionException: com.dukascopy.api.JFException: No response from server
ERROR
01.07.2013 01:02:10   java.security.PrivilegedActionException: com.dukascopy.api.JFException: No response from server:
ERROR
01.07.2013 01:02:10   java.security.PrivilegedActionException: com.dukascopy.api.JFException: No response from server @ com.dukascopy.visualforex.MobNaga.SimpleBB_Counters.onStart(SimpleBB_Counters.java:106)
INFO
01.07.2013 01:02:05   Strategy "SimpleBB_Counters" Strategy ID: is started at 2013-07-01 01:02:05.018 GMT on the remote server with parameters "defaultSlippage:"=[5], "defaultTakeProfit:"=[10], "fastPeriod:"=[9], "slowPeriod:"=[26], "subInstrument1:"=[USD/JPY], "subInstrument2:"=[GBP/USD], "subInstrument3:"=[AUD/USD], "defaultPeriod:"=[15 Mins], "defaultTradeAmount:"=[4.0], "defaultStopLoss:"=[100], "defaultInstrument:"=[EUR/USD]


P.S. I already solved it with a wrong way.
Thanks.


Attachments:
File comment: This is my easy Solution
SimpleBB_Counter03.vfs [69.16 KiB]
Downloaded 250 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:  

cron
  © 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