Announcement

Collapse
No announcement yet.

Use Function Parameter for text color

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Use Function Parameter for text color

    Greetings:

    I'm trying to use a 'String' FunctionParameter to set different colors in drawTextAbsolute without success in v7.9.

    Here's what I'm trying:

    var aFPArray = new Array();

    function preMain()
    {
    setPriceStudy(true);
    setStudyTitle("TradersReports");
    setShowCursorLabel(false);
    askForInput();

    //initialize formula parameters

    var x=0;

    //define a color menu option

    aFPArray[x] = new FunctionParameter( "Param1", FunctionParameter.STRING);
    with( aFPArray[x] ) {
    setName( "String Menu Option" );
    addOption( "Color.red" );
    addOption( "Color.blue" );
    setDefault( "Color.red" );
    }

    }

    function main(Param1)
    {

    if (getBarState() == BARSTATE_NEWBAR)
    {

    // Display report results

    drawTextAbsolute(1, 14, " Report Alert ", Param1, Color.black, Text.RELATIVETOLEFT | Text.RELATIVETOBOTTOM | Text.LEFT | Text.FRAME | Text.ONTOP | Text.BOLD, null, 10, "Proof1");

    }

    debugClear();
    debugPrintln(" Param1 : " + Param1);
    }

    Is there a solution?

    Warren
    Last edited by werosen; 03-18-2006, 01:16 PM.

  • #2
    Re: Use Function Parameter for text color

    Originally posted by werosen
    Greetings:

    I'm trying to use a 'String' FunctionParameter to set different colors in drawTextAbsolute without success in v7.9.

    Here's what I'm trying:

    var aFPArray = new Array();

    function preMain()
    {
    setPriceStudy(true);
    setStudyTitle("TradersReports");
    setShowCursorLabel(false);
    askForInput();

    //initialize formula parameters

    var x=0;

    //define a color menu option

    aFPArray[x] = new FunctionParameter( "Param1", FunctionParameter.STRING);
    with( aFPArray[x] ) {
    setName( "String Menu Option" );
    addOption( "Color.red" );
    addOption( "Color.blue" );
    setDefault( "Color.red" );
    }

    }

    function main(Param1)
    {

    if (getBarState() == BARSTATE_NEWBAR)
    {

    // Display report results

    drawTextAbsolute(1, 14, " Report Alert ", Param1, Color.black, Text.RELATIVETOLEFT | Text.RELATIVETOBOTTOM | Text.LEFT | Text.FRAME | Text.ONTOP | Text.BOLD, null, 10, "Proof1");

    }

    debugClear();
    debugPrintln(" Param1 : " + Param1);
    }

    Is there a solution?

    Warren
    When normally used to set a color, Color.red is an object, not a string. Setting the color using FunctionParameter, you need to provide a string value. Therein lies your problem. If you use the eval() function on the string you have provided the efs, that will evaluate the string in the appropriate context. e.g. use eval(Param1) in your drawTextAbsolute command versus just Param1

    This should work for you.

    Comment


    • #3
      Thanks Steve:

      I appreciate the assist.

      Warren

      Comment

      Working...
      X