Stock Portfolio Organizer
The ultimate porfolio management solution.
WiseTrader Toolbox
#1 Selling Amibroker Plugin featuring:
gen_brkout for Amibroker (AFL)
This afl copy from www.lurama125.com, supporting gen_cross_conf.afl
You need to put the following two afls in the include directory:
http://wisestocktrader.com/indicatorpasties/120-liba-afl
http://wisestocktrader.com/indicatorpasties/119-pebslib-afl
Screenshots
Similar Indicators / Formulas
Indicator / Formula
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 | //Gen_BRKOUT.AFL #include_once <LibA.afl>; pebstime = Hour ()*60+ Minute (); OptimizerSetEngine ( "cmae" ); Lastticktime = Param ( "Lastticktime" ,9999,0,9999,1); //If like in SA there is a closing tick instead of a closing bar, then we execute immediately there instead of the usual delay of 1 bar Firsttradetime = Param ( "FirstTradeTime" ,0,0,9999,1); //Never do any trade before this time Lasttradetime = Param ( "LastTradeTime" ,9999,0,9999,1); //Never do any trade after this time Firstsignaltime = Param ( "FirstSignalTime" ,0,0,9999,1); //do not trade on signals that trigger before this time, remember trade is entered usually 1 bar delay after signal Lastsignaltime = Param ( "LastSignalTime" ,9999,0,9999,1); //do not trade on signals that trigger after this time, remember trade is entered usually 1 bar delay after signal ExitatClose = ParamToggle ( "Exit at Close of Day" , "No|Yes" ); xxxdelay = 1-(pebstime>=Lastticktime)*1; //Ignore the delay when last tick, otherwise that trade will only happen next morning firststoptime = Param ( "First Stoptime" ,0,0,9999,1); Laststoptime = Param ( "Last Stoptime" ,9999,0,9999,1); TradeSL = Param ( "Trade stoploss" ,99999,0,99999,1); TradeSP = Param ( "Trade stopprofit" ,99999,0,99999,1); DaySL = Param ( "Day stoploss" ,99999,0,99999,1); DaySP = Param ( "Day stopprofit" ,99999,0,99999,1); MonthSL = Param ( "Month stoploss" ,99999,0,99999,1); MonthSP = Param ( "Month stopprofit" ,99999,0,99999,1); n_fn1_par = Param ( "Channel n" ,20,1,100,1); n_fn2_par = Param ( "Channelwidth n" ,2,1,10,1); n_fn1_opt = ParamToggle ( "Optimize Channel n" , "Yes|No" ); n_fn2_opt = ParamToggle ( "Optimize Channelwidth" , "Yes|No" ); if (n_fn1_opt==1){ n_fn1= n_fn1_par; } else { n_fn1 = Optimize ( "Channel n" ,n_fn1_par,1,100,1); } if (n_fn2_opt==1){ n_fn2 = n_fn2_par; } else { n_fn2 = Optimize ( "Channelwidth n" ,n_fn2_par,1,20,0.25); } fn1 = ParamList ( "Top BRK" , "HHV|BOLLINGER|KELTNER|FunctionHigh" ); fn2 = ParamList ( "Bottom BRK" , "LLV|BOLLINGER|KELTNER|FunctionLow" ); target_fn = ParamList ( "TargetFn" , "OHLC4|O|H|L|C|ema|sma|brkema|brkema2|brkema3|brkema4|frama|kama|tsf|dema|tema|wilder|hull" ); n_targetfn_par = Param ( "n_TargetFn" ,20,1,100,1); n_TargetFn_opt = ParamToggle ( "Optimize n_TargetFn" , "Yes|No" ); if (n_TargetFn_opt==1){ n_targetfn = n_TargetFn_par; } else { n_targetfn = Optimize ( "n_TargetFn" ,n_targetFn_par,1,100,1); } Cntxt = ParamList ( "Context" , "None|Contextfilter|Contextfilter2" ); symbol = ParamStr ( "Basesymbol" , Name ()); // trade on next bar open SetTradeDelays ( 0, 0, 0, 0 ); BuyPrice = SellPrice = Open ; ShortPrice = CoverPrice = Open ; //Points only PositionSize = MarginDeposit = 1; SetForeign (symbol); switch (target_fn){ case "OHLC4" : xxx = ( O + H + L + C )/4; break ; case "O" : xxx = O ; break ; case "H" : xxx= H ; break ; case "L" : xxx= L ; break ; case "C" : xxx = C ; break ; case "ema" : xxx = EMA ( C ,n_targetfn); break ; case "sma" : xxx = MA ( C ,n_targetfn); break ; case "brkema" : xxx = brkema(n_targetfn); break ; case "brkema2" : xxx = brkema2(n_targetfn); break ; case "brkema3" : xxx = brkema3(n_targetfn); break ; case "brkema4" : xxx = brkema4(n_targetfn); break ; case "frama" : xxx = frama(n_targetfn); break ; case "kama" : xxx = kama(n_targetfn,2,30); break ; case "tsf" : xxx = TSF ( C ,n_targetfn); break ; case "dema" : xxx = DEMA ( C ,n_targetfn); break ; case "tema" : xxx = TEMA ( C ,n_targetfn); break ; case "wilder" : xxx = Wilders ( C ,n_targetfn); break ; case "hull" : xxx = HullMA( C ,n_targetfn,0); break ; } switch (fn1){ case "HHV" : _TRACE ( "top hhv" ); aaa = Ref ( HHV ( H ,n_fn1),-1); break ; case "BOLLINGER" : _TRACE ( "top bollinger" ); aaa = BBandTop (xxx,n_fn1,n_fn2); break ; case "KELTNER" : _TRACE ( "top keltner" ); CenterLine = MA ( xxx, n_fn1 ); aaa = CenterLine + n_fn2 * ATR ( n_fn1 ); break ; case "FunctionHigh" : _TRACE ( "functionhigh" ); aaa = Ref ( HHV (xxx,n_fn1),-1); break ; } switch (fn2){ case "LLV" : _TRACE ( "bottom llv" ); bbb = Ref ( LLV ( L ,n_fn1),-1); break ; case "BOLLINGER" : _TRACE ( "bottom bollinger" ); bbb = BBandBot (xxx,n_fn1,n_fn2); break ; case "KELTNER" : _TRACE ( "bottom keltner" ); CenterLine = MA ( xxx, n_fn1 ); bbb = CenterLine - n_fn2 * ATR ( n_fn1 ); break ; case "FunctionLow" : _TRACE ( "functionlow" ); bbb = Ref ( LLV (xxx,n_fn1),-1); break ; } Buysignal = (xxx>aaa) AND (pebstime>=firstsignaltime) AND (pebstime<=Lastsignaltime); Sellsignal = (xxx<bbb) AND (pebstime>=firstsignaltime) AND (pebstime<=Lastsignaltime) OR ((pebstime>=Lastticktime) AND ExitAtClose ); Shortsignal = (xxx<bbb) AND (pebstime>=firstsignaltime) AND (pebstime<=Lastsignaltime); Coversignal = (xxx>aaa) AND (pebstime>=firstsignaltime) AND (pebstime<=Lastsignaltime) OR ((pebstime>=Lastticktime) AND ExitAtClose); //is this the best spot to remove the extra signals? i think so because after contextfilters you expect and do not want to remove consecutive buy or short signals Buysignal = ExRem (Buysignal,Shortsignal); Shortsignal = ExRem (Shortsignal,Buysignal); Longstate = Flip (Buysignal,(Sellsignal OR Shortsignal)); Shortstate = Flip (Shortsignal,(Coversignal OR BuySignal)); Totalstate = Longstate*1+Shortstate*(-1); totalstate = Ref (totalstate,-xxxdelay); //apply trade delay before applying contextfilter as contextfilters already have trade delay built in switch (Cntxt){ case "None" : break ; case "Contextfilter" : Totalstate = Contextfilter(Totalstate); break ; case "Contextfilter2" : Totalstate = Contextfilter2(Totalstate); break ; } //apply stops; delay already built in here correctly? still need to adjust for lastticktime 0 delay totalstate = TradeSLSP(totalstate,1,tradeSL,tradeSP,firststoptime,Laststoptime,Lastticktime); totalstate = DaySLSP(totalstate,1,DaySL,DaySP,firststoptime,Laststoptime,Lastticktime); totalstate = MonthSLSP(totalstate,1,MonthSL,MonthSP,firststoptime,Laststoptime,Lastticktime); Buysignal = (totalstate>0) AND (pebstime>=firsttradetime) AND (pebstime<=Lasttradetime); Sellsignal = (totalstate<=0) AND (pebstime>=firsttradetime) AND (pebstime<=Lasttradetime); Shortsignal = (totalstate<0) AND (pebstime>=firsttradetime) AND (pebstime<=Lasttradetime); Coversignal = (totalstate>=0) AND (pebstime>=firsttradetime) AND (pebstime<=Lasttradetime); Buysignal = ExRem (Buysignal,Shortsignal); Shortsignal = ExRem (Shortsignal,Buysignal); RestorePriceArrays (); Buy = Buysignal; Sell = Sellsignal; Short = Shortsignal; Cover = Coversignal; Longstate = Flip (Buysignal,(Sellsignal OR Shortsignal)); Shortstate = Flip (Shortsignal,(Coversignal OR BuySignal)); Totalstate = Longstate*1+Shortstate*(-1); //this totalstate already has the trade delay in PlotOHLC (0,0,Totalstate,Totalstate, _DEFAULT_NAME (), IIf (Totalstate<0, colorRed , colorGreen ), styleCloud ); //Plot(aaa,"aaa",ParamColor( "Color", colorCycle ), ParamStyle("Style") ); //Plot(bbb,"bbb",ParamColor( "Color", colorCycle ), ParamStyle("Style") ); SetChartBkColor ( colorBlack ); |
2 comments
Leave Comment
Please login here to leave a comment.
Back
this afl not working
Gen_BRKOUT.AFL
totalstate = contextfilter(Totalstate);
break;
case"contextfilter2":
Totalstate = contextfilter2(
^
error 30.
sysntax error
it will not working, if you do not copy liba.afl & pebslib.afl and paste them to folder amibroker/formulas/include……
try again.