Function Parameter Class

ICE Data Services -

Function Parameter Class

 

The function parameter class is a set of objects and functions that allow you to manage your input parameters in a script. When this class is used, you will no longer need to initialize parameters passed to your main() function. Here are some example function calls that best describe the usage and functionality of this class:

 

function preMain() {
  // The order these are defined is not important.

  // Class: FunctionParameter(parameterName, parameterType);

  // What is important is that the "parameterName" matches the parameter in the main definition.

  // Note: setName, setDefault, setLowerLimit, setUpperLimit are all OPTIONAL

  var fp1 = new FunctionParameter("sList", FunctionParameter.STRING); // This is the text that will appear in the "edit studies".  Prior to the FunctionParameter class // The name of the variable always appeard in the edit studies box.

  fp1.setName("StringList");

  fp1.addOption("option1");

  fp1.addOption("option2");

  fp1.addOption("option3");

  fp1.addOption("option4");

  fp1.addOption("option5"); // Default value to select.  -- See notes in main about defaults.

  fp1.setDefault("option3");

  var fp2 = new FunctionParameter("bInput", FunctionParameter.BOOLEAN);

  fp2.setName("Bool Input");

  fp2.setDefault(true);

  var fp3 = new FunctionParameter("sInput", FunctionParameter.STRING);

  fp3.setName("StringInput");

  fp3.setDefault("TheDefault");

  var fp4 = new FunctionParameter("nInput", FunctionParameter.NUMBER);

  fp4.setLowerLimit(1);
  fp4.setUpperLimit(100);

  fp4.setDefault(10);

  var fp5 = new FunctionParameter("colorInput", FunctionParameter.COLOR);

  fp5.setDefault(Color.black); // askForInput([title]) the title is optional.  This is the text that appears in the titlebar of the // Input box.  This function will cause an input box to appear when the formula is ADDED to the chart.

  askForInput("testing 123");

  setStudyTitle("FuncParmTest");
}

function main(sList, bInput, sInput, nInput, colorInput, blankInput) {
  if (getCurrentBarIndex() == 0) {
    // Point of interest:  If the user does not provide input values

    // these variables will AUTOMATICALLY be initialized to the value provided in

    // setDefault (see above in preMain).  This means you no longer need to do the

    // if(var==null) var = nnn;

    //

    debugPrintln("sList: " + sList);

    debugPrintln("bInput: " + bInput);

    debugPrintln("sInput: " + sInput);

    debugPrintln("nInput: " + nInput);

    debugPrintln("colorInput: " + colorInput);

    debugPrintln("blankInput: " + blankInput);
  }
}