hi,
I want to add a voice alert in BarBuilder indicator when BuyVolume > SellVolume by X%, can anyone point to sample code for adding voice alerts.
Thanks,
trades4x
How to add voice alert in custom indicator
-
- Posts: 552
- Joined: Mon Jul 09, 2018 11:18 am
- Has thanked: 25 times
- Been thanked: 86 times
Re: How to add voice alert in custom indicator
Here is a slightly modified BarBuilder which performes a voice alert any time a new bar comes. Feel free to modify it so it meets the desired conditions. Explore the SoundSynthHelper and Layer1ApiSoundAlertMessage classes if you need more info.
Please note that text processing should be performed in a separate thread.
Also note the BarBuilder no longer implements the HistoricalDataListener so voice alerts start right at the moment the module is activated.
Please note that text processing should be performed in a separate thread.
Also note the BarBuilder no longer implements the HistoricalDataListener so voice alerts start right at the moment the module is activated.
Code: Select all
public class BarBuilder extends DataRecorderBase implements CustomModule, TradeDataListener, TimeListener {
protected Long barTime = null;
protected final long barInterval = Intervals.INTERVAL_2_SECONDS;
private Bar bar = new Bar();
int num;
ExecutorService executor = Executors.newSingleThreadExecutor();
@Override
public void onTimestamp(long t) {
if (barTime == null || barTime > t) {
barTime = barInterval * (t / barInterval);
}
while (barTime + barInterval < t) {
barTime += barInterval;
onBar();
bar.startNext();
}
}
@Override
public void onTrade(double price, int size, TradeInfo tradeInfo) {
bar.addTrade(tradeInfo.isBidAggressor, size, price);
writeObjects(getDateTime(barTime), tradeInfo.isBidAggressor ? "Buy" : "Sell", price, size);
}
@Override
public void initialize(String alias, InstrumentInfo info, Api api, InitialState initialState) {
}
protected void onBar() {
String datetime = getDateTime(barTime);
String info = String.format("onBar time: %s. OHLC: %.0f, %.0f, %.0f, %.0f. Volume Buy Sell: %d, %d", datetime,
bar.getOpen(), bar.getHigh(), bar.getLow(), bar.getClose(), bar.getVolumeBuy(), bar.getVolumeSell());
Log.info(info);
byte[] bytes = SoundSynthHelper.synthesize("Bar number " + ++num);
Thread t = new Thread(() -> {
try (AudioInputStream stream = AudioSystem.getAudioInputStream(new ByteArrayInputStream(bytes))) {
AudioFormat format = stream.getFormat();
DataLine.Info line = new DataLine.Info(Clip.class, format);
Clip clip = (Clip) AudioSystem.getLine(line);
clip.open(stream);
clip.start();
} catch (UnsupportedAudioFileException | IOException | LineUnavailableException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
});
executor.execute(t);
}
@Override
protected String getFilename() {
return "Volume_" + System.currentTimeMillis() + ".txt";
}
@Override
public void stop(){
executor.shutdownNow();
}
}
Re: How to add voice alert in custom indicator
Yeah I am facing this problem that it starts activating as soon as it is loaded and often it finds events in excess of 13000+ and calling these voice alerts freezes the bookmap.
Any hints or sample code to avoid activating voice alert code for historical data except when replaying..
really need help on this ...
Any hints or sample code to avoid activating voice alert code for historical data except when replaying..
really need help on this ...
-
- Posts: 552
- Joined: Mon Jul 09, 2018 11:18 am
- Has thanked: 25 times
- Been thanked: 86 times
Re: How to add voice alert in custom indicator
Your class must not implement HistoricalDataListener.Any hints or sample code to avoid activating voice alert code for historical data
public class BarBuilder extends DataRecorderBase implements CustomModule, TradeDataListener, TimeListener, HistoricalDataListener{