Stock Portfolio Organizer
The ultimate porfolio management solution.
WiseTrader Toolbox
#1 Selling Amibroker Plugin featuring:
Trade Entry Efficiency for Amibroker (AFL)
Got the idea from this site http://shanebrewer.com/2012/11/29/testing-trading-system-entry-methodologies/
Please read the article, he explains it much better than me.
To use the formula, you can drag it onto your chart. Just make sure somewhere in your code, you’ve set the Buy, Sell, Short and Cover as well as BuyPrice, SellPrice, ShortPrice and CoverPrice. If you want to include costs (transaction costs and slippage, just uncomment the total cost – please note, they represent entry and exit costs, so, for example, if your transaction cost [i.e. spread] is 5 pips, choose 10 pips).
This is NOT a trading system, it does NOT generate trades and it does NOT plot anything. It simply shows you how efficient your entries are.
If you need a more detailed look at your trades, consider checking out my other afl, Visual Backtester
http://www.wisestocktrader.com/indicators/4062-visual-backtest-v2.
Feel free to use and distribute this code however you just, just please acknowledge myself and the author of the above-mentioned article.
You can ask me any questions about the code and how it works, but I WON’T modify it for you. I can share ideas, if you’re stuck, but please don’t ask for customisation.
DISCLAIMER: Don’t trade this system! It’s just there as an example. I can’t be held responsible for any results my formula produces. As with anything, take your time to learn how to do something well and right before committing real money.
Thanks and enjoy :)
Sethmo
Screenshots
Indicator / Formula
// /* Variables */ // SetBarsRequired(-2,0); SetChartOptions(0,chartShowArrows|chartShowDates); Buy = Cover = Cross(MA(Close,10), MA(Close,30)); Sell = Short = Cross(MA(Close,30), MA(Close,10)); BuyPrice = SellPrice = ShortPrice = CoverPrice = Close; Plot(C,"\nC", colorBlack, styleCandle); tick_size = IIf(TickSize != 0, TickSize, 1); cost = Param("Total Transaction Cost", 10, 5, 300, 5); Slippage = Param("Total Slippage", 10, 10, 100, 10); totalcost = 0;//(slippage + cost)*TickSize; LongTrades = 0; ShortTrades = 0; //Longs bar1LongProfit = 0; bar5LongProfit = 0; bar10LongProfit = 0; bar15LongProfit = 0; bar20LongProfit = 0; bar1Sell = BarsSince(Buy) == 1; bar5Sell = BarsSince(Buy) == 5; bar10Sell = BarsSince(Buy) == 10; bar15Sell = BarsSince(Buy) == 15; bar20Sell = BarsSince(Buy) == 20; //Shorts bar1ShortProfit = 0; bar5ShortProfit = 0; bar10ShortProfit = 0; bar15ShortProfit = 0; bar20ShortProfit = 0; bar1Cover = BarsSince(Short) == 1; bar5Cover = BarsSince(Short) == 5; bar10Cover = BarsSince(Short) == 10; bar15Cover = BarsSince(Short) == 15; bar20Cover = BarsSince(Short) == 20; // /* Functions */ // for(i = 1; i < BarCount-1; i++) { if(Buy[i]) LongTrades++; if(Short[i]) ShortTrades++; } procedure CalculateLongWinners(numBars) { LongWinners = 0; for(j = numBars; j < BarCount - 1; j++) { if(/*real*/Buy[j-numBars]) { LongProfit[j] = SellPrice[j] - (BuyPrice[j-numBars] + totalcost); if(LongProfit[j] > 0) LongWinners++; } } return LongWinners; } procedure CalculateShortWinners(numBars) { ShortWinners = 0; for(k = numBars; k < BarCount - 1; k++) { if(/*real*/Short[k-numBars]) { ShortProfit[k] = CoverPrice[k] - (ShortPrice[k-numBars] + totalcost); if(ShortProfit[k] > 0) ShortWinners++; } } return ShortWinners; } // /* Long Trades */ // printf("\n=-=-=- TRADE ENTRY EFFICIENCY -=-=-="); printf("\n"); printf("\nExiting after 1, 5, 10, 15, and 20 bars offer you some data to analyze. "); printf("\n\nExiting after 1 bar lets you determine if the entry gets you profitable right away. If not, you may want to tweak your entry setting a little bit."); printf("\n\nExiting after 5 and 10 bars gives the entry a little bit of time to work. You can then compare the 5 and 10 bar data with the 15 and 20 bar data and if your percentages are better for the 15 and 20 bar exits than the 5 and 10 bar exits,\n it means your entry is a little bit too early AND you may want wait a bit to enter."); printf("\n\nIf your 5 and 10 bars exits are good but the 15 and 20 drop off significantly, it can mean you have a good short term entry, but you may want to take profits sooner rather than later."); printf("\n"); printf("\nLong Trades"); printf("\nEntry Efficiency for:"); bar1LongEfficiency = (CalculateLongWinners(1)/LongTrades)*100; bar5LongEfficiency = (CalculateLongWinners(5)/LongTrades)*100; bar10LongEfficiency = (CalculateLongWinners(10)/LongTrades)*100; bar15LongEfficiency = (CalculateLongWinners(15)/LongTrades)*100; bar20LongEfficiency = (CalculateLongWinners(20)/LongTrades)*100; printf("\nBar 1 exit: " + NumToStr(bar1LongEfficiency , 1.2) + "%%"); printf("\nBar 5 exit: " + NumToStr(bar5LongEfficiency , 1.2) + "%%"); printf("\nBar 10 exit: " + NumToStr(bar10LongEfficiency , 1.2) + "%%"); printf("\nBar 15 exit: " + NumToStr(bar15LongEfficiency , 1.2) + "%%"); printf("\nBar 20 exit: " + NumToStr(bar20LongEfficiency , 1.2) + "%%"); printf("\nLongTrades: " + NumToStr(Longtrades,1.0)); printf("\n"); // /* Short Trades */ // bar1ShortEfficiency = (CalculateShortWinners(1)/ShortTrades)*100; bar5ShortEfficiency = (CalculateShortWinners(5)/ShortTrades)*100; bar10ShortEfficiency = (CalculateShortWinners(10)/ShortTrades)*100; bar15ShortEfficiency = (CalculateShortWinners(15)/ShortTrades)*100; bar20ShortEfficiency = (CalculateShortWinners(20)/ShortTrades)*100; printf("\nShort Trades"); printf("\nEntry Efficiency for:"); printf("\nBar 1 exit: " + NumToStr(bar1ShortEfficiency , 1.2) + "%%"); printf("\nBar 5 exit: " + NumToStr(bar5ShortEfficiency , 1.2) + "%%"); printf("\nBar 10 exit: " + NumToStr(bar10ShortEfficiency , 1.2) + "%%"); printf("\nBar 15 exit: " + NumToStr(bar15ShortEfficiency , 1.2) + "%%"); printf("\nBar 20 exit: " + NumToStr(bar20ShortEfficiency , 1.2) + "%%"); printf("\nShortTrades: " + NumToStr(Shorttrades,1.0)); _SECTION_END();
0 comments
Leave Comment
Please login here to leave a comment.
Back