/******************************************************************** * Copyright Garth Doverspike 2001 * frmGMom - Momentum 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("GMOM"); setCursorLabelName("GMOM"); /* * 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); setDefaultBarThickness(2); setPlotType(PLOTTYPE_HISTOGRAM); } /***** Variables to remember across iterations to main. ****/ var vLastRet = 0; /* * Momentum */ function main() { var vhighs; var vlows; var vLookback = 34; var vShort = 5; var vSum; var vShortSum; var i; var vSymbol; /* * Get highs and lows for 34 bars */ vhighs = high (0, -vLookback); vlows = low (0, -vLookback); /* * Check for NULL returns */ if (vhighs == null || vlows == null) { return; } if ((vSymbol = getSymbol()) == null){ return; } /* * Calc the two MA's */ vSum = 0; vShortSum = 0; for (i = 0; i < vLookback; i++) { vSum += (((vhighs[i] - vlows[i])/2) + vlows[i]); if (i == (vShort - 1)){ vShortSum = vSum; } } vSum = vSum/vLookback; vShortSum = vShortSum/vShort; switch (vSymbol){ case ("$INDU"): vSum = (vShortSum - vSum)/100; break; case ("$COMPQ"): vSum = (vShortSum - vSum)/10; break; default: vSum = (vShortSum - vSum); } if (vSum < vLastRet){ setBarFgColor(Color.red); } else { setBarFgColor(Color.green); } vLastRet = vSum; return (vSum); }