How can I go about getting multiple instances of the same indicator?
e.g. I need the VWAP which resets every 30 mins AND I also need a VWAP which resets every day say at 09:00
PS: I can one but NOT both as of now from the studies configuration of VWAP
any ideas?
multiple instances of same indicator
-
- Posts: 67
- Joined: Thu Nov 01, 2018 1:50 pm
- Has thanked: 38 times
- Been thanked: 9 times
-
- Posts: 548
- Joined: Mon Jul 09, 2018 11:18 am
- Has thanked: 25 times
- Been thanked: 85 times
Re: multiple instances of same indicator
Hi SuperDriveGuy,
are you asking about the indicator you have developed? Inherit one indicator from another and give it a different name (this is for your convenience only) so you'll have two.
For built-in indicators this is impossible.
are you asking about the indicator you have developed? Inherit one indicator from another and give it a different name (this is for your convenience only) so you'll have two.
For built-in indicators this is impossible.
-
- Posts: 67
- Joined: Thu Nov 01, 2018 1:50 pm
- Has thanked: 38 times
- Been thanked: 9 times
Re: multiple instances of same indicator
Thanks AndreyR!
I was referring to the built in VWAP indicator, so look like that it is not possible to get multiple VWAPs.
As an alternative maybe I can use one of the indicators provided as an example and just create copies as you suggested, so one for 10 mins, 30 mins etc etc
I have one question about the provided "sampleMovingVWAP" and "Moving Average Price", do they actually include the volume data in tgeir calculation i.e. is it a VWAP? I only seem to find reference to price and none to volume, maybe I am missing something? Thanks in advance
---------------------------------------------------------
package com.bookmap.api.simple.demo.indicators;
import java.awt.Color;
import com.bookmap.api.simple.demo.utils.data.MovingAverage;
import velox.api.layer1.data.InstrumentInfo;
import velox.api.layer1.messages.indicators.Layer1ApiUserMessageModifyIndicator.GraphType;
import velox.api.layer1.simplified.Api;
import velox.api.layer1.simplified.Indicator;
import velox.api.layer1.simplified.InitialState;
public class MovingVWAP extends MovingAveragePrice {
Indicator indicatorVwap;
MovingAverage maVwap;
@Override
public void initialize(String alias, InstrumentInfo info, Api api, InitialState initialState) {
super.initialize(alias, info, api, initialState);
indicatorVwap = api.registerIndicator("Moving VWAP", GraphType.PRIMARY);
indicatorVwap.setColor(Color.PINK);
}
}
---------------------------------------------------------
---------------------------------------------------------
@Layer1SimpleAttachable
@Layer1StrategyName("Moving Average Price")
@Layer1ApiVersion(Layer1ApiVersionValue.VERSION1)
public class MovingAveragePrice
implements CustomModule, TradeDataListener, IntervalListener, CustomSettingsPanelProvider {
private double lastTradePrice = Double.NaN;
private Indicator indicator;
private final long defaultPeriodSeconds = 30;
private long periodSeconds = defaultPeriodSeconds;
private final long interval = Intervals.INTERVAL_50_MILLISECONDS;
private MovingAverage ma;
private Api api;
@Override
public void initialize(String alias, InstrumentInfo info, Api api, InitialState initialState) {
indicator = api.registerIndicator("Moving Average", GraphType.PRIMARY);
indicator.setColor(Color.LIGHT_GRAY);
this.lastTradePrice = initialState.getLastTradePrice();
this.api = api;
ma = new MovingAverage(getNumPeriods());
}
@Override
public void onTrade(double price, int size, TradeInfo tradeInfo) {
lastTradePrice = price;
}
@Override
public long getInterval() {
return Intervals.INTERVAL_100_MILLISECONDS;
}
@Override
public void onInterval() {
double price = ma.update(lastTradePrice);
indicator.addPoint(price);
}
@Override
public void stop() {
}
-------------------------------------------------------
Thanks
I was referring to the built in VWAP indicator, so look like that it is not possible to get multiple VWAPs.
As an alternative maybe I can use one of the indicators provided as an example and just create copies as you suggested, so one for 10 mins, 30 mins etc etc
I have one question about the provided "sampleMovingVWAP" and "Moving Average Price", do they actually include the volume data in tgeir calculation i.e. is it a VWAP? I only seem to find reference to price and none to volume, maybe I am missing something? Thanks in advance
---------------------------------------------------------
package com.bookmap.api.simple.demo.indicators;
import java.awt.Color;
import com.bookmap.api.simple.demo.utils.data.MovingAverage;
import velox.api.layer1.data.InstrumentInfo;
import velox.api.layer1.messages.indicators.Layer1ApiUserMessageModifyIndicator.GraphType;
import velox.api.layer1.simplified.Api;
import velox.api.layer1.simplified.Indicator;
import velox.api.layer1.simplified.InitialState;
public class MovingVWAP extends MovingAveragePrice {
Indicator indicatorVwap;
MovingAverage maVwap;
@Override
public void initialize(String alias, InstrumentInfo info, Api api, InitialState initialState) {
super.initialize(alias, info, api, initialState);
indicatorVwap = api.registerIndicator("Moving VWAP", GraphType.PRIMARY);
indicatorVwap.setColor(Color.PINK);
}
}
---------------------------------------------------------
---------------------------------------------------------
@Layer1SimpleAttachable
@Layer1StrategyName("Moving Average Price")
@Layer1ApiVersion(Layer1ApiVersionValue.VERSION1)
public class MovingAveragePrice
implements CustomModule, TradeDataListener, IntervalListener, CustomSettingsPanelProvider {
private double lastTradePrice = Double.NaN;
private Indicator indicator;
private final long defaultPeriodSeconds = 30;
private long periodSeconds = defaultPeriodSeconds;
private final long interval = Intervals.INTERVAL_50_MILLISECONDS;
private MovingAverage ma;
private Api api;
@Override
public void initialize(String alias, InstrumentInfo info, Api api, InitialState initialState) {
indicator = api.registerIndicator("Moving Average", GraphType.PRIMARY);
indicator.setColor(Color.LIGHT_GRAY);
this.lastTradePrice = initialState.getLastTradePrice();
this.api = api;
ma = new MovingAverage(getNumPeriods());
}
@Override
public void onTrade(double price, int size, TradeInfo tradeInfo) {
lastTradePrice = price;
}
@Override
public long getInterval() {
return Intervals.INTERVAL_100_MILLISECONDS;
}
@Override
public void onInterval() {
double price = ma.update(lastTradePrice);
indicator.addPoint(price);
}
@Override
public void stop() {
}
-------------------------------------------------------
Thanks
-
- Posts: 548
- Joined: Mon Jul 09, 2018 11:18 am
- Has thanked: 25 times
- Been thanked: 85 times
Re: multiple instances of same indicator
Looks like they don't (i.e. they aren't volume weighted)
But you've got an onTrade method in your MovingAveragePrice (or any class that implements the TradeDataListener interface) which gets sizes of each trade. So you can adjust those demo indicators to your needs. This is just an approach idea:
But you've got an onTrade method in your MovingAveragePrice (or any class that implements the TradeDataListener interface) which gets sizes of each trade. So you can adjust those demo indicators to your needs. This is just an approach idea:
Code: Select all
double cumulativeTotal;
double cumulativeVolume;
double vwap;
@Override
public void onTrade(double price, int size, TradeInfo tradeInfo) {
double individualTotal = price*size;
cumulativeTotal += individualTotal;
cumulativeVolume += size;
vwap = cumulativeTotal/cumulativeVolume;
}