Day trading can often feel perplexing and uncertain without a solid grasp of the basics. For success in intraday trading, it’s crucial to have reliable indicators and patterns at your disposal. Stochastic is a tried-and-tested indicator that has been around for quite a while. It’s versatile, suitable for both intraday and swing trading. In this post, we delve into a Intraday Stochastic trading system that has yielded an impressive 63%~ annual compounded returns over the past three years. Plus, we’ve provided the Amibroker AFL code for this system.
Unpacking the Stochastic Indicator and Its Calculation
Stochastic is a momentum indicator that reflects the strength of the current trend by comparing the current price to a range of prices over a specified lookback period. As an oscillator, its value swings between 0 to 100, making it a reliable tool to spot overbought and oversold price levels.
Reference: https://tradingstrategyguides.com/best-stochastic-trading-strategy/
The Stochastic Indicator was crafted by George C Lane in the 1950s. In an interview, Lane mentioned that the Stochastic Oscillator “doesn’t follow price or volume, but the speed or the momentum of price. Typically, the momentum shifts direction before the price.”
Here’s how the Stochastic Indicator is calculated:
%K = (Current Close – Lowest Low)/(Highest High – Lowest Low) * 100
%D = 3-day SMA of %K
Where Lowest Low = lowest low over the look-back period
And Highest High = highest high over the look-back period
The default look-back period is 14 days, adjustable based on the security traded. Trading signals emerge when the %K line of Stochastic crosses the %D line.
Moreover, Stochastic Divergences are great at pinpointing price reversals. Divergence happens when the price trend and the indicator trend move in opposite directions.
Continue reading to discover a profitable trading system based on Stochastic:
Click Here to delve into AFL coding and craft your own Trading systems.
Intraday Stochastic Trading System – A Glimpse into the AFL
Parameter | Value |
---|---|
Preferred Time-frame | 5 Minutes |
Indicators Used | StochD, StochK |
Buy Condition |
|
Short Condition |
|
Sell Condition |
|
Cover Condition |
|
Stop Loss | 0.5% |
Targets | 1% |
Position Size | 100% of equity |
Initial Equity | 200000 |
Brokerage | 100 per order |
Margin | 10% |
Get the Intraday Stochastic Trading System – AFL Code
//------------------------------------------------------
//
// Formula Name: Intraday Stochastic System
// Website: https://zerobrokerageclub.com/
//------------------------------------------------------
_SECTION_BEGIN("Intraday Stochastic System");
SetTradeDelays( 1, 1, 1, 1 );
SetOption( "InitialEquity", 200000);
SetOption("FuturesMode" ,True);
SetOption("MinShares",1);
SetOption("CommissionMode",2);
SetOption("CommissionAmount",100);
SetOption("AccountMargin",10);
SetPositionSize(100,spsPercentOfEquity);
SetOption( "AllowPositionShrinking", True );
BuyPrice=Open;
SellPrice=Open;
ShortPrice=Open;
CoverPrice=Open;
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} – {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
NewDay = (Day()!= Ref(Day(), -1)) OR BarIndex() == 0;
Plot(NewDay,"",colorlightGrey,styleHistogram|styleDots|styleNoLabel|styleOwnScale);
FirstTradeTime=093000;
SquareOffTime = 151500;
periods = Param( "Periods", 14, 1, 200, 1 );
Ksmooth = Param( "%K avg", 12, 1, 20, 1 );
Dsmooth = Param( "%D avg", 10, 1, 20, 1 );
myStochD =StochD( periods , Ksmooth, DSmooth );
myStochK =StochK( periods , Ksmooth);
Overbought = 80 ;
Oversold =20 ;
Center = 50 ;
Buy = Cross(myStochK, myStochD) AND Cross(myStochK, Oversold) AND TimeNum()>= FirstTradeTime AND TimeNum()= FirstTradeTime AND TimeNum()= SquareOffTime;
Cover=buy OR TimeNum() >= SquareOffTime;
Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);
Short=ExRem(Short,Cover);
Cover=ExRem(Cover,Short);
StopLoss=Param("stop",0.5,0.5,2,0.5);
ApplyStop(Type=0,Mode=1,Amount=StopLoss);
Target=Param("Target",1,1,5,1);
ApplyStop(Type=1,Mode=1,Amount=Target);
printf("\nBuy : " + Buy );
printf("\nSell : " + Sell );
printf("\nShort : " + Short );
printf("\nCover : " + Cover );
printf("\nmyStochK : " + myStochK );
printf("\nmyStochD : " + myStochD );
/* Plot Buy and Sell Signal Arrows */
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50);
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-45);
PlotShapes(IIf(Cover, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40);
PlotShapes(IIf(Cover, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50);
PlotShapes(IIf(Cover, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-45);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorRed, 0, H, Offset=40);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorRed, 0, H, Offset=40);
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);
PlotShapes(IIf(Short, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);
_SECTION_END();
AFL Screenshot
Also Read: The Ichimoku Trading Strategy: Amibroker AFL Code
Intraday Stochastic Trading System – Backtest Report
Parameter | Value |
---|---|
Nifty | |
Initial Capital | 200000 |
Final Capital | 1342878.53 |
Scrip Name | NSE Nifty |
Backtest Period | 01-Jan-2014 to 20-Nov-2017 |
Timeframe | 5 Minutes |
Net Profit % | 571.44% |
Annual Return % | 62.64% |
Number of Trades | 265 |
Winning Trade % | 56.60% |
Average holding Period | 31.57 periods |
Max consecutive losses | 5 |
Max system % drawdown | -22.90% |
Max Trade % drawdown | -9.32% |
Download the comprehensive backtest report here.
Equity Curve
Profit Table
This intraday trend following strategy has turned a profit each year from 2014 to 2017.
Additional Amibroker Settings for Backtesting
Navigate to Symbol–>Information, and specify the lot size and margin requirement. The below screenshot shows a lot size of 75 and a margin requirement of 10% for NSE Nifty: