Stock Portfolio Organizer
The ultimate porfolio management solution.
WiseTrader Toolbox
#1 Selling Amibroker Plugin featuring:
Power of Stocks 5 EMA Strategy with Signals using Loop and Backtest Snippets for Amibroker (AFL)
Based on Power of Stocks 5 EMA Strategy is said in https://youtu.be/uu3zGIXaG8g Buy 15 min , Short 5 min.
This Strategy is only good for BANKNIFTY Short trading . Last two year (Oct ’20 to Sep ’22) gives 24000 points without commission and slippage. Accuracy 30%.
When Backtesting in Amibroker if same candle hit SL and entry , it counted as zero loss. This strategy get more trades entry and exit in same bar. So i made it backtestable in 1 minute.
It have option to select Stock | Index. For Stock it have separate Entry , Sqoff timing, Quantity is calculated as per Initial Equity divided by Position Size (Amibroker use Compounding in backtest, increase position size when increase in Capital, So limit number of Max Open Positions as per your requirement). for Index it is good to backtest with 1 quantity with out commission as it is mostly trade in options. As per Net Profit in points it can considered as good or not.
Trade Prices BuyPrice, ShortPrice, SellPrice, CoverPrice are used with ValueWhen Entry. It work for some strategies. Most Strategies it will change if next time entry condition valid. So Entry Exit Signals and Price code in loop is required. This AFL Signals are coded in loop and easily learn. Thanks to Yogesh Dalvi (Telegram @dyogesh) helped me to code this loop.
Screenshots
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 | /*VALLKKOTTAI MURUGAN THUNAI*\ Telegram @easysimpletrade Website https://easysimpletrade.blogspot.com Youtube https://www.youtube.com/channel/UCaAH8Um7QCIPsOXH47zHAfQ */ /* Based on Power of Stocks 5 EMA Strategy is said in https://youtu.be/uu3zGIXaG8g Buy 15 min , Short 5 min. Thanks to Yogesh Dalvi (Telegram @dyogesh) helped me to code this loop. */ _SECTION_BEGIN ( "POS 5 EMA" ); BTSI = ParamList ( "Analysing" , "Stock|Index" ,1); SOTIMES = ParamTime ( "Stock - Square OFF" , "14:59:00" ); EATIMES = ParamTime ( "Stock - Entry After" , "09:19:00" ); EBTIMES = ParamTime ( "Stock - Entry Before" , "14:35:00" ); SOTIMEI = ParamTime ( "Index - Square OFF" , "15:14:00" ); EATIMEI = ParamTime ( "Index - Entry After" , "09:19:00" ); EBTIMEI = ParamTime ( "Index - Entry Before" , "14:45:00" ); SOTIME = IIf (BTSI == "Stock" , SOTIMES, SOTIMEI); EATIME = IIf (BTSI == "Stock" , EATIMES, EATIMEI); EBTIME = IIf (BTSI == "Stock" , EBTIMES, EBTIMEI); TDVAL = Param ( "Position Size" , 20000,5000,125000,5000); INEQ = Param ( "Initial Equity" , 50000,1000,1000000,1000); RRR = Param ( "Risk Reward Ratio" , 3 , 1 ,10, 0.5); TFI = Param ( "Time Frame I" , 5 , 1 , 75); TFII = Param ( "Time Frame II" , 15 , 1 , 75); _SECTION_END (); H1 = TimeFrameGetPrice ( "H" , in1Minute *TFI,-1); L1 = TimeFrameGetPrice ( "L" , in1Minute *TFI,-1); H2 = TimeFrameGetPrice ( "H" , in1Minute *TFII,-1); L2 = TimeFrameGetPrice ( "L" , in1Minute *TFIi,-1); TimeFrameSet ( in1Minute *TFI); EMA51 = EMA ( C ,5); TimeFrameRestore (); TFIR = TFI/ Interval ()*60; EMA510 = TimeFrameExpand (EMA51, in1Minute *TFI,expandFirst); EMA51 = Ref (EMA510,-TFIR); TimeFrameSet ( in1Minute *TFII); EMA52 = EMA ( C ,5); TimeFrameRestore (); TFIIR = TFII/ Interval ()*60; EMA520 = TimeFrameExpand (EMA52, in1Minute *TFII,expandFirst); EMA52 = Ref (EMA520,-TFIR); RISK1 = H1 - L1; RISK2 = H2 - L2; ETIME = TimeNum () > EATIME AND TimeNum () < EBTIME; iBuy = H2 < EMA52 AND Cross ( H , H2) AND ETIME; iShort = L1 > EMA51 AND Cross (L1, L ) AND ETIME; //Exit----------------------------------------------------------------------------- iBENT = iBTGT = iBSL = 0; iSENT = iSTGT = iSSL = 0; iInTrade = 0; iTimeNum = TimeNum (); iInTradeArray = 0; Buy = Sell = Short = Cover = BuyPrice = SellPrice = ShortPrice = CoverPrice = 0; BENT = SENT = BTGT = STGT = BSL = SSL = BSLE = SSLE = BTGTE = STGTE = SQOFF = 0; for (i = 0 ; i <= BarCount -1 ; i++) { if (iInTrade == 1) { if ( High [i] > iBTGT) { Sell [i] = 1; SellPrice [i] = iBTGT; BTGTE[i] = 1; } else if ( Low [i] < iBSL) { Sell [i] = 1; SellPrice [i] = iBSL; BSLE[i] = 1; } else if (iTimeNum[i] > SOTIME) { Sell [i] = 1; SellPrice [i] = Close [i]; SQOFF[i] = 1; } } if (iInTrade == -1) { if ( Low [i] < iSTGT) { Cover [i] = 1; CoverPrice [i] = iSTGT; STGTE[i] = 1; } else if ( High [i] > iSSL) { Cover [i] = 1; CoverPrice [i] = iSSL; SSLE[i] = 1; } else if (iTimeNum[i] > SOTIME ) { Cover [i] = 1; CoverPrice [i] = Close [i]; SQOFF[i] = 1; } } if (iBuy[i] AND iInTrade == 0) { Buy [i] = 1; iBENT = H2[i]; iBSL = L2[i]; iBTGT = H2[i] + (RRR*RISK2[i]); iInTrade = 1; BuyPrice [i] = iBENT; } if (iShort[i] AND iInTrade == 0) { Short [i] = 1; iSENT = L1[i]; iSSL = H1[i]; iSTGT = L1[i] - (RRR*RISK1[i]); iInTrade = -1; ShortPrice [i] = iSENT; } if (iInTrade != 0) { BENT[i] = iBENT; BSL[i] = iBSL; BTGT[i] = iBTGT; SENT[i] = iSENT; SSL[i] = iSSL; STGT[i] = iSTGT; iInTradeArray[i] = iInTrade; } if ( Sell [i] OR Cover [i]) { iInTrade = 0; } } BVALID = IIf (iInTradeArray == 1 ,1,0); SVALID = IIf (iInTradeArray == -1 ,1,0); BTGT = Prec (BTGT,1); STGT = Prec (STGT,1); //Backtest----------------------------------------------------------------------------------------- NDO = TimeFrameGetPrice ( "O" , inDaily ); SQTY = round (TDVAL/NDO); IQTY = 1; QTY = IIf (BTSI == "Stock" , SQTY, IQTY); Margin = IIf (BTSI == "Stock" , 20, 100); Comison = IIf (BTSI == "Stock" , 0.04, 0); MXOP = INEQ*5/TDVAL; SetOption ( "InitialEquity" ,INEQ); SetOption ( "MaxOpenPositions" ,MXOP); SetOption ( "AccountMargin" ,Margin); SetOption ( "CommissionMode" ,1); SetOption ( "CommissionAmount" ,Comison); SetOption ( "ActivateStopsImmediately" , True ); //SetOption("AllowSameBarExit",True); SetPositionSize (QTY, spsShares ); //Exploration--------------------------------------------------------------------------------------------------------------- BWATCH = H1 < EMA52 AND H < H2; SWATCH = L1 > EMA51 AND L > L1; WatchStatus = WriteIf (BWATCH, "Watch for Buy" , WriteIf (SWATCH, "Watch for Sell" , "" )); Filter = 1; //Buy OR Short OR BWATCH OR SWATCH; AddColumn ( IIf ( Buy ,66, IIf ( Short ,83,32) ), "Signal" , formatChar, colorYellow , IIf ( Buy , colorGreen , IIf ( Short , colorRed , colorDefault ) )); AddTextColumn (WatchStatus, "Watch" ); AddColumn ( IIf (BVALID,BENT, IIf (SVALID,SENT, Null )), "Entry" ); AddColumn ( IIf (BVALID,BSL, IIf (SVALID,SSL, Null )), "Stop Loss" ); AddColumn ( IIf (BVALID,BTGT, IIf (SVALID,STGT, Null )), "Target" ); //Chart------------------------------------------------------------------------------------------------------------------------------------------------------------------------ _N (Title = StrFormat ( "{{NAME}} - {{INTERVAL}} {{DATE}} O %g, H %g, L %g, C %g {{VALUES}}" , O , H , L , C )); SetChartOptions ( 1, chartShowDates , chartGridMiddle, 0, 0, 0 ); SetBarFillColor ( IIf ( C > O , ColorRGB ( 0, 75, 0 ), IIf ( C <= O , ColorRGB ( 75, 0, 0 ), colorLightGrey ) ) ); Plot ( C , "" , IIf ( C > O , ColorRGB ( 0, 255, 0 ), IIf ( C <= O , ColorRGB ( 255, 0, 0 ), colorLightGrey ) ), 64, Null , Null , 0, 0, 1 ); GfxTextOut ( "Entry " + IIf (BVALID,BENT, IIf (SVALID,SENT, Null )), 700, 20); GfxTextOut ( "SL " + IIf (BVALID,BSL, IIf (SVALID,SSL, Null )), 700, 40); GfxTextOut ( "Target " + IIf (BVALID,BTGT, IIf (SVALID,STGT, Null )), 700, 60); PlotShapes ( IIf ( Buy , shapeSquare , shapeNone ), colorGreen , 0, L , Offset=-20); PlotShapes ( IIf ( Buy , shapeSquare , shapeNone ), colorLime , 0, L , Offset=-30); PlotShapes ( IIf ( Buy , shapeUpArrow , shapeNone ), colorWhite , 0, L , Offset=-25); PlotShapes ( IIf ( Short , shapeSquare , shapeNone ), colorRed , 0, H , Offset=20); PlotShapes ( IIf ( Short , shapeSquare , shapeNone ), colorOrange , 0, H , Offset=30); PlotShapes ( IIf ( Short , shapeDownArrow , shapeNone ), colorWhite , 0, H , Offset=-25); PlotShapes ( IIf ( Sell AND BTGTE, shapeDownTriangle , shapeNone ), colorLime , 0, H , Offset=-30); PlotShapes ( IIf ( Sell AND BSLE, shapeCircle , shapeNone ), colorLime , 0, H , Offset=30); PlotShapes ( IIf ( Cover AND STGTE, shapeUpTriangle , shapeNone ), colorOrange , 0, L , Offset=-30); PlotShapes ( IIf ( Cover AND SSLE, shapeCircle , shapeNone ), colorOrange , 0, L , Offset=-30); PlotShapes ( IIf (SQOFF AND ( Sell OR Cover ), shapeSquare , shapeNone ), colorWhite , 0, L , Offset=-30); Plot ( EMA520, "EMA5 15min" , colorLime , styleStaircase | styleNoLabel ); Plot ( EMA510, "EMA5 5min" , colorRed , styleStaircase | styleNoLabel ); |
12 comments
Leave Comment
Please login here to leave a comment.
Back
Nice One!!!
Two EMA Lines are plotting, can you explain which one is 5 EMA Green/Red?
But Wherever Arrow marks plotted there the candle touching EMA Line which should not be
The result for nifty 5min Timeframe is amazing, Why do say that it works only for banknifty? Also thanks for the afl.
Sorry. there is an issue with the afl. I’ll ask admin replace the afl or i repost again
Obul! Green is 15 min 5EMA which is for buy. Red is 5min which is for sell
@EasySimpleTrade I have updated the formula with the new one you posted.
@EasySimpleTrade I think whatever mistake you did with that afl was good mistake because now the profits are reduced. WHat mistake did you do?
this formula is repainting ?
as per notes u said buy in 15 mins and sell in 5 mins
do we run in 5min scan ?
@administrator thanks admin, as updated post is in pending , i thought it not updated.
@viraldalal yes there is one issue for repaint in line 55 change TFIR to TFIIR .
EMA52 = Ref(EMA520,-TFIIR); Thanks for identifying
@viraldalal If you run in one minute it give accurate backtest result. or you can run in 5 minute
thank you for your inputs and solving problem in 1 day