The KPL Swing is a simple trend following mechanical trading system w hich automates the entry and exit.
The trading system is extremely simple and easy to use, works across multiple time frames and does not require any in-depth knowledge of TA. It is somewhat s imilar to the turtle trading system.
The trading or investing logic is simple.... buy new highs (strength) and sel l new lows (weakness). The default entry or decision level for long positions is a close above 20 days highest high.
The system follows a trailing stoploss for exit with profitable trades. No ta rgets are given as no one knows how high (or low) a stock can move. Profits are whatever the market gives. A trailing stoploss locks in the gains and removes em otions from trading.
Respect for stoplosses is a mandatory requirement. If you cannot follow stopl osses, you should stay out of the market completely.
Caveat:
Caveat: this indicator works best with indices and highly li quid stocks. It is not recommended for stocks with with poor liquidity as freak trad es often distort the value of the breakout level (high or low).
Code for Amibroker AFL is posted at the end of this page.
- Default setting: N=20. Higher values (30, 50, 100 etc) will give fewer but far more reliable trades. - Timeframe and charts: daytraders/ swing traders (30 min), positional traders ( daily) and long term investors (weekly/ monthly). - Smaller the timeframe or N, higher the number of trades and whipsaws. - Ignore signals if market is rangebound. Eg., if market is trading within last month's range, ignore signal on daily chart. - Entry trade: Initiate a long trade when indicator gives a BUY (stock closes fo r the first time above the 20 days or 20 weeks highest high).
- Stoploss: Keep a "hard stoploss" few points below the Signal bar LOW. - Trend reversal: Exit trade when indicator gives a SELL (Exit long positions).< br> - Position sizing: always follow this to determine trade quantity...this will au tomatically limit losses to a predefined value irrespective of stock price. - Always paper trade before trading with actual cash.
- You can use a ATR based trailing stoploss (highly recommended). This is a buil t-in indicator in Amibroker and will give excellent returns / fast exits. Use AT R(20). - You can use the same code in Scanner mode to generate Buy/ Sell signals.
Position sizing - How much quantity to buy? Use posit ion sizing and limit loss to Rs.500/- per trade.
Qtty = 500/ (Purchase price - hard stoploss).
Eg. You want to buy a stock trading at Rs.100/- with a stoploss Rs.90. The qu antity you shd trade is 500/(100-90) = 50 shares. So if your stoploss gets hit, you shd exit and your max loss will be Rs.500/-.
And finally, the code....Amibroker AFLs
Note: the current bar is always dynamic so for intraday purposes, you should evaluate the signal only after the current bar is complete.
_SECTION_BEGIN("KPL Swing"); Swing"); //Copyright Kamalesh Langote. Email:[email protected]. Visit http://www.vfmdirec t.com/kplswing for latest code and updates //Copy & paste formula in NotePad and save file as "kplswing.afl" in C: Program Files > Amibroker > Formulas > Custom folder. To use just drag and drop from Ind icator list (custom) on price chart no=Param( "Swing", 20, 1, 100 ); res=HHV(H,no); sup=LLV(L,no); avd=IIf(C>Ref(res,-1),1,IIf(Ctsl,colorB "Ribbon",IIf(C>tsl,colorBlue,colorRed),styleOwnSc lue,colorRed),styleOwnScale|styleArea|styleNoL ale|styleArea|styleNoL abel, -0.5, 100 ); // arrows code Buy=Cross(C,Ref(res,-1)); Sell=Cross(Ref(sup,-1),C); shape=Buy*shapeUpArrow + Sell*shapeDownArrow; PlotShapes(shape,colorBlack,0,IIf(Buy,Low,High)); // scanner code Buy=Cross(C,tsl); Sell=Cross(tsl,C);
_SECTION_END();
Metastock users: I am no longer supporting metastock....
Metastock formula.... note - arrows will not appear in metas tock.
{Copyright Kamalesh Langote. Email:[email protected] More details at http://www. vfmdirect.com/kplswing} no:=Input("Swing/ Bars", 1, 55, 20); res:=HHV(H,no); sup:=LLV(L,no); avd:=If(C>Ref(res,-1),1,If(C0,avd); tsl:=If(avn=1,sup,res); tsl;
--> <script type="text/javascript" language="JavaScript" src="../jsfiles/bottom.js"> -------------------------------------------------------------------------------------------------Ichimoku Kinko Hyo trading system...! amibroker users can use the following code for the system: Code: //============================================================ SetChartOptions(0,chartShowArrows|chartShowDates); _N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Cl ose %g (%.1f%%) Vol " +WriteVal( V, 1.0 ) +" {{VALUES}}", O, H, L, C, SelectedVa lue( ROC( C, 1 )) )); Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("S tyle") | GetPriceStyle() ); if( ParamToggle("Tooltip shows", "All Values|Only Prices" ) ) { ToolTip=StrFormat("Open: %g\nHigh: %g\nLow: %g\nClose: %g (%.1f%%)\nVolume: "+Nu mToStr( V, 1 ), O, H, L, C, SelectedValue( ROC( C, 1 ))); } SL = ( HHV( H, 26 ) + LLV( L, 26) )/2; TL = ( HHV( H, 9 ) + LLV( L, 9 ) )/2; DL = Ref( C, 26 ); Span1 = (( SL + TL )/2); Span2 = (HHV( H, 52) + LLV(L, 52))/2; Plot(SL,"SL",2,styleThick); // standard, base, or kijun-sen line Plot(TL,"TL",2,styleThick); // turning, conversion, or tenkan-sen line Plot(DL,"",colorLightBlue,styleLine); // delayed, lagging, or chikou span Plot(Span1,"",colorGreen,1,0,0,26); // senkou span A, kumo, or white clouds
( 172,172,172 ))); _SECTION_END(); // Two adjustable parameter "Buy sensitivity" and "Buy Finetune" provided to adj ust entry points. // Two adjustable parameter "Sell sensitivity" and "Sell Finetune" provided to a djust Exit points. _SECTION_BEGIN("KAMA System 1.0");
SetChartOptions(0,chartShowArrows|chartShowDates); Title = ("KAMA SYSTEM - " + Name()+" " + Date() +" "+Interval(2) +" "+ Encode Color(colorLime)+",Open "+Open +" ,High "+H+" ,Low "+L+" ,Close "+C+" "+"{{VALUE S}}"); //{{VALUES}}"+ O+ H+ L+C); //_N(Title =StrFormat("{{Name}} - {{Interval}} {{Date}} Open %g, Hi %g, Lo %g, C lose %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) )); // Buy adjustments bs=Param("BUY Sensitivity",7,2,20,1); bf=Param("BUY Finetune",2,0.1,20,0.1); ///uncommentf for optimization //bs=Optimize("BUY Sensitivity",7,2,20,1); //bf=Optimize("BUY Finetune",2,0.1,20,0.1); // Sell Adjustments ss=Param("SELL Sensitivity",5,2,20,1); sf=Param("SELL Finetune",1,0.1,20,0.1); ///uncommentf for optimization ss=Optimize("SELL Sensitivity",5,2,20,1); sf=Optimize("SELL Finetune",1,0.1,20,0.1); //stock selection parameters MyCL = Param( "CL", 10, 10, 100, 10 ); MyVK = Param( "VK", 30, 10, 100, 10 ); MyTL = Param( "TL", 300, 100, 1000, 100 ); //stock selection //TLM = EMA(C*V/100000,100) ; //include = C> MyCL AND V/1000> MyVK AND C*V/100000 > MyTL AND TLM > 0.333 * MyT L ; // common fast = 2/(2+1); slow = 2/(30+1); //BUY part dirb=abs(Close-Ref(Close,-bs)); volb=Sum(abs(Close-Ref(Close,-1)),bs); ERb=dirb/volb; scb =( ERb*(fast-slow)+slow)^2;
shape = Buy * shapeUpArrow +Sell * shapeDownArrow ; PlotShapes( shape, IIf( Buy, colorLime, colorRed),0, IIf( Buy, Low, High ) ); GraphXSpace = 5; dist = 1.5*ATR(20); for( i = 0; i < BarCount; i++ ) { if( Buy[i] ) PlotText( "Buy\n@" + C[ i ], i, L[ i ]-dist[i], colorLime ); if( Sell[i] ) PlotText( "sell\n@" + C[ i ], i, L[ i ]+dist[i], colorRed ); } Filter= Buy OR Sell; PositionScore=100/C; PositionSize = - 20; SetBarsRequired(10000, 10000); SetFormulaName("KAMA System"); _SECTION_END(); _SECTION_BEGIN("IIR2"); // IIR2.afl // // Documentation to describe what the function does. // Second order smoother // the function statement function IIR2( input, f0, f1, f2 ) // the function body { result[ 0 ] = input[ 0 ]; result[ 1 ] = input[ 1 ]; for( i = 2; i < BarCount; i++ ) { result[i] = f0 * input[i] + f1 * result[i-1] + f2 * result[i-2]; } // the function returns a single value and exits.
return result; } // The routine that calls the function. SmoothedClose = IIR2(Close, 0.2, 1.4, -0.6 ); //Plot( Close, "Price", 2, styleCandle ); Plot( SmoothedClose, "function example", colorRed ); //Figure 8.1 IIR2 _SECTION_END(); _SECTION_BEGIN("GSMA"); SetBarsRequired(100000,0); PI = 3.1415926; function jIIR2( input, f0, f1, f2 ) { result[ 0 ] = input[ 0 ]; result[ 1 ] = input[ 1 ]; for( i = 2; i < BarCount; i++ ) { result[ i ] = f0 * input[ i ] + f1 * result[ i - 1 ] + f2 * result[ i - 2 ]; } return result; } function GSMA( input, Period ) { N = 0; an = 2 * PI / Period; c0 = b0 = 1; c1 = b1 = b2 = a1 = a2 = gamma1 = 0; beta1 = 2.415 * ( 1- cos( an ) ); alpha = -beta1 + sqrt( beta1 ^ 2 + 2 * beta1 ); alpha1 = ( cos( an ) + sin( an ) - 1 )/cos( an ); { fo = alpha ^ 2; f1 = 2 * ( 1- alpha ); f2 = -( 1 - alpha )*( 1 - alpha ); } return jIIR2( input, fo,f1,f2); } period=Param("period",13,1,40,1); //Plot( Close, "Price", colorBlack, styleCandle ); Plot( GSMA( C,period), "GSMA", colorLime ); // Linear Regression Line with 2 Standard Deviation Channels Plotted Above and Below // Written by Patrick Hargus, with critical hints from Marcin Gorzynski, Amibro ker.com Technical Support // Designed for use with AB 4.63 beta and above, using drag and drop featur e. // Permits plotting a linear regression line of any price field available on th e chart for a period determined by the user. // 2 Channels, based on a standard deviation each determined by the user, ar e plotted above and below the linear regression line.
// A look back feature is also provided for examining how the indic ator would have appeared on a chart X periods in the past. P = ParamField("Price field",-1); Daysback = Param("Period for Liner Regression Line",21,1,240,1); shift = Param("Look back period",0,0,240,1); // =============================== Math Formula =============================== ============================== x = Cum(1); lastx = LastValue( x ) - shift; aa = LastValue( Ref(LinRegIntercept( p, Daysback), -shift) ); bb = LastValue( Ref(LinRegSlope( p, Daysback ), -shift) ); y = Aa + bb * ( x - (Lastx - DaysBack +1 ) ); // ==================Plot the Linear Regression Line =========================== =============================== LRColor = ParamColor("LR Color", colorCycle ); LRStyle = ParamStyle("LR Style"); LRLine = IIf( x > (lastx - Daysback) AND BarIndex() < Lastx, y, Null ); Plot( LRLine , "LinReg", LRCOLOR, LRSTYLE ); // styleDots ); // ========================== Plot 1st SD Channel ============================= ================================== SDP = Param("Standard Deviation", 1.5, 0, 6, 0.1); SD = SDP/2; width = LastValue( Ref(SD*StDev(p, Daysback),-shift) ); // THIS IS WHERE THE W IDTH OF THE CHANELS IS SET SDU = IIf( x > (lastx - Daysback) AND BarIndex() < Lastx, y+width , Null ) ; SDL = IIf( x > (lastx - Daysback) AND BarIndex() < Lastx, y-width , Null ) ; SDColor = ParamColor("SD Color", colorCycle ); SDStyle = ParamStyle("SD Style"); Plot( SDU , "Upper Lin Reg", SDColor,SDStyle ); Plot( SDL , "Lower Lin Reg", SDColor,SDStyle ); // ========================== Plot 2d SD Channel ============================= ================================== SDP2 = Param("2d Standard Deviation", 2.0, 0, 6, 0.1); SD2 = SDP2/2; width2 WIDTH SDU2 = SDL2 =
= LastValue( Ref(SD2*StDev(p, Daysback),-shift) ); // THIS IS WHERE THE OF THE CHANELS IS SET IIf( x > (lastx - Daysback) AND BarIndex() < Lastx, y+width2 , Null ) ; IIf( x > (lastx - Daysback) AND BarIndex() < Lastx, y-width2 , Null ) ;