Indicator Metadata

Indicator metadata is a collection of parameters which describe every indicator. Consider two cases when knowing this data is particularly important:

  • Using universal indicator calculation methods - one has to know how many optional inputs to pass (and optionally what are their names - what they stand for) and how many outputs to expect.
  • When plotting an indicator on chart from a strategy - one has to know how many optional inputs need to be passed and if setting custom output style - then also the number of outputs.

For full reference of metadata describing classes see articles: IndicatorInfo, InputParameterInfo, OptInputParameterInfo and OutputParameterInfo. Note that only a fraction of this data one might find useful to know in his strategy (like number of optional inputs and number of outputs) - most of them solely serve for indicator design purposes.

Retrieve indicator metadata

JForex API interface IIndicator enables the user the access to indicator metadata like input, optional input, output types, etc. One gets an indicator instance in the following way:

IIndicator indCOG = context.getIndicators().getIndicator("COG");

Consider a function which prints out name and type of all the indicator's inputs, outputs and optional inputs:

    private void printIndicatorInfos(IIndicator ind){
        IndicatorInfo info = ind.getIndicatorInfo();
        print(String.format("%s: input count=%s, optional input count=%s, output count=%s", 
                info.getTitle(),
                info.getNumberOfInputs(), 
                info.getNumberOfOptionalInputs(),
                info.getNumberOfOutputs()));
        for (int i = 0; i < ind.getIndicatorInfo().getNumberOfInputs(); i++){
            print(String.format("Input %s: %s - %s", 
                i, ind.getInputParameterInfo(i).getName(), ind.getInputParameterInfo(i).getType()));
        }
        for (int i = 0; i < ind.getIndicatorInfo().getNumberOfOptionalInputs(); i++){
            print(String.format("Opt Input %s: %s - %s", 
                i, ind.getOptInputParameterInfo(i).getName(), ind.getOptInputParameterInfo(i).getType()));
        }
        for (int i = 0; i < ind.getIndicatorInfo().getNumberOfOutputs(); i++){
            print(String.format("Output %s: %s - %s", 
                i, ind.getOutputParameterInfo(i).getName(), ind.getOutputParameterInfo(i).getType()));
        }
    }

private void print(Object o){
    console.getOut().println(o);
}

IndicatorMetadata.java

Retrieve metadata by group

Consider printing to console metadata of all candle pattern indicators:

@Override
public void onStart(IContext context) throws JFException {
    this.indicators = context.getIndicators();
    this.console = context.getConsole();
    Collection<String> indNames = indicators.getAllNames();

    for(String name : indNames){
        IndicatorInfo info = indicators.getIndicator(name).getIndicatorInfo();
        //CDL is prefix of all candle pattern indicator names
        if(info.getGroupName().equalsIgnoreCase("Pattern Recognition") && name.contains("CDL")){
            console.getOut().println(String.format("%s, %s, %s, inputs=%s, opt inputs=%s, outputs=%s",
                info.getName(),info.getGroupName(),info.getTitle(),
                info.getNumberOfInputs(), info.getNumberOfOptionalInputs(), info.getNumberOfOutputs())
            );
        }
    }
}

Retrieve optional input value ranges

Consider printing to console all indicator's optional inputs, their value ranges and default values:

    public void onStart(IContext context) throws JFException {
        this.console = context.getConsole();
        this.indicators = context.getIndicators();      

        IIndicator indicator = indicators.getIndicator(indName);        
        IndicatorInfo info = indicator.getIndicatorInfo();
        int optInputCount = info.getNumberOfOptionalInputs();

        for(int i = 0; i < optInputCount; i++){
            OptInputParameterInfo optInfo = indicator.getOptInputParameterInfo(i);
            OptInputDescription descr = optInfo.getDescription();
            String rangeInfoStr = "";
            if(descr instanceof IntegerRangeDescription){
                IntegerRangeDescription d = ((IntegerRangeDescription)descr);
                rangeInfoStr = String.format("min=%s, max=%s", d.getMin(), d.getMax());
            } else if (descr instanceof DoubleRangeDescription){
                DoubleRangeDescription d = ((DoubleRangeDescription)descr);
                rangeInfoStr = String.format("min=%.5f, max=%.5f", d.getMin(), d.getMax());
            } else if (descr instanceof BooleanOptInputDescription){
                rangeInfoStr = ""; //boolean does not have no range
            } else if (descr instanceof IntegerListDescription){
                IntegerListDescription d = ((IntegerListDescription)descr);
                rangeInfoStr = String.format("names=%s, values=%s", 
                    Arrays.asList(d.getValueNames()), Arrays.toString(d.getValues()));
            } else if (descr instanceof DoubleListDescription){
                DoubleListDescription d = ((DoubleListDescription)descr);
                rangeInfoStr = String.format("names=%s, values=%s", 
                    Arrays.asList(d.getValueNames()), Arrays.toString(d.getValues()));
            }
            print("Opt input: %s, range: %s, default= %s",
                optInfo.getName(), rangeInfoStr, descr.getOptInputDefaultValue());
        }         
    }

OptInputValueRange2.java

The information on this web site is provided only as general information, which may be incomplete or outdated. Click here for full disclaimer.