Indicator error adding panel settings

Custom indicators, trading strategies, data export and recording and more...
hedgefair
Posts: 11
Joined: Wed Nov 13, 2019 6:49 pm

Indicator error adding panel settings

Post by hedgefair » Wed Apr 15, 2020 11:19 pm

Note: I'm not aware of a high-level way of doing this. Is there anything on the API now?

I have coded an indicator for Bookmap. Running ok. Now I want to add a settings panel.  Following ATRTrailing I've tried to make a test indicator as an example but I cannot make it runs.  "Error: No entry point fond in jar. Entry point is a class marked with velox.api.layer1.annotations.Layer1Attachable annotation".  Can anyone at bookmap help?.
 

Code: Select all

 
package com.bookmap.api.simple.demo.indicators;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import java.util.function.Consumer;
import java.util.stream.Stream;

import javax.swing.JComboBox;
import javax.swing.JLabel;

import com.bookmap.api.simple.demo.utils.gui.BookmapSettingsPanel;

import velox.api.layer1.annotations.Layer1ApiVersion;
import velox.api.layer1.annotations.Layer1ApiVersionValue;
import velox.api.layer1.annotations.Layer1SimpleAttachable;
import velox.api.layer1.annotations.Layer1StrategyName;
import velox.api.layer1.data.InstrumentInfo;
import velox.api.layer1.data.TradeInfo;
import velox.api.layer1.layers.utils.OrderBook;
import velox.api.layer1.messages.indicators.Layer1ApiUserMessageModifyIndicator.GraphType;
import velox.api.layer1.settings.StrategySettingsVersion;
import velox.api.layer1.simplified.Api;

import velox.api.layer1.simplified.Bar;
import velox.api.layer1.simplified.BarDataListener;
import velox.api.layer1.simplified.CustomModule;
import velox.api.layer1.simplified.CustomSettingsPanelProvider;
import velox.api.layer1.simplified.Indicator;

import velox.api.layer1.simplified.IndicatorModifiable;
import velox.api.layer1.simplified.InitialState;
import velox.api.layer1.simplified.Intervals;
import velox.api.layer1.simplified.LineStyle;
import velox.api.layer1.simplified.TimeListener;
import velox.api.layer1.simplified.TradeDataListener;

import velox.gui.StrategyPanel;
import velox.gui.colors.ColorsConfigItem;




@Layer1SimpleAttachable
@Layer1StrategyName("PanelTest")
@Layer1ApiVersion(Layer1ApiVersionValue.VERSION1)
public class Panel_test implements CustomModule,CustomSettingsPanelProvider, BarDataListener, TradeDataListener, TimeListener{

@SuppressWarnings("unused")
private long nanoseconds;
public static enum SettingsName {
        PERIOD_1,PERIOD_2
    }
    private static final Color defaultColorBuy = Color.BLUE;
    private static final Color defaultColorSell = Color.RED;
    private static final LineStyle defaultLineStyle = LineStyle.SOLID;
    private static final int defaultLineWidth = 2;
    private static final int defaultPeriod1 = 60;
    private static final int defaultPeriod2 = 30;
    
    @StrategySettingsVersion(currentVersion = 1, compatibleVersions = {})
    public static class Settings {
        public Color colorBuy = defaultColorBuy;
        public Color colorSell = defaultColorSell;
        public LineStyle lineStyle = defaultLineStyle;
        public int lineWidth = defaultLineWidth;

        public int period1 = defaultPeriod1;
        public int period2 = defaultPeriod2;
    }

    protected IndicatorModifiable lineBuy;
    protected IndicatorModifiable lineSell;

    protected Settings settings;
    protected Api api;
    
private int nPeriods = 60;
private int nPeriodsMean = 30;
    
@Override
    public void initialize(String alias, InstrumentInfo info, Api api, InitialState initialState) {
this.api = api;
        settings = api.getSettings(Settings.class);
    lineBuy = api.registerIndicatorModifiable("DF_Ask", GraphType.BOTTOM);
    lineBuy.setColor(Color.BLUE);
    setVisualProperties(lineBuy);
    lineSell= api.registerIndicatorModifiable("DF_Bid", GraphType.BOTTOM);
    lineSell.setColor(Color.RED);
    setVisualProperties(lineSell);
    }
private void setVisualProperties(final Indicator indicator) {
indicator.setLineStyle(settings.lineStyle);
indicator.setWidth(settings.lineWidth);
}
@Override
public StrategyPanel[] getCustomSettingsPanels() {
StrategyPanel p1 = getStyleSettingsPanel();
StrategyPanel p2 = getParametersSettingsPanel();
return new StrategyPanel[] { p1, p2 };
    }
private StrategyPanel getStyleSettingsPanel() {
        BookmapSettingsPanel panel = new BookmapSettingsPanel("Indicators style settings");
        addColorsSettings(panel);
        addLineStyleSettings(panel);
        addLineWidthSettings(panel);
        return panel;
    }
    
    private void addColorsSettings(final BookmapSettingsPanel panel) {
        panel.addSettingsItem("Ask line color:", createColorsConfigItem(true));
        panel.addSettingsItem("Bid line color:", createColorsConfigItem(false));
    }
    
    
    private void setAlignment(final JComboBox<?> c) {
        ((JLabel)c.getRenderer()).setHorizontalAlignment(JLabel.LEFT);
    }
    
        
    private ColorsConfigItem createColorsConfigItem(boolean isBuy) {
        Consumer<Color> c = new Consumer<Color>() {

            @Override
            public void accept(Color color) {
                if (isBuy) {
                    settings.colorBuy = color;
                    lineBuy.setColor(settings.colorBuy);
                } else {
                    settings.colorSell = color;
                    lineSell.setColor(settings.colorSell);
                }
            }
        };
        Color color = isBuy ? settings.colorBuy : settings.colorSell;
        Color defaultColor = isBuy ? defaultColorBuy : defaultColorSell;
        return new ColorsConfigItem(color, defaultColor, c);
    }
    
   
    private void addLineStyleSettings(final BookmapSettingsPanel panel) {
        String[] lineStyles = Stream.of(LineStyle.values()).map(Object::toString).toArray(String[]::new);
        JComboBox<String> c = new JComboBox<>(lineStyles);
        setAlignment(c);
        c.setSelectedItem(settings.lineStyle.toString());
        c.setEditable(false);
        c.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                int idx = c.getSelectedIndex();
                if (idx != settings.lineStyle.ordinal()) {
                    settings.lineStyle = LineStyle.values()[idx];
                    lineBuy.setLineStyle(settings.lineStyle);
                    lineSell.setLineStyle(settings.lineStyle);
                }
            }
        });
        panel.addSettingsItem("Line type:", c);
    }
    
    private void addLineWidthSettings(final BookmapSettingsPanel panel) {
        JComboBox<Integer> c = new JComboBox<>(new Integer[] { 1, 2, 3, 4, 5 });
        setAlignment(c);
        c.setSelectedItem(settings.lineWidth);
        c.setEditable(false);
        c.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                int newLineWidth = (int) c.getSelectedItem();
                if (newLineWidth != settings.lineWidth) {
                    settings.lineWidth = newLineWidth;
                    lineBuy.setWidth(settings.lineWidth);
                    lineSell.setWidth(settings.lineWidth);
                }
            }
        });
        panel.addSettingsItem("Line width:", c);
    }
    
    
    private StrategyPanel getParametersSettingsPanel() {
        BookmapSettingsPanel panel = new BookmapSettingsPanel("Settings");
        addBarPeriodSettings1(panel);
        addBarPeriodSettings2(panel);
        return panel;
    }
    
    private void addBarPeriodSettings1(final BookmapSettingsPanel panel) {
        JComboBox<Integer> c = new JComboBox<>(
                new Integer[] { 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200, 250, 300, 350, 400, 450, 500});
        setAlignment(c);
        int selected = (int) (settings.period1);
        c.setSelectedItem(selected);
        c.setEditable(false);
        c.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
            onSettingsUpdated(SettingsName.PERIOD_1, c.getSelectedItem());
            }
        });
        panel.addSettingsItem("Bar period 1:", c);
    }
    
    private void addBarPeriodSettings2(final BookmapSettingsPanel panel) {
        JComboBox<Integer> c = new JComboBox<>(
                new Integer[] { 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200, 250, 300, 350, 400, 450 , 500});
        setAlignment(c);
        int selected = (int) (settings.period2);
        c.setSelectedItem(selected);
        c.setEditable(false);
        c.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
            onSettingsUpdated(SettingsName.PERIOD_2, c.getSelectedItem());
            }
        });
        panel.addSettingsItem("Bar period 2:", c);
    }
    
    protected void onSettingsUpdated(SettingsName settingsName, Object value) {
        switch (settingsName) {
        case PERIOD_1:
            int p1 = (int) value;
            if (p1 != settings.period1) {
                settings.period1 = p1;
                //onAtrUpdated(tr, atr);
            }
            break;
        case PERIOD_2:
        int p2 = (int) value;
            if (p2 != settings.period2) {
                settings.period2 = p2;
                //onAtrUpdated(tr, atr);
            }
            break;
        }
    }
    
    
    @Override
    public void stop() {
        api.setSettings(settings);
    }
    
    
@Override
    public void onTimestamp(long t) {
        nanoseconds = t;
    }
@Override
public long getInterval() {
return Intervals.INTERVAL_1_SECOND;
}

@Override
    public void onTrade(double price, int size, TradeInfo tradeInfo) {
   
    }
   
@Override
    public void onBar(OrderBook orderBook, Bar bar) { 
// this is to be sure that periods are changing so Im ploting that
lineBuy.addPoint(nPeriods);
    lineSell.addPoint(nPeriodsMean);
    }
}

Tags:

Andry API support
Posts: 548
Joined: Mon Jul 09, 2018 11:18 am
Has thanked: 25 times
Been thanked: 85 times

Re: Indicator error adding panel settings

Post by Andry API support » Thu Apr 16, 2020 7:57 am

Hi hedgefair!
We need to see your full log. Post it here or send me a private message.

hedgefair
Posts: 11
Joined: Wed Nov 13, 2019 6:49 pm

Re: Indicator error adding panel settings

Post by hedgefair » Fri Apr 17, 2020 11:48 am

20200417 11:47:31.916(UTC) WARN: No entry points in D:\Bookmap\MyAPICustomModules\testGUI.jar


Andry API support
Posts: 548
Joined: Mon Jul 09, 2018 11:18 am
Has thanked: 25 times
Been thanked: 85 times

Re: Indicator error adding panel settings

Post by Andry API support » Fri Apr 17, 2020 11:54 am

Hi hedgefair!
Unfortunately, that one line is not enough to figure out what is wrong.
Please upload your full log file. It is at C:\Bookmap\Logs for Windows or similar location for any other OS.

hedgefair
Posts: 11
Joined: Wed Nov 13, 2019 6:49 pm

Re: Indicator error adding panel settings

Post by hedgefair » Fri Apr 17, 2020 12:17 pm

I have started bookmap, tried to load indicator and shut down
here is the log:
https://www.dropbox.com/s/rxwpf7wev9ux6 ... n.txt?dl=0

two more:
https://www.dropbox.com/s/2h698v0ykuroy ... n.txt?dl=0
https://www.dropbox.com/s/ejj9ypmoqippu ... n.txt?dl=0

by the way, all the code is in my first post

thanks for your help

hedgefair
Posts: 11
Joined: Wed Nov 13, 2019 6:49 pm

Re: Indicator error adding panel settings

Post by hedgefair » Fri Apr 17, 2020 1:33 pm

Problem solved with Svyatoslav help!.

Thanks very much. The Bookmap team is great!

Post Reply