Announcement

Collapse
No announcement yet.

help with EFS for Watchlist

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

  • help with EFS for Watchlist

    Trying to use color coding to show a simple trend indicator based on MAs in a watchlist.

    [PHP]
    /************************************************** *******
    Plot the trend on a watch list
    ************************************************** ********/
    function preMain() {

    setPriceStudy(true);
    setDefaultBarBgColor(Color.lightgrey);
    setShowTitleParameters(false)

    // setPlotType(PLOTTYPE_LINE,0);
    // setDefaultBarThickness(1,0);
    // setPlotType(PLOTTYPE_LINE,1);
    // setDefaultBarThickness(1,1);
    // setDefaultBarFgColor(Color.blue,0);
    // setDefaultBarFgColor(Color.red,1);
    }

    bInit = false;
    var n50=0;
    var n200 = 0;
    var nPrc=0;
    var rText=""

    function main() {
    if (!bInit) {
    n50 = sma(50, 0);
    n200 = sma(200, 0);
    nPrc = close(0);
    rText = "new Array(n50, n200)";
    bInit = true;
    }

    if (nPrc > n50 && n50 > n200) {
    setBarBgColor(Color.RGB(190,255,190), 0, nPrc);
    setBarFgColor(Color.RGB(0,0,128));
    rText = "new Array(n50, n200)";
    } else if (nPrc < n50 && n50 < n200) {
    setBarBgColor(Color.RGB(255,190,190), 0, 0, nPrc);
    setBarFgColor(Color.RGB(128,0,0));
    rText = "new Array(n200, n50)";
    } else {
    setBarFgColor(Color.darkgrey);
    setBarBgColor(Color.lightgrey);
    }


    return eval(rText);
    }
    /[PHP]
    Last edited by pj909; 12-11-2020, 02:31 PM.

  • #2
    p.s. Been too long since I posted here. How do I get it format like a script?

    Comment


    • #3
      Use the PHP tags ie [ PHP ] at the beginning and [ /PHP ] at the end of the code (without the spaces after the [ and before the ]) as in the example below
      Alex

      PHP Code:
      function preMain() {

      setPriceStudy(true);
      setStudyTitle("SMA");
      setCursorLabelName("SMA",0);
      setDefaultBarFgColor(Color.RGB(0x00,0x94,0xFF), 0);
      setPlotType(PLOTTYPE_LINE,0);
      setDefaultBarThickness(1,0);
      }

      function 
      main() {

      return 
      sma(10);



      Originally posted by pj909 View Post
      p.s. Been too long since I posted here. How do I get it format like a script?

      Comment


      • #4
        Thanks Alex (had the / outside the brackets, duh).

        PHP Code:
        /************************************************** *******
        Plot the trend on a watch list
        ************************************************** ********/
        function preMain() {

        setPriceStudy(true);
        setDefaultBarBgColor(Color.lightgrey);
        setShowTitleParameters(false)

        // setPlotType(PLOTTYPE_LINE,0);
        // setDefaultBarThickness(1,0);
        // setPlotType(PLOTTYPE_LINE,1);
        // setDefaultBarThickness(1,1);
        // setDefaultBarFgColor(Color.blue,0);
        // setDefaultBarFgColor(Color.red,1);
        }

        bInit false;
        var 
        n50=0;
        var 
        n200 0;
        var 
        nPrc=0;
        var 
        rText=""

        function main() {
        if (!
        bInit) {
             
        n50 sma(500);
             
        n200 sma(2000);
             
        nPrc close(0);
             
        rText "new Array(n50, n200)";
        bInit true;
        }

        if (
        nPrc n50 && n50 n200) {
             
        setBarBgColor(Color.RGB(190,255,190), 0nPrc);
             
        setBarFgColor(Color.RGB(0,0,128));
             
        rText "new Array(n50, n200)";
        } else if (
        nPrc n50 && n50 n200) {
             
        setBarBgColor(Color.RGB(255,190,190), 00nPrc);
             
        setBarFgColor(Color.RGB(128,0,0));
             
        rText "new Array(n200, n50)";
        } else {
             
        setBarFgColor(Color.darkgrey);
             
        setBarBgColor(Color.lightgrey);
        }

        return eval(
        rText);

        So is it possible to change the order (and color) of the return values?

        Comment


        • #5
          If you want to color code a value in a Watchlist, it has to be done as a "return value" with a TAG.

          You've commented out all of your OUTPUTS (or return values). This means you are trying to control colors of things that are not being returned by the script.

          In other words, nothing returned means nothing gets color coded.

          B

          Comment


          • #6
            Try this...

            PHP Code:
            /************************************************** *******
            Plot the trend on a watch list
            ************************************************** ********/
            function preMain() {

            setPriceStudy(true);
            setDefaultBarBgColor(Color.lightgrey);
            setShowTitleParameters(false)

             
            setPlotType(PLOTTYPE_LINE,0);
             
            setDefaultBarThickness(1,0);
            // setPlotType(PLOTTYPE_LINE,1);
            // setDefaultBarThickness(1,1);
            // setDefaultBarFgColor(Color.blue,0);
            // setDefaultBarFgColor(Color.red,1);
            }

            bInit false;
            var 
            n50=0;
            var 
            n200 0;
            var 
            nPrc=0;
            var 
            rText=""

            function main() {
            if (!
            bInit) {
                 
            n50 sma(500);
                 
            n200 sma(2000);
                 
            nPrc close(0);
                 
            rText "new Array(n50, n200)";
            bInit true;
            }

            if (
            nPrc n50 && n50 n200) {
                 
            setBarBgColor(Color.RGB(190,255,190), 0nPrc);
                 
            setBarFgColor(Color.RGB(0,0,128),0);
                 
            rText "new Array(n50, n200)";
            } else if (
            nPrc n50 && n50 n200) {
                 
            setBarBgColor(Color.RGB(255,190,190), 00nPrc);
                 
            setBarFgColor(Color.RGB(128,0,0),0);
                 
            rText "new Array(n200, n50)";
            } else {
                 
            setBarFgColor(Color.darkgrey,0);
                 
            setBarBgColor(Color.lightgrey,0);
            }

            return eval(
            rText);

            You have to use the TAG ID for the setBar.... color options to determine what is being colored.

            Seeing as though you only have ONE return value (0), that is what we are trying to color.

            Comment

            Working...
            X