/******************************************************************** * Copyright Garth Doverspike 2001 * frmGMAcc - Acceleration per Bill Williams * * No warranty expressed or implied on functionality - Use at your own risk * If you find a bug please email me ********************************************************************/ function preMain() { setStudyTitle("GMACC"); setCursorLabelName("GMACC"); /* * Set the properties of the default bar. These will be the * properties of any bar for which style, color, thickness is * not specificed. */ setDefaultBarStyle(PS_SOLID); /* setStudyMax(100); setStudyMin(-100); */ setDefaultBarFgColor(Color.black); setDefaultBarBgColor(Color.white); setDefaultBarThickness(2); setPlotType(PLOTTYPE_HISTOGRAM); } /***** Variables to remember across iterations to main. ****/ var vLastRet = 0; var vLastMom = 0; /* * Momentum Acceleration */ function main() { var vhighs; var vlows; var vLongLength = 34; var vShortLength = 5; var vMALength = 5; var i; var vASum; var x; var vSymbol; var vIsGreen; var vSum = new Array(5); var vShortSum = new Array(5) ; if ((vSymbol = getSymbol()) == null){ return; } vDiffMA = 0; /* * We loop on the GMOM to get a MA of it */ vASum = 0; for (x = 0; x < vMALength; x ++){ /* * Get highs and lows for 34 bars for each x */ if (x == 0){ vhighs = high (x, -vLongLength); vlows = low (x, -vLongLength); } else { vhighs = high (-x, -vLongLength); vlows = low (-x, -vLongLength); } /* * Check for NULL returns */ if (vhighs == null || vlows == null) { return; } /* * Calc the two MA's */ vSum[x] = 0; vShortSum[x] = 0; for (i = 0; i < vLongLength; i++) { vSum[x] += (((vhighs[i] - vlows[i])/2) + vlows[i]); if (i == vShortLength - 1){ vShortSum [x]= vSum[x]; } } /* * vSum now 34 day MA */ vSum[x] = vSum[x]/vLongLength; /* * vShortSum = 5 day MA */ vShortSum[x] = vShortSum[x]/vShortLength; /* * vSum now = MOM */ vSum[x] = vShortSum[x] - vSum[x]; /* * vASum = Sum of 5 day MOM */ vASum = vASum + vSum[x]; } /* * Now 5 day MA of MOM */ vASum = vASum/vMALength; /* * Now difference between MOM and 5 day MA */ vASum = vSum[0] - vASum; /* * Determine if MOM for this period is green, and set LastMom */ if (vSum[0] < vLastMom){ vIsGreen = 0; } else { vIsGreen = 1; } vLastMom = vSum[0]; switch (vSymbol){ case ("$INDU"): vASum = vASum/100; break; case ("$COMPQ"): break; default: break; } if (vASum < vLastRet){ setBarFgColor(Color.maroon); if (vIsGreen == 0){ setBarBgColor(Color.red); } } else { setBarFgColor(Color.green); if (vIsGreen == 1){ setBarBgColor(Color.lime); } } vLastRet = vASum; return (vASum); }