Announcement

Collapse
No announcement yet.

setting efs output

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • setting efs output

    I'm new to EFS, and I've been following the examples as best I can, but I'm stumped. Can you help me modify the MA Cross Over study? Instead of setting the BarBgColor, I'd like to generate either a "1" or "-1" in a non-price study for those same conditions. I have already coded a more complex study, but I'm missing the basics on how to return a value based on my conditions.

  • #2
    jobe1
    Without seeing the efs you are referring to it is not possible to provide a specific code example.
    Regardless enclosed below you can see two basic scripts that will return 1, -1 or 0 depending on the state of the two averages and the conditions used to determine that state.
    The first example assumes you want to return a 1 or -1 when the faster average is above/below the slower one.
    The second example instead assumes you want to identify the crossover point and assign to that a 1 or -1 depending on the direction of the crossover. The results are shown in the enclosed chart.
    Alex

    PHP Code:
    var Avg1 null;
    var 
    Avg2 null;
     
    function 
    main(){
     
        if(
    Avg1==nullAvg1 sma(10);
        if(
    Avg2==nullAvg2 sma(21);
        
        if(
    Avg1.getValue(0)==null || Avg2.getValue(0)==null) return;
        
        if(
    Avg1.getValue(0)>Avg2.getValue(0)){
            var 
    Signal 1;
        } else if(
    Avg1.getValue(0)<Avg2.getValue(0)){
            var 
    Signal = -1;
        } else {
            var 
    Signal 0;
        }
        
        return 
    Signal;

    PHP Code:
    var Avg1 null;
    var 
    Avg2 null;
     
    function 
    main(){
     
        if(
    Avg1==nullAvg1 sma(10);
        if(
    Avg2==nullAvg2 sma(21);
        
        if(
    Avg1.getValue(-1)==null || Avg2.getValue(-1)==null) return;
        
        if(
    Avg1.getValue(0)>Avg2.getValue(0)&&Avg1.getValue(-1)<Avg2.getValue(-1)){
            var 
    Signal 1;
        } else if(
    Avg1.getValue(0)<Avg2.getValue(0)&&Avg1.getValue(-1)>Avg2.getValue(-1)){
            var 
    Signal = -1;
        } else {
            var 
    Signal 0;
        }
        
        return 
    Signal;

    Comment


    • #3
      thank you

      Thank you very much. I realize this is the very basics, and I appreciate your taking the time to post this. I should be able to build on this now that I'm over the hump.

      Comment


      • #4
        For curiousity's sake, do you know how to achieve the same results using the formula wizard? My aim is to get away from the wizard, but I'm interested in how that works too. I've indicated a "non-price study" and entered the conditions, but not sure where and how to tell the wizard to make 1s and -1s.

        This post should definately be over in the EFS Wizard forum, but since I started it here, thought I would leave it here. Thanks again for your help.

        Comment


        • #5
          jobe1
          It is not possible to write a functionally similar code with the Formula Wizard because the script requires creating user defined variables which cannot be done in the Formula Wizard.
          Anyhow should you encounter any problems in applying the logic I suggested earlier to the efs you were referring to then either post that script or a link to it and someone may be able to assist you.
          Alex

          Comment


          • #6
            You are the best, Alexis. I've already assimilated the concept and applied it to my study. Works great! It would have driven me mad trying to get the wizard to do that.

            Comment


            • #7
              jobe1
              Thank you for the feedback and for the kind words
              Alex

              Comment

              Working...
              X