Stock Portfolio Organizer
The ultimate porfolio management solution.
WiseTrader Toolbox
#1 Selling Amibroker Plugin featuring:
ATR stop loss indicator for Amibroker (AFL)
I have taken through internet only. But it is a good indicator… Try out..
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 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 | // Trade simulation. Helps you to record your real trades and test new trading approaches without any programming skills. // Copyright Abnash Singh 20th February 2012 // Modified April 29,2013 - for allowing last bar trades and for excluding ATR stop optionally, when own stop loss system is used. // You can download and use this AFL, but do not make any changes in the copyright information, even if you make changes in the code // Upto 9 trades can be plotted in any time frame. // Once installed on Amibroker insert the vertical Study lines with labels b1, b2 etc for Buy signals AND s1, s2 etc for Short signals AND // e1, e2 etc for the exit signals. The AFL automatically recognises the context of the exit for a Buy OR Sell Signal. // Remember that the Buy AND Sell signals are generated one bar after the vertical position of the Study line. // This has no practical impact on entering your trade signals. // Next you can modify the trade entry AND exit values, if required in the parameter windows AND you have your trade journal ready! // To re-use the AFL for another trading session, please remember to delete all the existing studies, // by right clicking in the display area AND selecting delete al studies AND resetting the parameter window. SetBarsRequired (1000, 0 ); setbuy = ParamTrigger ( "Buy" , "Buy" ); setsell = ParamTrigger ( "Sell" , "Sell" ); setshort = ParamTrigger ( "Short" , "Short" ); setcover = ParamTrigger ( "Cover" , "Cover" ); clear = ParamTrigger ( "Clear" , "Clear" ); clearall = ParamTrigger ( "Clear All" , "Clear All" ); showcandlechart= ParamList ( "Show Candle chart" , "YES|NO" ); useATRstop= ParamToggle ( "ATR stop to be used ?" , "No|Yes" ,1); stylecndl= ParamList ( "Bar/Candle chart" , "BAR|CANDLE" ); BarLum1 = Param ( "Bar Color Intensity" , 8, 0, 10,01); LineColor = ColorBlend( ColorRGB (50,60,60), ColorRGB (50,60,60), BarLum1); UpBarColor = ColorBlend( ColorRGB (5,36,5), ColorRGB (10,75,10), BarLum1); DnBarColor = ColorBlend( ColorRGB (36,5,5), ColorRGB (75,10,10), BarLum1); tp1= Param ( "Trade 1 price " ,0,0,20000); ep1= Param ( "Exit 1 price " ,0,0,20000); tp2= Param ( "Trade 2 price " ,0,0,20000); ep2= Param ( "Exit 2 price " ,0,0,20000); tp3= Param ( "Trade 3 price " ,0,0,20000); ep3= Param ( "Exit 3 price " ,0,0,20000); tp4= Param ( "Trade 4 price " ,0,0,20000); ep4= Param ( "Exit 4 price " ,0,0,20000); tp5= Param ( "Trade 5 price " ,0,0,20000); ep5= Param ( "Exit 5 price " ,0,0,20000); tp6= Param ( "Trade 6 price " ,0,0,20000); ep6= Param ( "Exit 6 price " ,0,0,20000); tp7= Param ( "Trade 7 price " ,0,0,20000); ep7= Param ( "Exit 7 price " ,0,0,20000); tp8= Param ( "Trade 8 price " ,0,0,20000); ep8= Param ( "Exit 8 price " ,0,0,20000); tp9= Param ( "Trade 9 price " ,0,0,20000); ep9= Param ( "Exit 9 price " ,0,0,20000); bi = BarIndex (); qty = LastValue ( bi ); y = Year (); m = Month (); d = Day (); r = Hour (); e = Minute (); sby = SelectedValue ( y ); sbm = SelectedValue ( m ); sbd = SelectedValue ( d ); sbr = SelectedValue ( r ); sbe = SelectedValue ( e ); qty = LastValue ( bi ); Varname = Name ()+ sby + sbm + sbd + sbr + sbe; if ( setbuy ) { StaticVarSet ( Varname, 1 ); } if ( setsell ) { StaticVarSet ( Varname, -1 ); } if ( setshort ) { StaticVarSet ( Varname, -2 ); } if ( setcover ) { StaticVarSet ( Varname, 2 ); } if ( clear ) { StaticVarRemove ( Varname ); } if ( clearall ) { for ( i = 0; i < qty; i++ ) StaticVarRemove ( Name ()+y[i] + m[i] + d[i] + r[i] + e[i]); } Buy = Sell = Short = Cover = exit =0; profit=sessprofit=priceatbuy=priceatshort=priceatexit=tradecount=lastsig=pricetouse=maxprofit=lastmax=0; shape=xp=ep=cp=0; tradeline= Null ; BarColor = IIf ( Close > Open , UpBarColor, DnBarColor); SetBarFillColor (BarColor); avp=( O + C )/2; //you can choose to have avp=c instead of average if (stylecndl== "BAR" )stylec= styleBar ; else stylec= styleCandle ; if (showcandlechart== "YES" ) { Plot ( C , "Close" , colorWhite , styleNoTitle | stylec); } avp=( O + C )/2; //ATR Stop begin Multiple = Param ( "Multiple" , 3, 0.5, 10, 0.1 ); // How many ATR's to be allowed below the highest high since latest "buy" bar ATRPeriods = Param ( "ATR Periods" , 20, 1, 50, 1 ); // How many periods to use for the ATR Showtarget = ParamList ( "Show Target Milestones " , "Yes|No" ); Step = Param ( "Step for target milestones" , 20, 0,50, 10 ); // Step for profit progress, default is 20 points. stopArray = Null ; atrArray = ATR ( ATRPeriods ); HHArray = Null ; LLArray = Null ; exitArray = Null ; trendDirection = 0; //ATr Stop end dmy= ATR (10); for (i=1;i< BarCount ;i++) { sig = StaticVarGet ( Name ()+y[i] + m[i] + d[i] + r[i] + e[i]); if ( sig == 1 ) Buy [ i ] = True ; if ( sig == -2 ) Short [ i ] = True ; if (sig==-1 OR sig==2)exit[i]= True ; if (Lastsig!=0 AND ! Buy [i] AND ! Short [i])tradeline[i]=tradeline[i-1]; if ( Buy [i] OR Short [i]) { tradecount=tradecount+1; if (tradecount==1){xp=tp1;ep=ep1;} else if (tradecount==2){xp=tp2;ep=ep2;} else if (tradecount==3){xp=tp3;ep=ep3;} else if (tradecount==4){xp=tp4;ep=ep4;} else if (tradecount==5){xp=tp5;ep=ep5;} else if (tradecount==6){xp=tp6;ep=ep6;} else {xp=0;ep=0;} } if ( Buy [i]) { // we just triggered a long trade. Set up starting values stopArray[i] = High [i] - ( Multiple * atrArray[i] ); HHArray[i] = High [i]; // initialize the highest high array trendDirection = 1; // going long. Base bar flag is now set. if (xp>0)priceatbuy=tradeline[i]=xp; else priceatbuy=tradeline[i]=avp[i]; //defaulting price to average price. if (Lastsig==-1) { profit=priceatshort-priceatbuy; sessprofit=sessprofit+profit; PlotText ( WriteVal (profit,1.0),i, H [i]+10, colorYellow ); } Lastsig=1; } if ( Short [i]) { // we just triggered a short trade. Set up starting values stopArray[i] = Low [i] + ( Multiple * atrArray[i] ); LLArray[i] = Low [i]; // initialize the lowest low array trendDirection = 0 - 1; // going short. Base bar. // PlotText("1",i,H[i]+10,colorWhite); if (xp>0)priceatshort=tradeline[i]=xp; else priceatshort=tradeline[i]=avp[i]; //defaulting price to average price. if (Lastsig==1) { profit=priceatshort-priceatbuy; sessprofit=sessprofit+profit; PlotText ( WriteVal (profit,1.0),i, H [i]+2*dmy[i], colorYellow ); } Lastsig=-1; } if (Lastsig==0)tradeline[i]= Null ; if (exit[i]) { if (ep>0)priceatexit=ep; else priceatexit=avp[i]; if (Lastsig==1) { profit= priceatexit-priceatbuy; Sell [i]=1; } else if (Lastsig==-1) { profit= priceatshort-priceatexit; Cover [i]=1; } sessprofit=sessprofit+profit; PlotText ( WriteVal (profit,1.0),i, H [i]+2*dmy[i], colorYellow ); Lastsig=profit=0; } if (Lastsig==1)Cp[i]=avp[i]-priceatbuy; else if (Lastsig==-1)Cp[i]=priceatshort-avp[i]; exitArray[i] = 0; if ( trendDirection > 0 AND useatrstop) { // keep track of the highest high, highest close, highest low, etc.. if ( trendDirection > 1 ) { // We are in the trade (2nd day or later) if ( Low [i] < stopArray[i-1] OR exit[i]) { //stop got hit. Reset the trade. trendDirection = 0; // OK. wait until we trigger another trade. exitArray[i] = 1; if (Lastsig==1) { if (ep>0)pricetouse=ep; else pricetouse=avp[i]; profit=pricetouse-priceatbuy; sessprofit=sessprofit+profit; PlotText ( WriteVal (profit,1.0),i, H [i]+2*dmy[i], colorYellow ); } Lastsig=0; } else { // keep track of the HHV since trade was entered. if ( High [i] > HHArray[i-1] ) HHArray[i] = High [i]; else HHArray[i] = HHArray[i-1]; // Compute the stop based on the HHV. stopArray[i] = HHArray[i] - ( Multiple * atrArray[i] ); } } trendDirection = trendDirection + 1; } if ( trendDirection < 0 AND useatrstop) { // keep track of the lowest low, lowest close, lowest high, etc.. if ( trendDirection < 0 - 1 ) { // We are in the trade (2nd day or later) if ( High [i] > stopArray[i-1] OR exit[i] ) { // our stop got hit. Reset the trade. trendDirection = 0; exitArray[i] = 0 - 1; if (Lastsig==-1) { if (ep>0)pricetouse=ep; else pricetouse=avp[i]; profit=priceatshort-pricetouse; sessprofit=sessprofit+profit; PlotText ( WriteVal (profit,1.0),i, H [i]+2*dmy[i], colorYellow ); } Lastsig=0; } else { // keep track of the LLV since trade was entered. if ( Low [i] < LLArray[i-1] ) LLArray[i] = Low [i]; else LLArray[i] = LLArray[i-1]; // Compute the stop based on the LLV. stopArray[i] = LLArray[i] + ( Multiple * atrArray[i] ); } } trendDirection = trendDirection - 1; } if ( trendDirection == 0 ) { stopArray[i] = 0; LLArray[i] = 0; HHArray[i] = 0; } if ( Buy [i] OR Short [i])Maxprofit=lastmax=0; if (Cp[i]>Maxprofit)Maxprofit=Cp[i]; //Profit milestones in steps of 20. Can be modified to be in steps of ATR's by replacing 20 with a variable ATR value //Profits 2 contains the running profits. This can be used to devise a peak profit based exit. if (exitarray[i]==0 AND int (Maxprofit/step)*step>Lastmax AND Maxprofit>=step AND showtarget== "Yes" ) { Lastmax= int (Maxprofit/step)*step; PlotText ( WriteVal ( int (Maxprofit/step)*step,1.0),i, H [i]+2*ATRarray[i], colorYellow ); } } if (Lastsig!=0)sessprofit=sessprofit+Cp[i-1]; Plot (avp, "Mid" , ColorRGB (120,120,120), styleNoTitle ); Plot (Tradeline, "Trade price" , colorBlue ); shapebuy = IIf ( Buy , shapeUpArrow , Null ); Shapesell= IIf ( Sell ,shapeHollowDownArrow, Null ); shapeshort = IIf ( Short , shapeDownArrow , Null ); Shapecover= IIf ( Cover , shapeHollowUpArrow , Null ); shape2= IIf (exit, shapeDownArrow , Null ); PlotShapes ( shapeshort, colorRed , 0, High ); PlotShapes ( shapebuy, colorGreen , 0, Low ); PlotShapes ( shapesell, colorBlue , 0, High ); PlotShapes ( shapecover, colorBlue , 0, Low ); PlotText ( WriteVal (sessprofit,1.0)+ "\n" + WriteVal (tradecount,1.0),i, H [ BarCount -1]+2*dmy[ BarCount -1], colorYellow ); if (useATRstop) { Plot ( IIf (stopArray!=0,stoparray, Null ), "StopLine" , ParamColor ( "Stopline Color:" , colorYellow ), ParamStyle ( "Stop Style" , styleDashed ) ); PlotShapes ( abs ( exitArray )* shapeHollowCircle , colorYellow , 0, ValueWhen ( stopArray, stopArray, 1 ), 0 ); } Title = Date ()+ " Trade Plotter " + Interval (format=2)+ " " + Name ()+ " O " + WriteVal ( O ,1.2)+ " H " + WriteVal ( H ,1.2)+ " L " + WriteVal ( L ,1.2)+ " C " + WriteVal ( C ,1.2)+ " Mid price " + WriteVal (avp,1.2)+ EncodeColor ( colorYellow )+ " Trade Price " + WriteVal (tradeline,1.2); |
1 comments
Leave Comment
Please login here to leave a comment.
Back
howlong it will take to approve?