Announcement

Collapse
No announcement yet.

EFS Help required please

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

  • EFS Help required please

    I am trying to get the following formula to work but something is not quite correct.
    In one single study pane I will have two study lines based off the following two formulas.
    Indicator 1 Color.red)

    A 3 bar simple smoothed average of the following;

    {[[Highest(High(ofpast5bars))-Open(5barsago)]+[Close(current)-Lowest(Low(ofpast5bars))]]*100}
    all divided by {[(Highest(High(ofpast5bars)-Lowest(Low(ofpast5bars))]*2}

    Indicator 2 Color.blue)

    {[Close(current)-Lowest(Low(ofpast5bars)]*100}
    all divided by {Highest(High(ofpast5bars)-Lowest(Low(ofpast5bars)}

    PS It should also have a black color line at 50% mark.

    Here is my attempt at EFS but I am not getting the following formula to work and would
    sincerely appreciate the assistance to get this working

    function preMain() {
    setPriceStudy(false);
    setStudyTitle("LSS",0);
    setStudyTitle("SI",1);
    setDefaultBarFgColor(Color.red,0);
    setDefaultBarFgColor(Color.blue,1);
    setPlotType(PLOTTYPE_LINE,0);
    setPlotType(PLOTTYPE_LINE,1);
    addBand(50,PS_SOLID,1,Color.black);
    }

    function main() {
    if(vLSS == null && vSI == null);
    var vC1 = close(0);
    var vO1 = open(-5);
    var vH1 = Math.max(high(),high(-1),high(-2),high(-3),high(-4));
    var vL1 = Math.min(low(),low(-1),low(-2),low(-3),low(-4));
    var vLSSp = ((((vH1 - vO1)+(vC1 - vL1))*100)/((vH1 - vL1)*2));
    var vLSSa = vLSSp(-1);
    var vLSSb = vLSSp(-2);
    var vLSSc = ((vLSSp+vLSSa+vLSSb)/3);
    var vLSS = study1.getValue("vLSSc");
    var vSIc = (((vC1 - vL1)*100)/(vH1 - vL1))
    var vSI = study2.getValue("vSIc");

    return new Array(vLSS,vSI);
    }

    //Regards Kevan

  • #2
    Offered Support...

    First, a few things about your EFS..


    study1 and study2 are not defined anywhere?? This will present a problem in the fact that there is nothing to return for these values (as far as I can see).

    your "IF" condition is incorrect.

    "if(vLSS == null && vSI == null);"

    First vLSS and vSI are not defined before this statement, so this "IF" condition will probably FAIL.

    Second, a proper IF statement should look like...

    if(vLSS == null && vSI == null) {
    .. enclose something in the brackets for the "IF" statement
    }

    Another thing you'll have to contend with is your calls to..

    vLSSp(-1) & vLSSp(-2)...

    You are trying to call past values for a variable that is never defined in your code. Both of these variables are not available in your file - so they can't be accessed.

    These are all the problems I can see in your code. If I can offer more assistance, let me know.

    Brad
    Brad Matheny
    eSignal Solution Provider since 2000

    Comment


    • #3
      Try this...

      I think I've fixed everything for you (if I understand it properly).

      Here you go..

      PHP Code:
      var vC1;
      var 
      vO1;
      var 
      vH1;
      var 
      vL1;
      var 
      vLSSp;

      function 
      preMain() {
       
      setPriceStudy(false);
       
      setStudyTitle("LSS",0);
       
      setStudyTitle("SI",1);
       
      setDefaultBarFgColor(Color.red,0);
       
      setDefaultBarFgColor(Color.blue,1);
       
      setPlotType(PLOTTYPE_LINE,0);
       
      setPlotType(PLOTTYPE_LINE,1);
       
      addBand(50,PS_SOLID,1,Color.black);
      }

      function 
      main(vLen) {
       if (
      vLen == null) { vLen 3; }
      var 
      x;

        
      vLSSp 0;
       for (
      x=0;x>-vLen;x--) {
        
      vC1 close(x);
        
      vO1 open(x-5);
        
      vH1 Math.max(high(x),high(x-1),high(x-2),high(x-3),high(x-4));
        
      vL1 Math.min(low(x),low(x-1),low(x-2),low(x-3),low(x-4));
        
      vLSSp += ((((vH1 vO1)+(vC1 vL1))*100)/((vH1 vL1)*2));

        if (
      == 0) {
         var 
      vSI = (((vC1 vL1)*100)/(vH1 vL1))
        }  
       }
        
      vLSSp vLSSp/vLen;

      return new Array(
      vLSSp,vSI);

      Attached Files
      Brad Matheny
      eSignal Solution Provider since 2000

      Comment


      • #4
        Thank you Doji3333

        I have written out the script and carefully checked it out. It is working well and I thank you for your help as I am still new to the EFS programming. One thing I need to confirm is that the final array of the vLSSp is the smoothed data from the past three bars. I think you have included it by using the following lines
        if (vLen == null) { vLen = 3; }
        and using
        vLSSp = vLSSp/vLen;
        am I correct in interpreting these lines?
        Many thanks once again Doji3333 for you help it is very much appreciated.
        Regards Kevan

        Comment


        • #5
          Confirmation..

          Kevan,

          Yes, you'll see a "for" loop in the code. This is calculating and averaging the vLSSp value for you.

          The other portion of the loop is where it calculates the vLSI value.

          Everything should be OK with my code (I hope).

          Brad
          Brad Matheny
          eSignal Solution Provider since 2000

          Comment


          • #6
            Many Thanks

            Many thanks for your help Brad. I have checked it out and when I back checked the data to other calculations it is just fine. I have modified the original formula slightly to provide different colors on the background and buy and sell arrows to make it easier to read at a glance.
            Regards
            Kevan

            Comment

            Working...
            X