Announcement

Collapse
No announcement yet.

MA Vol EFS help

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

  • MA Vol EFS help

    I tried a few ways but they did not work and could use a small favor.
    When the MA is greater then 250 the background truns one colr and when less then 250 the background turns another. I have gotten real rusty. If someone could add the 2 lines of code I would greatly appreciateit. Kind of frustrated with my results.
    Thanks
    Earl
    [email protected]

    /************************************************** *******
    Alexis C. Montenegro © December 2004
    Use and/or modify this code freely. If you redistribute it
    please include this and/or any other comment blocks and a
    description of any changes you make.
    ************************************************** ********/

    var fpArray = new Array();

    function preMain() {

    setPriceStudy(false);
    setStudyTitle("VolumeMA");
    setCursorLabelName("Vol", 0);
    setCursorLabelName("maVol", 1);
    setDefaultBarStyle(PS_SOLID, 0);
    setDefaultBarStyle(PS_SOLID, 1);
    setDefaultBarFgColor(Color.black, 0);
    setDefaultBarFgColor(Color.black, 1);
    setDefaultBarThickness(2, 0);
    setDefaultBarThickness(2, 1);
    setPlotType(PLOTTYPE_HISTOGRAM, 0);
    setPlotType(PLOTTYPE_LINE, 1);
    askForInput();
    setStudyMin(1);
    setStudyMax(500);

    var x = 0;
    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("MAType", FunctionParameter.STRING);
    with(fpArray[x++]){
    addOption("sma");
    addOption("ema");
    addOption("wma");
    setDefault("sma");
    }
    fpArray[x] = new FunctionParameter("MALength", FunctionParameter.NUMBER);
    with(fpArray[x++]){
    setLowerLimit(1);
    setDefault(20);
    }
    fpArray[x] = new FunctionParameter("Source", FunctionParameter.STRING);
    with(fpArray[x++]){
    setName("Color based on");
    addOption("Price");
    addOption("Volume");
    setDefault("Price");
    }
    fpArray[x] = new FunctionParameter("ColorUp", FunctionParameter.COLOR);
    with(fpArray[x++]){
    setName("Up Color");
    setDefault(Color.blue);
    }
    fpArray[x] = new FunctionParameter("ColorDn", FunctionParameter.COLOR);
    with(fpArray[x++]){
    setName("Down Color");
    setDefault(Color.red);
    }
    fpArray[x] = new FunctionParameter("Params", FunctionParameter.BOOLEAN);
    with(fpArray[x++]){
    setName("Show Parameters");
    setDefault(false);
    }
    }

    var bInit = false;
    var vSymbol = null;
    var xMAofVol = null;

    function main(Symbol,Interval,MAType,MALength,Source,ColorU p,ColorDn,Params) {

    if(bInit == false){
    if(Symbol == null) Symbol = getSymbol();
    if(Interval == null) Interval = getInterval();
    vSymbol = Symbol+","+Interval;
    xMAofVol = eval(MAType)(MALength,volume(sym(vSymbol)));
    setShowTitleParameters(eval(Params));
    bInit = true;
    }

    if(Source=="Price"){
    if (close(sym(vSymbol)) < open(sym(vSymbol)))
    setBarFgColor(ColorDn,0);
    else if (close(sym(vSymbol)) > open(sym(vSymbol)))
    setBarFgColor(ColorUp,0);
    else if (close(sym(vSymbol)) == open(sym(vSymbol)))
    setBarFgColor(Color.black,0);
    }
    if(Source=="Volume"){
    if (volume(sym(vSymbol)) < volume(-1,sym(vSymbol)))
    setBarFgColor(ColorDn,0);
    else if (volume(sym(vSymbol)) > volume(-1,sym(vSymbol)))
    setBarFgColor(ColorUp,0);
    else if (volume(sym(vSymbol)) == volume(-1,sym(vSymbol)))
    setBarFgColor(Color.black,0);
    }

    return new Array (volume(sym(vSymbol)),getSeries(xMAofVol));
    }

  • #2
    Earl
    The code enclosed below shows you how to evaluate if the average is above 250 and color the background.
    Add it to your script just before the return statement replacing your_color with the color of you choice and use it as an example to create other conditions
    Alex

    PHP Code:
    if(xMAofVol.getValue(0)>250)
         
    setBarBgColor(Color.your_color); 

    Comment


    • #3
      Worked like a charm. One more thing.

      I also wanted to do the same based on the just actual volume bar over or uner 250. I replace xMAofVol with vSymbol, and it did not work. What is the correct word to put in here.
      Thanks.

      Comment


      • #4
        Earl
        In that case use volume(sym(vSymbol)) in your conditions
        Alex

        Comment


        • #5
          Works perfect Thanks

          Earl

          Comment

          Working...
          X