\n
<\/span>function <\/span>ParamOptimize<\/span>( <\/span>description<\/span>, <\/span>defaultVal<\/span>, <\/span>minv<\/span>, <\/span>maxv<\/span>, <\/span>step <\/span>)\r { \r return <\/span>Optimize<\/span>(<\/span>description<\/span>, <\/span>Param<\/span>(<\/span>description<\/span>,<\/span>defaultVal<\/span>, <\/span>minv<\/span>, <\/span>maxv<\/span>, <\/span>step <\/span>), <\/span>minv<\/span>, <\/span>maxv<\/span>, <\/span>step <\/span>); \r }\r\r<\/span>BlankBars <\/span>= <\/span>10<\/span>; <\/span>\/\/ Set to the number set in preferences\r\r<\/span>Buy <\/span>= <\/span>Sell <\/span>= <\/span>Short <\/span>= <\/span>Cover <\/span>= <\/span>Pos <\/span>= <\/span>0<\/span>;\r<\/span>Periods <\/span>= <\/span>ParamOptimize<\/span>( <\/span>"Periods"<\/span>, <\/span>3<\/span>, <\/span>3<\/span>, <\/span>30<\/span>, <\/span>1 <\/span>);\r<\/span>Width <\/span>= <\/span>ParamOptimize<\/span>( <\/span>"Width"<\/span>, <\/span>1<\/span>, <\/span>0<\/span>, <\/span>5<\/span>, <\/span>0.1 <\/span>);\r<\/span>BBTOp <\/span>= <\/span>BBandTop<\/span>( <\/span>H<\/span>, <\/span>Periods<\/span>, <\/span>Width <\/span>); <\/span>\/\/ Note H is used instead of the tradional C\r<\/span>BBBot <\/span>= <\/span>BBandBot<\/span>( <\/span>L<\/span>, <\/span>Periods<\/span>, <\/span>Width <\/span>); <\/span>\/\/ Note L is used instead of the tradional C\r\r<\/span>Plot<\/span>( <\/span>BBTop<\/span>, <\/span>"BBTop"<\/span>, <\/span>colorBlue<\/span>, <\/span>styleLine <\/span>);\r<\/span>Plot<\/span>( <\/span>BBBOt<\/span>, <\/span>"BBBot"<\/span>, <\/span>colorBlue<\/span>, <\/span>styleLine <\/span>);\r<\/span>Plot<\/span>( <\/span>C<\/span>, <\/span>""<\/span>, <\/span>1<\/span>, <\/span>128 <\/span>);\r\r<\/span>BI <\/span>= <\/span>BarIndex<\/span>();\r<\/span>start <\/span>= <\/span>Status<\/span>( <\/span>"firstvisiblebarindex" <\/span>) - <\/span>BI<\/span>[<\/span>0<\/span>] - <\/span>BlankBars<\/span>;\r<\/span>end <\/span>= <\/span>Status<\/span>( <\/span>"lastvisiblebarindex" <\/span>) - <\/span>BI<\/span>[<\/span>0<\/span>] - <\/span>BlankBars<\/span>;\r<\/span>LBI <\/span>= <\/span>LastValue<\/span>( <\/span>BarIndex<\/span>() );\r\rfor ( <\/span>b <\/span>= <\/span>LBI<\/span>; <\/span>b <\/span>> <\/span>Periods<\/span>; <\/span>b<\/span>-- )\r{\r if ( <\/span>L<\/span>[<\/span>b<\/span>] <= <\/span>BBBot<\/span>[<\/span>b<\/span>] AND <\/span>pos <\/span><= <\/span>0 <\/span>)\r {\r <\/span>pos <\/span>= <\/span>1<\/span>;\r <\/span>Buy<\/span>[<\/span>b<\/span>] = <\/span>True<\/span>;\r <\/span>BuyPrice<\/span>[<\/span>b<\/span>] = <\/span>BBBot<\/span>[<\/span>b<\/span>];\r }\r else\r if ( <\/span>H<\/span>[<\/span>b<\/span>] >= <\/span>BBTop<\/span>[<\/span>b<\/span>] AND <\/span>Pos <\/span>>= <\/span>0 <\/span>)\r {\r <\/span>Pos <\/span>= -<\/span>1<\/span>;\r <\/span>Sell<\/span>[<\/span>b<\/span>] = <\/span>True<\/span>;\r <\/span>SellPrice<\/span>[<\/span>b<\/span>] = <\/span>BBTop<\/span>[<\/span>b<\/span>];\r }\r}\r\r<\/span>Short <\/span>= <\/span>Sell<\/span>;\r<\/span>ShortPrice <\/span>= <\/span>SellPrice<\/span>;\r\r<\/span>Cover <\/span>= <\/span>Buy<\/span>;\r<\/span>CoverPrice <\/span>= <\/span>