Announcement

Collapse
No announcement yet.

Need little help on this simple problem

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

  • Need little help on this simple problem

    All I want on this EFS is to have the background trun colors if the indicator is above .85 or another if below -.85. I keep thinking it is correct but no syntax errors but no color change. Can someone help or fix this one for me.
    Thanks.

    var RSI = null;

    function preMain(){
    setStudyTitle("earl");
    setCursorLabelName("earl",0);
    setDefaultBarFgColor(Color.red,0);
    addBand(.85, PS_SOLID, 4, Color.black);
    addBand(-.85, PS_SOLID, 4, Color.black);

    addBand(.70, PS_SOLID, 2, Color.white);
    addBand(-.70, PS_SOLID, 2, Color.white);

    //addBand(-.80, PS_SOLID, 2, Color.red);

    //addBand(.80, PS_SOLID, 2, Color.red);
    addBand(-.00, PS_SOLID, 3, Color.yellow);
    setDefaultBarThickness(2);
    //setComputeOnClose();
    }

    function main(){
    wmaLength = 6;
    rsiLength = 6;
    if (RSI == null) RSI = new RSIStudy(rsiLength,"close");
    var IEarl = 0, WtdSum = 0 ;

    ///I think something is missing. I want the background to turn green if the main line is
    /// greater then .85 and red if less then -.85. Nothing appears on the char, but n
    ///syntax errors???
    if(IEarl > 0.85)
    {
    setBarBgColor(Color.green);
    }
    else if(IEarl < -0.85)
    {
    setBarBgColor(Color.maroon);
    }
    Value1 = .1 * (RSI.getValue(RSIStudy.RSI) - 50);

    for(i = 0; i < wmaLength; i++)
    WtdSum += (wmaLength - i) * (.1 * (RSI.getValue(RSIStudy.RSI,-i) - 50)) ;
    CumWt = (wmaLength + 1 ) * wmaLength * .5 ;
    Value2 = WAverage = WtdSum / CumWt ;

    IEarl = (Math.exp(2 * Value2) - 1) / (Math.exp(2 * Value2) + 1);

    return IEarl;
    }

  • #2
    earl540
    The variable IEarl is a local variable and gets reset to 0 at every iteration of the efs. So when the efs evaluates your conditions to color the background the value of IEarl is at that point 0.
    To resolve this you need to move all the conditions and commands that color the background to the line after you compute IEarl
    Alex

    Comment

    Working...
    X