Hi, I've made my first indicator for Jforex.
I'm very new at this.
I want to use the STDDEV to check the market volatility because
I trade only accelerations following a price squeez.
I managed to make my indicator, but yet I want to do this :
- Getting the value of the indicator
- Testing if STDDEV value < 1 and triggering an Alert box showing the Instrument, the period
and the event ("Price squeez").
Last question :
If I want to check the STDDEV of an MACD how can I do this ? I mean taking the MACD
value instead of Price.
Thank a lot for your help.
Here is my STDDEV indicator
package jforex;
import com.dukascopy.api.*;
import com.dukascopy.api.indicators.*;
public class ET_Nico implements IIndicator {
private IConsole console;
private IContext context;
private IndicatorInfo indicatorInfo;
private InputParameterInfo[] inputParameterInfos;
private OptInputParameterInfo[] optInputParameterInfos;
private OutputParameterInfo[] outputParameterInfos;
private double[][] inputs = new double[1][];
private int[] timePeriod = new int[3];
private double[][] outputs = new double[3][];
private IIndicator ET_Price;
public void onStart(IIndicatorContext context) {
console = context.getConsole();
IIndicatorsProvider indicatorsProvider = context.getIndicatorsProvider();
ET_Price = indicatorsProvider.getIndicator("STDDEV");
indicatorInfo = new IndicatorInfo("ET_Nico", "Affichage ET Price", "My indicators", false, false, false, 1, 1, 1);
inputParameterInfos = new InputParameterInfo[] {new InputParameterInfo("Input data", InputParameterInfo.Type.DOUBLE)};
optInputParameterInfos = new OptInputParameterInfo[] {new OptInputParameterInfo("Period", OptInputParameterInfo.Type.OTHER,
new IntegerRangeDescription(20, 2, 100, 1))};
outputParameterInfos = new OutputParameterInfo[] {new OutputParameterInfo("ET", OutputParameterInfo.Type.DOUBLE,
OutputParameterInfo.DrawingStyle.LINE)};
}
public IndicatorResult calculate(int startIndex, int endIndex) {
//calculating startIndex taking into account lookback value
if (startIndex - getLookback() < 0) {
startIndex -= startIndex - getLookback();
}
// Set parameters to ET_Price and calculate it's values:
ET_Price.setInputParameter(0, inputs[0]);
ET_Price.setOptInputParameter(0, timePeriod[0]);
ET_Price.setOutputParameter(0, outputs[0]);
ET_Price.calculate(startIndex, endIndex);
return ET_Price.calculate(startIndex, endIndex);
}
public IndicatorInfo getIndicatorInfo() {
return indicatorInfo;
}
public InputParameterInfo getInputParameterInfo(int index) {
if (index <= inputParameterInfos.length) {
return inputParameterInfos[index];
}
return null;
}
// Lookback of the indicator should be biggest lookback of all three ET_Prices.
public int getLookback() {
ET_Price.setOptInputParameter(0, timePeriod[0]);
int ema1Lookback = ET_Price.getLookback();
return ema1Lookback;
}
public int getLookforward() {
return 0;
}
public OptInputParameterInfo getOptInputParameterInfo(int index) {
if (index <= optInputParameterInfos.length) {
return optInputParameterInfos[index];
}
return null;
}
public OutputParameterInfo getOutputParameterInfo(int index) {
if (index <= outputParameterInfos.length) {
return outputParameterInfos[index];
}
return null;
}
public void setInputParameter(int index, Object array) {
inputs[index] = (double[]) array;
}
// Also change method that saves time period parameters
public void setOptInputParameter(int index, Object value) {
timePeriod[index] = (Integer) value;
}
public void setOutputParameter(int index, Object array) {
outputs[index] = (double[]) array;
}
}