Stock Portfolio Organizer
The ultimate porfolio management solution.
Shares, Margin, CFD's, Futures and Forex
EOD and Realtime
Dividends and Trust Distributions
And Much More ....
WiseTrader Toolbox
#1 Selling Amibroker Plugin featuring:
Advanced Adaptive Indicators
Advanced Pattern Exploration
Neural Networks
And Much More ....
oz trail 2 for Amibroker (AFL)
Copy & Paste Friendly
Back
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 | procedure exit_proc( Buy , BuyPrice ,TrailLevel,StopLevel,TargetLevel) { global BuyHelpArray; global BuyPriceHelpArray; global SellHelpArray; global SellPriceHelpArray; global LongStopTrailArray; global LongTargetArray; global FlagStorageArray; BuyHelpArray=0; BuyPriceHelpArray=0; SellHelpArray=0; SellPriceHelpArray=0; LongStopTrailArray= Null ; LongTargetArray= Null ; FlagStorageArray=0; delay=1; slip=TickSize*0; for (i=1;i< BarCount ;i++) { if ( Buy [i]) { BuyHelpArray[i]=1; BuyPriceHelpArray[i]= BuyPrice [i]+slip; LongStopTrailArray[i]=BuyPriceHelpArray[i]-BuyPriceHelpArray[i]/100*StopLevel; LongStopTrailArray[i-1]=LongStopTrailArray[i]; FlagStorageArray[i]=1; LongTargetArray[i]=BuyPriceHelpArray[i]+BuyPriceHelpArray[i]/100*TargetLevel; for (j=i+delay;j< BarCount ;j++) { LongStopTrailArray[j]= Max ( H [j-1]- H [j-1]/100*TrailLevel,LongStopTrailArray[j-1]); LongTargetArray[j]=LongTargetArray[i]; if (LongStopTrailArray[j]<=LongStopTrailArray[i]) FlagStorageArray[j]=1; else FlagStorageArray[j]=2; if (FlagStorageArray[j]==1 AND L [j]<LongStopTrailArray[j]) { SellHelpArray[j]=1; SellPriceHelpArray[j]= Min ( O [i],LongStopTrailArray[j])-slip; i=j; break ; } else if (FlagStorageArray[j]==2 AND C [j-1]<LongStopTrailArray[j-1]) { SellHelpArray[j]=1; SellPriceHelpArray[j]= O [j]-slip; i=j; break ; } else if ( H [j]>LongTargetArray[j]) { SellHelpArray[j]=1; SellPriceHelpArray[j]= Max ( O [j],LongTargetArray[j])-slip; i=j; break ; } else if (j== BarCount -1) { i= BarCount ; break ; } } } } } //SetBarsRequired(sbrAll,0); TrailLevel= Param ( "Trail stop %" ,20,5,20,1); StopLevel= Param ( "Stop loss %" ,5,5,20,1); TargetLevel= Param ( "Target %" ,10,5,20,1); Buy = Cross ( EMA ( Close ,10), EMA ( Close ,25)); Buy = Ref ( Buy ,-1); BuyPrice = Open ; exit_proc( Buy , BuyPrice ,TrailLevel,StopLevel,targetLevel); Buy =BuyHelpArray; BuyPrice =BuyPriceHelpArray; Sell =SellHelpArray; SellPrice =SellPriceHelpArray; GraphXSpace =5; SetChartBkColor ( ColorRGB (0,0,0)); SetChartOptions (0, chartShowDates ); SetBarFillColor ( IIf ( C > O , colorGreen , IIf ( C <= O , colorRed , colorLightGrey ))); Plot ( C , "Price" , IIf ( C > O , colorDarkGreen , IIf ( C <= O , colorDarkRed , colorLightGrey )),64,0,0,0,0); PlotShapes ( IIf ( Buy , shapeUpArrow , shapeNone ), colorDarkGreen ,0, L ,-15); PlotShapes ( IIf ( Buy , shapeSmallCircle , shapeNone ), colorLightBlue ,0, BuyPrice ,0); PlotShapes ( IIf ( Sell , shapeDownArrow , shapeNone ), colorRed ,0, H ,-15); PlotShapes ( IIf ( Sell , shapeSmallCircle , shapeNone ), colorYellow ,0, SellPrice ,0); Plot (LongStopTrailArray, "" , IIf (FlagStorageArray==1, colorRed , colorBlue ),1); Plot (LongTargetArray, "" , colorGreen ,1); |