Announcement

Collapse
No announcement yet.

My First EFS - Doesn't work, darn it. Help?

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

  • My First EFS - Doesn't work, darn it. Help?

    Here is what I'm trying to create:

    A Price Study of....

    3 times a WeightedMA of the TrueRange with a len 21

    Where the "True Range" is the greater of one of the following:

    • The difference between today’s high and today’s low
    • The difference between today’s high and yesterday’s close,
    or
    • The difference between today’s low and yesterday’s close.

    For reference, this is Andrew Abraham's "volitility Indicator" from his article in S&C volume 16:9 (425-427) in 1998 I think, if that helps.

    After doing several searches, I have found that my major problem seems to be the inability of EFS to do a MAStudy on a user defined variable. I understand that I must make an array of my variable "vhighest". Not sure how to populate it.

    Below is my very first EFS code I've ever written.
    ---------------------------
    function preMain() {
    setPriceStudy(true);
    setStudyTitle("TTT");
    setCursorLabelName("TTT");
    }

    function main(vMALength) {
    if (vMALength == null){
    vMALength = 21;
    }

    var vtodayshigh = call("getTodayOHLC.efs", "High");
    var vtodayslow = call("getTodayOHLC.efs", "Low");
    var vyesterdaysclose = call("getPrevOHLC.efs", "Close");

    var vtodayshighlow = Math.abs(vtodayshigh - vtodayslow);
    var vtodayshighclose = Math.abs(vtodayshigh - vyesterdaysclose);
    var vtodayslowclose = Math.abs(vtodayslow - vyesterdaysclose);

    var vhigher = Math.max(vtodayshighlow, vtodayshighclose);
    var vhighest = Math.max(vhigher, vtodayslowclose);

    var study2 = new MAStudy(vMALength,0,vhighest,MAStudy.MA,MAStudy.WE IGHTED);
    var vTTT = study2.getValue(MAStudy.MA);

    if(vTTT == null) {
    return;
    }
    return (vTTT * 3);
    }
    ---------------------------------

    Thank you for any help you can provide!
    Jim Fisk

  • #2
    Jim
    You cannot use custom variables with EFS1 builtin studies. That can be easily done in EFS2 which will be available with version 7.9 currently in the last stages of beta testing. For more information on EFS2 visit the EFS 2 Development Forum.
    Anyhow you can use the MA-EMA-WMAof_template2.efs which is available here and that will compute the simple, exponential or weighted average of any variable.
    Having said that are you trying to calculate this on multiple intervals ie compute the efs on daily data while running it on intraday charts? If that is the case I would strongly suggest you look into using EFS2 as that will greatly simplify the task that can otheriwse be considerably complex. If not then you don't need to use the call() functions to retrieve those values, just use high(), low() and close(-1).
    Also when computing the vhighest variable you can do that in one step rather than two ie
    var vhighest = Math.max(vtodayshighlow, vtodayshighclose, vtodayslowclose);
    Hope this helps
    Alex

    Comment


    • #3
      Thank you! Looks like EFS2 will be a good upgrade. In the meantime, I'll try your suggestions.

      Thank you

      Comment


      • #4
        moonwizard
        FWIW in EFS2 you can replace the whole section of code you wrote to compute the true range with the atr() function set to length 1 and use that as the source to the weighted moving average.
        If you run the enclosed script you will see that the plot of wma(21,atr(1)) is exactly the same as that of the weighted moving average of the external function which computes the true range.
        Alex

        PHP Code:
        function preMain() {
            
        setStudyTitle("True Range");
            
        setCursorLabelName("TR1",0);
            
        setCursorLabelName("TR2",1);
            
        setDefaultBarFgColor(Color.blue,0);
            
        setDefaultBarFgColor(Color.red,1);
        }
         
        function 
        main() {
         
            var 
        study1 wma(21,efsInternal("calcTR"));
            var 
        study2 wma(21,atr(1));
         
            return new Array (
        study1 ,study2);
        }
         
        function 
        calcTR(){
         
            var 
        vtodayshighlow Math.abs(high(0) - low(0));
            var 
        vtodayshighclose Math.abs(high(0) - close(-1));
            var 
        vtodayslowclose Math.abs(low(0) - close(-1));
            var 
        vhighest Math.max(vtodayshighlowvtodayshighclosevtodayslowclose);
         
            return 
        vhighest;

        Comment


        • #5
          The attached EFS2 formula computes the indicator referenced by moonwizard which was originally created by Andrew Abraham in his article "Trading the trend".
          In the image below the formula is applied to the same daily chart shown in the article (at that time JPM was Chase Manhattan) with identical results.
          eSignal version 7.9 is required to run the efs.
          Alex

          Attached Files

          Comment

          Working...
          X