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
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.blue, 0);
setDefaultBarFgColor(Color.red, 1);
setDefaultBarFgColor(Color.green, 2);
setDefaultBarThickness( 2, 0 );
setDefaultBarThickness( 2, 1 );
setDefaultBarThickness( 2, 2 );
}
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(JawsLength, TeethLength, LipsLength, JawsOffset, TeethOffset, LipsOffset) {
if (JawsLength == null) JawsLength = 13;
if (TeethLength == null) TeethLength = 8;
if (LipsLength == null) LipsLength = 5;
if (JawsOffset == null) JawsOffset = 8;
if (TeethOffset == null) TeethOffset = 5;
if (LipsOffset == null) LipsOffset = 3;
if ( bInit == false) {
midPoint = hl2();
//Calculate SMAs.
JawsSMA = sma(JawsLength, midPoint);
TeethSMA = sma(TeethLength, midPoint);
LipsSMA = sma(LipsLength, midPoint);
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(j, JawsOffset);
Teeth = offsetSeries(t, TeethOffset);
Lips = offsetSeries(l, LipsOffset);
bInit = true;
}
var J = 0;
var T = 0;
var L = 0;
J = Jaws.getValue(0);
T = Teeth.getValue(0);
L = Lips.getValue(0);
return new Array(J, T, L);
}
Comment