Announcement

Collapse
No announcement yet.

altering line colors

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

  • altering line colors

    Hi,

    I have been trying to plot an ADX line which changes colors when it goes below 10 or above 29. One below it should go red, once above 29 it should go green.

    This code here is my last try to make this work. It give me no output. The code before which didn't use the getValue() function gave me one color which never changed.

    Any input would be greatly appreciated.




    ---------------------------------------------------------------------

    var fpArray = new Array();




    function preMain() {

    setPriceStudy(false);
    setStudyTitle("ADX");
    setCursorLabelName("ADX", 0);
    setPlotType(PLOTTYPE_LINE,0);
    setDefaultBarThickness(2,0);



    var x=0;
    fpArray[x] = new FunctionParameter("Length", FunctionParameter.NUMBER);
    with(fpArray[x++]){
    setLowerLimit(1);
    setDefault(14);
    }
    fpArray[x] = new FunctionParameter("Smoothing", FunctionParameter.NUMBER);
    with(fpArray[x++]){
    setLowerLimit(1);
    setDefault(14);
    }
    fpArray[x] = new FunctionParameter("Symbol", FunctionParameter.STRING);
    with(fpArray[x++]){
    setDefault();
    }
    fpArray[x] = new FunctionParameter("Interval", FunctionParameter.STRING);
    with(fpArray[x++]){
    setDefault();
    }
    fpArray[x] = new FunctionParameter("Params", FunctionParameter.BOOLEAN);
    with(fpArray[x++]){
    setName("Show Parameters");
    setDefault(false);
    }
    }

    var bInit = false;
    var xADX = null;
    var xPDI = null;
    var xNDI = null;

    function main(Length,Smoothing,Symbol,Interval,Params) {

    if(bInit == false){
    if(Symbol == null) Symbol = getSymbol();
    if(Interval == null) Interval = getInterval();
    var vSymbol = Symbol+","+Interval;
    xADX = adx(Length,Smoothing,sym(vSymbol));
    xPDI = pdi(Length,Smoothing,sym(vSymbol));
    xNDI = ndi(Length,Smoothing,sym(vSymbol));
    setShowTitleParameters(eval(Params));



    bInit = true;

    }

    if (getValue(xADX(0) > 29)) setDefaultBarColor (Color, green);
    else if (getValue(xADX(0) <= 10)) setDefaultBarColor (Color, red);
    else setDefaultBarColor (Color, yellow);


    return new Array (getSeries(xADX));
    }

  • #2
    Hi Beebers,

    Color, green should be ...

    Color.green

    Check out the knowledgebase here and here.

    There are some other issues with your getValue statements as well. I believe this is the correct syntax.

    if(xADX.getValue(0)>10)setBarFgColor ( Color.green );

    Comment


    • #3
      Steve,

      this worked. Thank you so much.

      Comment


      • #4
        Hi Beebers,

        Good to hear, you are most welcome.

        Comment


        • #5
          Hi guys.

          Very interested in the work you are doing here. I have taken the liberty of using your code as I am interested in a "colour coded" ADX but with the trigger values of >20 and then another band at >40.

          I can get the line to change from red to green as it crossed 20 but is there any way it can then change to a different colour as it passes 40? I am not at all proficient when it comes to coding efs's so I thought the following might work, but it doesn't. Any help greatly appreciated..

          var fpArray = new Array();




          function preMain() {

          setPriceStudy(false);
          setStudyTitle("ADX");
          setCursorLabelName("ADX", 0);
          setPlotType(PLOTTYPE_LINE,0);
          setDefaultBarThickness(2,0);



          var x=0;
          fpArray[x] = new FunctionParameter("Length", FunctionParameter.NUMBER);
          with(fpArray[x++]){
          setLowerLimit(1);
          setDefault(14);
          }
          fpArray[x] = new FunctionParameter("Smoothing", FunctionParameter.NUMBER);
          with(fpArray[x++]){
          setLowerLimit(1);
          setDefault(14);
          }
          fpArray[x] = new FunctionParameter("Symbol", FunctionParameter.STRING);
          with(fpArray[x++]){
          setDefault();
          }
          fpArray[x] = new FunctionParameter("Interval", FunctionParameter.STRING);
          with(fpArray[x++]){
          setDefault();
          }
          fpArray[x] = new FunctionParameter("Params", FunctionParameter.BOOLEAN);
          with(fpArray[x++]){
          setName("Show Parameters");
          setDefault(false);
          }
          }

          var bInit = false;
          var xADX = null;
          var xPDI = null;
          var xNDI = null;

          function main(Length,Smoothing,Symbol,Interval,Params) {

          if(bInit == false){
          if(Symbol == null) Symbol = getSymbol();
          if(Interval == null) Interval = getInterval();
          var vSymbol = Symbol+","+Interval;
          xADX = adx(Length,Smoothing,sym(vSymbol));
          xPDI = pdi(Length,Smoothing,sym(vSymbol));
          xNDI = ndi(Length,Smoothing,sym(vSymbol));
          setShowTitleParameters(eval(Params));



          bInit = true;

          }

          if(xADX.getValue(0)<20)setBarFgColor ( Color.red );
          else if (xADX.getValue(0)>20)setBarFgColor ( Color.green );
          else if (xADX.getValue(0)>40)setBarFgColor ( Color.blue );
          else setDefaultBarColor (Color.yellow);


          return new Array (getSeries(xADX));

          Comment


          • #6
            How about this for the last few lines .....


            ----------------------------------------------------


            setDefaultBarFgColor(Color.yellow);
            if(xADX.getValue(0)<=20)setBarFgColor ( Color.red );
            else if(xADX.getValue(0)>=40)setBarFgColor ( Color.green );


            return new Array (getSeries(xADX));


            -----------------------------------------------------------

            Comment


            • #7
              That's the tickets....Brillaint! Changed the colours round a bit (now fushcia when >40 as the blue didn't show that well against the green on the chart).. Cracking job, thanks so much for the quick reply..

              var fpArray = new Array();




              function preMain() {

              setPriceStudy(false);
              setStudyTitle("ADX");
              setCursorLabelName("ADX", 0);
              setPlotType(PLOTTYPE_LINE,0);
              setDefaultBarThickness(2,0);



              var x=0;
              fpArray[x] = new FunctionParameter("Length", FunctionParameter.NUMBER);
              with(fpArray[x++]){
              setLowerLimit(1);
              setDefault(14);
              }
              fpArray[x] = new FunctionParameter("Smoothing", FunctionParameter.NUMBER);
              with(fpArray[x++]){
              setLowerLimit(1);
              setDefault(14);
              }
              fpArray[x] = new FunctionParameter("Symbol", FunctionParameter.STRING);
              with(fpArray[x++]){
              setDefault();
              }
              fpArray[x] = new FunctionParameter("Interval", FunctionParameter.STRING);
              with(fpArray[x++]){
              setDefault();
              }
              fpArray[x] = new FunctionParameter("Params", FunctionParameter.BOOLEAN);
              with(fpArray[x++]){
              setName("Show Parameters");
              setDefault(false);
              }
              }

              var bInit = false;
              var xADX = null;
              var xPDI = null;
              var xNDI = null;

              function main(Length,Smoothing,Symbol,Interval,Params) {

              if(bInit == false){
              if(Symbol == null) Symbol = getSymbol();
              if(Interval == null) Interval = getInterval();
              var vSymbol = Symbol+","+Interval;
              xADX = adx(Length,Smoothing,sym(vSymbol));
              xPDI = pdi(Length,Smoothing,sym(vSymbol));
              xNDI = ndi(Length,Smoothing,sym(vSymbol));
              setShowTitleParameters(eval(Params));



              bInit = true;

              }

              setDefaultBarFgColor(Color.green);
              if(xADX.getValue(0)<=20)setBarFgColor ( Color.red );
              else if(xADX.getValue(0)>=40)setBarFgColor ( Color.fushcia );


              return new Array (getSeries(xADX));


              return new Array (getSeries(xADX));
              }

              Comment


              • #8
                If it's OK with you guys I might post the efs itself, with credit where credit is due?? Do let me know if that is OK.. TIA

                Comment


                • #9
                  No problem - this is a public forum after all .....

                  Comment


                  • #10
                    colour / color ADX indicator

                    perfect. here it is..
                    Attached Files

                    Comment


                    • #11
                      oops, for some reason I posted the version without the credits where credit is due.. Amended version attached..
                      Attached Files
                      Last edited by nwal66; 02-17-2007, 03:54 PM.

                      Comment

                      Working...
                      X