/*[[ Name := % bollinger signals Author := Nick Bilak Link := Separate Window := No First Color := Fuchsia First Draw Type := Symbol First Symbol := 108 Use Second Data := Yes Second Color := Aqua Second Draw Type := Symbol Second Symbol := 108 ]]*/ Inputs: CountBars(500); Inputs: mprd(200),bprd(5),bdev(1),bdays(3),bhi(0.8),blo(0.2),rule4(0); var: i(0),buysig(false),sellsig(false),buyaddsig(true),selladdsig(true),exitlong(false),exitshort(false); var: firstTime(true),loopbegin(0),shift(0); Arrays: pb[5](0); SetLoopCount(0); If firstTime then { loopbegin = CountBars; firstTime=False; }; loopbegin++; For shift = loopbegin downto 0 { //get %b //%b is defined as: %b= (Close - Lower Bollinger Band)/(Upper Bollinger Band - Lower Bollinger Band) for i=1 to 4 { pb[i]=(C[i+shift]-iBandsEx(bprd,bdev,0,PRICE_CLOSE,MODE_LOW,i+shift))/(iBandsEx(bprd,bdev,0,PRICE_CLOSE,MODE_HIGH,i+shift)-iBandsEx(bprd,bdev,0,PRICE_CLOSE,MODE_LOW,i+shift)); }; /* Rules for Long Entries: 1.) The market closes above its 200-day moving average. (SMA) 2.) The %b closes below 0.2 for 3 days in a row. 3.) Buy the market at the close (or at the next opening) when rules 1 & 2 are met 4.) Buy an additional unit if/when %b closes below 0.2 for 4 days in a row (1 additional day) 5.) Exit at the close when %b closes above 0.8 Rules for Shorts: 1.) The market closes below its 200 day MA 2.) The %b closes above 0.8 for 3 days in a row 3.) Sell the market at close (or at the next opening) when rules 1 & 2 are met 4.) Sell an additional unit if/when %b closes above 0.8 for 4 days in a row (1 additional day) 5.) Exit at the close when %b closes below 0.2 */ if c[1+shift]>iMA(mprd,MODE_SMA,1+shift) and pb[1]bhi and pb[2]>bhi and pb[3]>bhi then { sellsig=true; buysig=false; }; if buysig then { buysig=false; // if GetIndexValue(2+shift)=0 and GetIndexValue(3+shift)=0 then SetIndexValue(1+shift,l[1+shift]-5*point); }; if sellsig then { sellsig=false; // if GetIndexValue2(2+shift)=0 and GetIndexValue2(3+shift)=0 then SetIndexValue2(1+shift,h[1+shift]+5*point); }; loopbegin--; };