将事件监听器添加到 MotiveWave UI

时间:2021-03-10 05:22:06

标签: java event-handling algorithmic-trading

我正在使用 MotiveWave 和自定义研究外观:

public class MyCustomStudy extends Study implements EventListener {

    private final static Logger LOGGER = Logger.getLogger(MyCustomStudy.class.getName());

    enum Values {
        M
    }

    enum Oscillators {

        MOMENTUM("Momentum"),

        RATE_OF_CHAANGE("Rate Of Change"),

        RSI("Relative Strength Index");

        String name;

        Oscillators(String name) {
            this.name = name;
        }

        public String getName() {
            return name;
        }
    }

    @Override
    public void initialize(Defaults defaults) {

        var sd = createSD();
        var oscillators = sd.addTab(get("Oscillators"));

        var osInputs = oscillators.addGroup(get("Oscillators"));
        Object[] oscillatorTypes = new Object[Oscillators.values().length];

        int index = 0;

        for (Oscillators os : Oscillators.values()) {

            oscillatorTypes[index++] = os.getName();
        }

        osInputs.addRow(new InputDescriptor(Inputs.INPUT, "Category", oscillatorTypes, Oscillators.RATE_OF_CHAANGE));
//        LOGGER.info("\nThe message is = " + Oscillators.values()[0].getName() + "\n");

        var tab = sd.addTab(get("TAB_GENERAL"));

        var inputs = tab.addGroup(get("LBL_INPUTS"));
        inputs.addRow(new InputDescriptor(Inputs.INPUT, get("LBL_INPUT"), Enums.BarInput.values(), Enums.BarInput.CLOSE));
        inputs.addRow(new IntegerDescriptor(Inputs.PERIOD, get("LBL_PERIOD"), 14, 1, 9999, 1));

        var lines = tab.addGroup(get("LBL_COLORS"));
        lines.addRow(new PathDescriptor(Inputs.PATH, get("LBL_LINE"), defaults.getLineColor(), 1.0f, null));
        lines.addRow(new IndicatorDescriptor(Inputs.IND, get("LBL_INDICATOR"), null, null, false, true, true));

//         Quick Settings (Tool Bar and Popup Editor)
        sd.addQuickSettings(Inputs.INPUT);
        sd.addQuickSettings(new SliderDescriptor(Inputs.PERIOD, get("LBL_PERIOD"), 14, 1, 9999, true, Enums.Icon.SINE_WAVE::get));
        sd.addQuickSettings(Inputs.PATH);

        var desc = createRD();
        desc.setLabelSettings(Inputs.INPUT, Inputs.PERIOD);
        desc.exportValue(new ValueDescriptor(Momentum.Values.M, get("LBL_MOMENTUM"), new String[]{Inputs.INPUT, Inputs.PERIOD}));
        desc.declarePath(Momentum.Values.M, Inputs.PATH);
        desc.declareIndicator(Momentum.Values.M, Inputs.IND);
        desc.setRangeKeys(Momentum.Values.M);
    }

    @Override
    public int getMinBars() {

        return getSettings().getInteger(Inputs.PERIOD);
    }

    @Override
    protected void calculate(int index, DataContext ctx) {

        int period = getSettings().getInteger(Inputs.PERIOD);
        if (index < period) return;
        Object input = getSettings().getInput(Inputs.INPUT);

        var series = ctx.getDataSeries();
        Double curVal = series.getDouble(index, input);
        Double prevVal = series.getDouble(index - period, input);

        if (curVal == null || prevVal == null) return;
        double val = (curVal / prevVal) * 100;

        series.setDouble(index, Momentum.Values.M, val);
        series.setComplete(index);
    }
}

这是提供的用户界面:

enter image description here

我想添加一个基于振荡器类别更改的事件监听,如果振荡器更改,UI(例如另一个选项卡)需要基于此更改。

如何添加事件侦听器,至少可以记录/打印客户正在更改的类别?

https://www.motivewave.com/support/sdk.htm

https://www.motivewave.com/sdk/javadoc/index.html

0 个答案:

没有答案