Dukascopy Support Board
http://www.dukascopy.com/swiss/english/forex/jforex/forum/

showPresetDialog()
http://www.dukascopy.com/swiss/english/forex/jforex/forum/viewtopic.php?f=83&t=50423
Page 1 of 1

Author:  MobNaga [ Wed 27 Nov, 2013, 12:28 ]
Post subject:  showPresetDialog()

I want to use a method.
Something like this "int i = JFXPresetPane.showPresetDialog(JFrame, frame, IStrategy strategy);"
Image
Is such Class already exist?
regards,

Attachments:
PresetPanel.JPG [8.62 KiB]
Downloaded 475 times

Author:  API Support [ Wed 27 Nov, 2013, 12:58 ]
Post subject:  Re: showPresetDialog()

Why would you need such method?

Author:  MobNaga [ Wed 27 Nov, 2013, 14:14 ]
Post subject:  Re: showPresetDialog()

I made my own Tester for onBarMethod Strategies.
And, Now, I use that tester strategy like this way,
package jforex.strategies;

import com.dukascopy.api.*;
import com.dukascopy.api.IEngine.OrderCommand;
import com.dukascopy.api.IIndicators.AppliedPrice;

import mobnaga.hispeedtester.*;
@Library("C:\\Documents and Settings\\adm\\My Documents\\JForex\\Strategies\\files\\mobnaga.hispeedtester.jar")
public class SMASimpleStrategy extends HST_FrontTypeS {
//public class SMASimpleStrategy implements IStrategy {
    private IEngine engine;
    private IHistory history;
    private IIndicators indicators;
    private IConsole console;
    private int counter = 0;

    @Configurable("Instrument")
    public Instrument instrument = Instrument.EURUSD;
    @Configurable("Period")
    public Period selectedPeriod = Period.FIFTEEN_MINS;
    @Configurable("SMA filter")
    public Filter indicatorFilter = Filter.NO_FILTER;
    @Configurable("Amount")
    public double amount = 0.02;
    @Configurable("Stop loss")
    public int stopLossPips = 10;
    @Configurable("Take profit")
    public int takeProfitPips = 90;

    public void onStart(IContext context) throws JFException {
        if(knockOn(context, context.getFilesDir().getAbsolutePath()+"\\HSTTEST_"+hstFromTime+".csv", null) == HST_ENDED) return;
        this.engine = context.getEngine();
        this.history = context.getHistory();
        this.indicators = context.getIndicators();
        this.console = context.getConsole();
    }

    public void onAccount(IAccount account) throws JFException {
    }

    public void onMessage(IMessage message) throws JFException {
    }

    public void onStop() throws JFException {
        //close all orders
        for (IOrder order : engine.getOrders()) {
            engine.getOrder(order.getLabel()).close();
        }
    }

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

    public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
        if (!instrument.equals(instrument) || !period.equals(selectedPeriod))
            return;

        IBar prevBar = history.getBar(instrument, selectedPeriod, OfferSide.BID, 1);

        int smaTimePeriod = 50;
        int candlesBefore = 2;
        int candlesAfter = 0;

        double sma = indicators.sma(instrument, selectedPeriod, OfferSide.BID, AppliedPrice.CLOSE, smaTimePeriod, indicatorFilter,
                candlesBefore, prevBar.getTime(), candlesAfter)[0];

        // SMA crossed previous green candle
        if (prevBar.getOpen() < sma && prevBar.getClose() > sma) {
            submitOrder(OrderCommand.BUY);
        }
        // SMA crossed previous red candle
        if (prevBar.getOpen() > sma && prevBar.getClose() < sma) {
            submitOrder(OrderCommand.SELL);
        }
    }

    private IOrder submitOrder(OrderCommand orderCmd) throws JFException {

        double stopLossPrice, takeProfitPrice;

        // Calculating stop loss and take profit prices
        if (orderCmd == OrderCommand.BUY) {
            stopLossPrice = history.getLastTick(this.instrument).getBid() - getPipPrice(this.stopLossPips);
            takeProfitPrice = history.getLastTick(this.instrument).getBid() + getPipPrice(this.takeProfitPips);
        } else {
            stopLossPrice = history.getLastTick(this.instrument).getAsk() + getPipPrice(this.stopLossPips);
            takeProfitPrice = history.getLastTick(this.instrument).getAsk() - getPipPrice(this.takeProfitPips);
        }

        // Submitting an order for the specified instrument at the current market price
        return engine.submitOrder(getLabel(instrument), this.instrument, orderCmd, this.amount, 0, 20, stopLossPrice, takeProfitPrice);
    }

    protected String getLabel(Instrument instrument) {
        String label = instrument.name();
        label = label + (counter++);
        label = label.toUpperCase();
        return label;
    }

    private double getPipPrice(int pips) {
        return pips * this.instrument.getPipValue();
    }

}

PresetPanel is this,
Image

But, If I use this way,
I have to add some line to each strategy file.
If I could use preferences easily by jforex tool, Then I can choose the strategy file in flexibly.
like this..
Image

thanks,

Attachments:
PresetPanel2.JPG [30.09 KiB]
Downloaded 483 times
PresetPanel.JPG [29.96 KiB]
Downloaded 472 times

Author:  API Support [ Thu 05 Dec, 2013, 15:02 ]
Post subject:  Re: showPresetDialog()

The parameter dialog is part of the platform, if you wish to have a GUI to modify the parameters and presets from the JForex-SDK, then you need to build a dialog on your own, see example:
https://www.dukascopy.com/swiss/english/forex/jforex/forum/viewtopic.php?f=65&t=42104&p=65211#p65211

Author:  MobNaga [ Wed 11 Dec, 2013, 12:51 ]
Post subject:  Re: showPresetDialog()

Thanks, I got it...

Attachments:
MyPresetSetterTest.java [7.5 KiB]
Downloaded 258 times
MyPresetSetterTest.java [7.5 KiB]
Downloaded 263 times
MyPresetSetterTest.java [7.5 KiB]
Downloaded 259 times
MyPresetSetterTest.jfx [164.81 KiB]
Downloaded 263 times

  Page 1 of 1