Announcement

Collapse
No announcement yet.

Display problem with Williams' Alligator

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

  • Display problem with Williams' Alligator

    Hi everyone!

    A version of Bill Williams' Alligator indicator was recently uploaded to file sharing, however this version does not smooth the moving averages, which is integral to Williams' Alligator. The code found below attempts to smooth the moving averages in the Alligator, however I am encountering difficulty in implementing it.

    The problem is this: when I load the indicator into the chart, the MAs do not appear and the value for the "Jaws" MA displays "None" in the cursor window. From debugging, I have learned that the code correctly calculates both the SMAs and the Smoothed MAs, however when I try to obtain the values for the Smoothed MAs, the code seems to halt. [See the comments in the code itself.] I have used the getValue function to obtain the values for the Smoothed MAs, because the compiler will not let me pass the Smooth MA variables (i.e. JawsSmoothed, TeethSmoothed, etc.) directly into the offsetSeries function and returns an error that says the function expected a Series object. So, I use the getValue function to remedy this error message, however, being unaccustomed with JavaScript, I don't understand the compiler's objection and do not know if this is the correct solution.

    I would really, really appreciate some help with this. It would be beneficial for eSignal users too, if we could publish an accurate version of Williams' indicator, at least how it is published in Trading Chaos, Second Edition.

    Thanks!

    Best,
    Jake

    PHP Code:
    var bInit false;


    function 
    preMain() {

        
    setPriceStudy(true);
        
    setStudyTitle("Alligator");
        
        
    setCursorLabelName("Jaws"0);
        
    setCursorLabelName("Teeth"1);
        
    setCursorLabelName("Lips"2);
        
        
    setDefaultBarFgColor(Color.blue0);
        
    setDefaultBarFgColor(Color.red1); 
        
    setDefaultBarFgColor(Color.green2);
        
    setDefaultBarThickness2); 
        
    setDefaultBarThickness2); 
        
    setDefaultBarThickness2); 
        
    }

    var 
    midPoint null;
    var 
    JawsSMA null;
    var 
    TeethSMA null;
    var 
    LipsSMA null;
    var 
    TeethSmoothed null;
    var 
    JawsSmoothed null;
    var 
    LipsSmoothed null;
    var 
    Jaws null;
    var 
    Teeth null;
    var 
    Lips null;

    function 
    main(JawsLengthTeethLengthLipsLengthJawsOffsetTeethOffsetLipsOffset) {

        if (
    JawsLength == nullJawsLength 13;
        if (
    TeethLength == nullTeethLength 8;
        if (
    LipsLength == nullLipsLength 5;
        if (
    JawsOffset == nullJawsOffset 8;
        if (
    TeethOffset == nullTeethOffset 5;
        if (
    LipsOffset == nullLipsOffset 3;
        
        if ( 
    bInit == false) {
            
            
    midPoint hl2();
            
            
    //Calculate SMAs.
            
    JawsSMA sma(JawsLengthmidPoint);
            
    TeethSMA sma(TeethLengthmidPoint);
            
    LipsSMA sma(LipsLengthmidPoint); 
            
    debugPrint("Jaws SMA = " JawsSMA "\n");
            
            
    //Calculate Smoothed MAs.
            
    JawsSmoothed = (( JawsSMA * (JawsLength 1) ) + midPoint ) / JawsLength;
            
    TeethSmoothed = (( TeethSMA * (TeethLength 1) ) + midPoint ) / TeethLength;
            
    LipsSmoothed = (( LipsSMA * (LipsLength 1) ) + midPoint ) / LipsLength;
            
    debugPrint("JawsSmoothed = " JawsSmoothed "\n");
            
            var 
    jaws 0
            var 
    teeth 0;
            var 
    lips 0;
            
    debugPrint("JawsSmoothed2 = " JawsSmoothed "\n");
            
            
    //This is the problem area.  When I compile, the following "JawsSmoothed3" does not print to the formula output window,
            //which means the following part of the code is messing up things.
            
    jaws JawsSmoothed.getValue(0);
            
    teeth TeethSmoothed.getValue(0);
            
    lips LipsSmoothed.getValue(0);
            
    debugPrint("JawsSmoothed3 = " JawsSmoothed "\n");
            
            
    //Offset MAs.
            
    Jaws offsetSeries(jJawsOffset);
            
    Teeth offsetSeries(tTeethOffset);
            
    Lips offsetSeries(lLipsOffset);
            
    bInit true;
        }
        
        var 
    0;
        var 
    0;
        var 
    0;
        
        
    Jaws.getValue(0);
        
    Teeth.getValue(0);
        
    Lips.getValue(0);

        return new Array(
    JTL);


  • #2
    Re: Display problem with Williams' Alligator

    Jake
    You may not need to rewrite the script but only implement a few changes to the formula provided in FileShare to obtain the results you are looking for.
    As a first step change the default values set in the FunctionParameters in lines 57, 76 and 94 to 13, 8 and 5 respectively
    Change also the values in lines 121, 123 and 125 to 13, 8 and 5 respectively.
    Then replace the following lines of code in the script (ie lines 132-134)
    PHP Code:
    xEMA1 offsetSeries(ema(LengthSlowxhl2), OffsetSlow);
            
    xEMA2 offsetSeries(ema(LengthMediumxhl2), OffsetMedium);
            
    xEMA3 offsetSeries(ema(LengthFastxhl2), OffsetFast); 
    with the following
    PHP Code:
    xEMA1 offsetSeries(ema((2*LengthSlow)-1xhl2), OffsetSlow);
            
    xEMA2 offsetSeries(ema((2*LengthMedium)-1xhl2), OffsetMedium);
            
    xEMA3 offsetSeries(ema((2*LengthFast)-1xhl2), OffsetFast); 
    Save the formula and then load it in the chart
    Alex


    Originally posted by sunyata_trader
    Hi everyone!

    A version of Bill Williams' Alligator indicator was recently uploaded to file sharing, however this version does not smooth the moving averages, which is integral to Williams' Alligator. The code found below attempts to smooth the moving averages in the Alligator, however I am encountering difficulty in implementing it.

    The problem is this: when I load the indicator into the chart, the MAs do not appear and the value for the "Jaws" MA displays "None" in the cursor window. From debugging, I have learned that the code correctly calculates both the SMAs and the Smoothed MAs, however when I try to obtain the values for the Smoothed MAs, the code seems to halt. [See the comments in the code itself.] I have used the getValue function to obtain the values for the Smoothed MAs, because the compiler will not let me pass the Smooth MA variables (i.e. JawsSmoothed, TeethSmoothed, etc.) directly into the offsetSeries function and returns an error that says the function expected a Series object. So, I use the getValue function to remedy this error message, however, being unaccustomed with JavaScript, I don't understand the compiler's objection and do not know if this is the correct solution.

    I would really, really appreciate some help with this. It would be beneficial for eSignal users too, if we could publish an accurate version of Williams' indicator, at least how it is published in Trading Chaos, Second Edition.

    Thanks!

    Best,
    Jake

    PHP Code:
    var bInit false;


    function 
    preMain() {

        
    setPriceStudy(true);
        
    setStudyTitle("Alligator");
        
        
    setCursorLabelName("Jaws"0);
        
    setCursorLabelName("Teeth"1);
        
    setCursorLabelName("Lips"2);
        
        
    setDefaultBarFgColor(Color.blue0);
        
    setDefaultBarFgColor(Color.red1); 
        
    setDefaultBarFgColor(Color.green2);
        
    setDefaultBarThickness2); 
        
    setDefaultBarThickness2); 
        
    setDefaultBarThickness2); 
        
    }

    var 
    midPoint null;
    var 
    JawsSMA null;
    var 
    TeethSMA null;
    var 
    LipsSMA null;
    var 
    TeethSmoothed null;
    var 
    JawsSmoothed null;
    var 
    LipsSmoothed null;
    var 
    Jaws null;
    var 
    Teeth null;
    var 
    Lips null;

    function 
    main(JawsLengthTeethLengthLipsLengthJawsOffsetTeethOffsetLipsOffset) {

        if (
    JawsLength == nullJawsLength 13;
        if (
    TeethLength == nullTeethLength 8;
        if (
    LipsLength == nullLipsLength 5;
        if (
    JawsOffset == nullJawsOffset 8;
        if (
    TeethOffset == nullTeethOffset 5;
        if (
    LipsOffset == nullLipsOffset 3;
        
        if ( 
    bInit == false) {
            
            
    midPoint hl2();
            
            
    //Calculate SMAs.
            
    JawsSMA sma(JawsLengthmidPoint);
            
    TeethSMA sma(TeethLengthmidPoint);
            
    LipsSMA sma(LipsLengthmidPoint); 
            
    debugPrint("Jaws SMA = " JawsSMA "\n");
            
            
    //Calculate Smoothed MAs.
            
    JawsSmoothed = (( JawsSMA * (JawsLength 1) ) + midPoint ) / JawsLength;
            
    TeethSmoothed = (( TeethSMA * (TeethLength 1) ) + midPoint ) / TeethLength;
            
    LipsSmoothed = (( LipsSMA * (LipsLength 1) ) + midPoint ) / LipsLength;
            
    debugPrint("JawsSmoothed = " JawsSmoothed "\n");
            
            var 
    jaws 0
            var 
    teeth 0;
            var 
    lips 0;
            
    debugPrint("JawsSmoothed2 = " JawsSmoothed "\n");
            
            
    //This is the problem area.  When I compile, the following "JawsSmoothed3" does not print to the formula output window,
            //which means the following part of the code is messing up things.
            
    jaws JawsSmoothed.getValue(0);
            
    teeth TeethSmoothed.getValue(0);
            
    lips LipsSmoothed.getValue(0);
            
    debugPrint("JawsSmoothed3 = " JawsSmoothed "\n");
            
            
    //Offset MAs.
            
    Jaws offsetSeries(jJawsOffset);
            
    Teeth offsetSeries(tTeethOffset);
            
    Lips offsetSeries(lLipsOffset);
            
    bInit true;
        }
        
        var 
    0;
        var 
    0;
        var 
    0;
        
        
    Jaws.getValue(0);
        
    Teeth.getValue(0);
        
    Lips.getValue(0);

        return new Array(
    JTL);

    Comment


    • #3
      Alexis,

      Thank you so much for your response! I altered the code, loaded the indicator, and compared the output to a chart Williams has in Trading Chaos and they are nearly identical. My question for you is: is the equation that I tried to program, which is provided by Williams at the end of Trading Chaos in code that he write for TradeStation, equivalent to the exponential MA equation you provided? Williams' equation is a modification of a simple moving average.

      Thanks again.

      Best,
      Jake

      Comment


      • #4
        Jake
        I am not familiar with the specific code you mention but I have compared the adjusted exponential averages I suggested to you with those of the Alligator study provided by some other applications (such as for example Metastock which uses Wilder's Smoothing) and the values match
        Alex


        Originally posted by sunyata_trader
        Alexis,

        Thank you so much for your response! I altered the code, loaded the indicator, and compared the output to a chart Williams has in Trading Chaos and they are nearly identical. My question for you is: is the equation that I tried to program, which is provided by Williams at the end of Trading Chaos in code that he write for TradeStation, equivalent to the exponential MA equation you provided? Williams' equation is a modification of a simple moving average.

        Thanks again.

        Best,
        Jake

        Comment


        • #5
          Jake
          FWIW here are two screenshots one captured from Metastock in which I am running the built-in Alligator study and the other from eSignal using the formula with the modifications I suggested. As you can see the plots are identical
          Alex



          Comment


          • #6
            Williams Alligator

            Any chance you can post or link to the complete updated efs for those of us challenged by script modification?

            Thanks.
            OpaBert

            Comment


            • #7
              Hello Opabert,

              Please take a look at this formula in our Library, ABillW_Alligator.efs.
              Jason K.
              Project Manager
              eSignal - an Interactive Data company

              EFS KnowledgeBase
              JavaScript for EFS Video Series
              EFS Beginner Tutorial Series
              EFS Glossary
              Custom EFS Development Policy

              New User Orientation

              Comment


              • #8
                note that the 21, 13, 8 lengths used in the posted ABillW_Alligator.efs (as at 2009-02-12) do not match the Williams values.
                The Williams values (13, 8, 5) are the Wilder lengths, to convert to the lengths for an "ordinary" ema you multiply by 2 and subtract 1 (as per Alex code mods below), so the values in this script should be 25, 15, 9.

                Comment

                Working...
                X