/******************************************************************** * Copyright Garth Doverspike 2001 * frmGFact - Fractals 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() { setPriceStudy(true); setStudyTitle("GFAC"); setCursorLabelName("GFAC"); /* * 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); setDefaultBarFgColor(Color.black); setDefaultBarThickness(2); setPlotType(PLOTTYPE_LINE); } /***** Variables to remember across iterations to main. ****/ var vUlabel = 0; /* * FRAC Up and Down */ function main() { var vhighs; var vlows; var vLookback = 5; var vLookup; var i; var skip = 0; var vLabel; /* * TODO: Add an option for lines drawn on setup vs. signal (we are doing setup now). * Option for line color */ /* * Get highs and lows for 5 bars */ vhighs = high (0, -vLookback); vlows = low (0, -vLookback); /* * Check for NULL returns */ if (vhighs == null || vlows == null) { return; } vLookup = 1; /* * Up Frac */ if (vhighs[2] > vhighs[1] && vhighs[2] > vhighs[0]){ for (i = 0; i <= vLookup; i++){ if (vhighs[2] < vhighs [i+3]){ skip = 1; break; } else if (vhighs[2] == vhighs[i+3]){ vLookup = i+2; vLookback = vLookback + i + 1; vhighs = high (0, -vLookback); continue; } } /* * Draw it */ if (skip == 0){ for (i = 1; i < (vLookup + 2); i++){ vLabel = "FUP" + vUlabel++; drawLineRelative(-i, vhighs[i], -i-1, vhighs[i+1], PS_SOLID, 3, Color.red, vLabel); } } } /* * Down FRAC (remember they can be both up and down) */ vLookup = 1; vLookback = 5; if (vlows[2] < vlows[1] && vlows[2] < vlows[0]){ for (i = 0; i <= vLookup; i++){ if (vlows[2] > vlows [i+3]){ return; } else if (vlows[2] == vlows[i+3]){ vLookup = i+2; vLookback = vLookback + i + 1; vlows = low (0, -vLookback); continue; } } /* * Draw it */ for (i = 1; i < (vLookup + 2); i++){ vLabel = "FDOWN" + vUlabel++; drawLineRelative(-i, vlows[i], -i-1, vlows[i+1], PS_SOLID, 3, Color.green, vLabel); } } }