/********************************************************* Alexis C. Montenegro © December 2004 Use and/or modify this code freely. If you redistribute it please include this and/or any other comment blocks and a description of any changes you make. **********************************************************/ var fpArray = new Array(); function preMain() { setPriceStudy(true); setStudyTitle("S/R Bands"); setDefaultBarFgColor(Color.lightgrey,0); setDefaultBarFgColor(Color.lightgrey,1); setDefaultBarFgColor(Color.lightgrey,2); setDefaultBarFgColor(Color.lightgrey,3); setDefaultBarFgColor(Color.black,4); setDefaultBarFgColor(Color.lightgrey,5); setDefaultBarFgColor(Color.lightgrey,6); setDefaultBarFgColor(Color.lightgrey,7); setDefaultBarFgColor(Color.lightgrey,8); setDefaultBarThickness(1,0); setDefaultBarThickness(1,1); setDefaultBarThickness(1,2); setDefaultBarThickness(1,3); setDefaultBarThickness(1,4); setDefaultBarThickness(1,5); setDefaultBarThickness(1,6); setDefaultBarThickness(1,7); setDefaultBarThickness(1,8); setPlotType(PLOTTYPE_FLATLINES,0); setPlotType(PLOTTYPE_FLATLINES,1); setPlotType(PLOTTYPE_FLATLINES,2); setPlotType(PLOTTYPE_FLATLINES,3); setPlotType(PLOTTYPE_FLATLINES,4); setPlotType(PLOTTYPE_FLATLINES,5); setPlotType(PLOTTYPE_FLATLINES,6); setPlotType(PLOTTYPE_FLATLINES,7); setPlotType(PLOTTYPE_FLATLINES,8); var x=0; fpArray[x] = new FunctionParameter("Interval", FunctionParameter.STRING); with(fpArray[x++]){ setDefault(); } fpArray[x] = new FunctionParameter("SR1", FunctionParameter.NUMBER); with(fpArray[x++]){ setDefault(0.500); } fpArray[x] = new FunctionParameter("SR2", FunctionParameter.NUMBER); with(fpArray[x++]){ setDefault(0.618); } fpArray[x] = new FunctionParameter("SR3", FunctionParameter.NUMBER); with(fpArray[x++]){ setDefault(1.000); } fpArray[x] = new FunctionParameter("SR4", FunctionParameter.NUMBER); with(fpArray[x++]){ setDefault(1.382); } fpArray[x] = new FunctionParameter("Colors", FunctionParameter.STRING); with(fpArray[x++]){ addOption("ON"); addOption("OFF"); setDefault("ON"); } fpArray[x] = new FunctionParameter("Params", FunctionParameter.BOOLEAN); with(fpArray[x++]){ setName("Show Parameters"); setDefault(false); } } var xHigh = null; var xLow = null; var xClose = null; var High_1 = null; var Low_1 = null; var Close_1 = null; var Rng = null; var vBal = null; var vUp1 = null; var vUp2 = null; var vUp3 = null; var vUp4 = null; var vDn1 = null; var vDn2 = null; var vDn3 = null; var vDn4 = null; var vInterval = null; var bInit = false; function main(Interval,SR1,SR2,SR3,SR4,Colors,Params) { if(bInit == false){ if(isIntraday() && Interval == null) Interval = "D"; else if(isDaily() && Interval == null) Interval = "W"; else if(isWeekly() && Interval == null) Interval = "M"; else if(Interval == null) Interval = getInterval(); vInterval = Interval; xHigh = high(inv(vInterval)); xLow = low(inv(vInterval)); xClose = close(inv(vInterval)); setCursorLabelName(SR4+" ", 0); setCursorLabelName(SR3+" ", 1); setCursorLabelName(SR2+" ", 2); setCursorLabelName(SR1+" ", 3); setCursorLabelName("Bal"+" ", 4); setCursorLabelName(SR1+" ", 5); setCursorLabelName(SR2+" ", 6); setCursorLabelName(SR3+" ", 7); setCursorLabelName(SR4+" ", 8); setShowTitleParameters(eval(Params)); bInit = true; } if(getBarStateInterval(vInterval+"")==BARSTATE_NEWBAR){ High_1 = xHigh.getValue(-1); Low_1 = xLow.getValue(-1); Close_1 = xClose.getValue(-1); Rng = High_1-Low_1; vBal = (High_1+Low_1+Close_1)/3; vUp1 = vBal+(Rng*SR1); vUp2 = vBal+(Rng*SR2); vUp3 = vBal+(Rng*SR3); vUp4 = vBal+(Rng*SR4); vDn1 = vBal-(Rng*SR1); vDn2 = vBal-(Rng*SR2); vDn3 = vBal-(Rng*SR3); vDn4 = vBal-(Rng*SR4); } if(High_1==null||Low_1==null||Close_1==null) return; if(Colors=="ON"){ setBarBgColor(Color.lime,3,vUp1,vUp2); setBarBgColor(Color.yellow,1,vUp3,vUp4); setBarBgColor(Color.red,5,vDn2,vDn1); setBarBgColor(Color.yellow,7,vDn4,vDn3); } return new Array(vUp4,vUp3,vUp2,vUp1,vBal,vDn1,vDn2,vDn3,vDn4); }