The easiest way to save your settings is to use the @Parameter annotation. Take a look at the code below.
Code: Select all
package com.bookmap.api.simple.simplified;
import java.awt.Color;
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.messages.indicators.Layer1ApiUserMessageModifyIndicator.GraphType;
import velox.api.layer1.simplified.Api;
import velox.api.layer1.simplified.CustomModule;
import velox.api.layer1.simplified.Indicator;
import velox.api.layer1.simplified.InitialState;
import velox.api.layer1.simplified.Parameter;
import velox.api.layer1.simplified.TradeDataListener;
@Layer1SimpleAttachable
@Layer1StrategyName("Last trade Colors @Parameter: live")
@Layer1ApiVersion(Layer1ApiVersionValue.VERSION2)
public class LastTradeDemoColorParameter implements CustomModule, TradeDataListener {
private Indicator lastTradeIndicator;
@Parameter(name = "lineColor")
Color lineColor = Color.GREEN;
@Override
public void initialize(String alias, InstrumentInfo info, Api api, InitialState initialState) {
lastTradeIndicator = api.registerIndicator("Last trade, no history", GraphType.PRIMARY);
lastTradeIndicator.setColor(lineColor);
}
@Override
public void stop() {
}
@Override
public void onTrade(double price, int size, TradeInfo tradeInfo) {
lastTradeIndicator.addPoint(price);
}
}
It is as functional as the one I gave you yesterday, but it is shorter. In a few words: annotated field gets shown in the GUI and its value gets saved. Attention: only Numeric Objects (e.g. Integer, Double...) or String or Boolean or Color are accepted. You can also choose whether to reload your indicator after resetting it's value from the GUI. Use reloadOnChange annotation parameter for that.
Warning: new Color gets applied only after the instrument is reloaded. If you write code like this
Code: Select all
@Parameter(name = "lineColor", reloadOnChange = false)
Color lineColor = Color.GREEN;
you assign a new Color value, but you'll see it at the screen only after the indicator gets reloaded (like you reload it manually or change another annotated field value where 'reloadOnChange = true')