Skip to main content

The Ichimoku Trading Strategy: A Comprehensive Approach to Technical Analysis

The Ichimoku Trading Strategy is a powerful tool in technical analysis. It’s like having support, resistance, trend direction, and momentum all on a single chart. This incredible indicator consists of five key parts, each telling its unique story. It was created by Goichi Hosoda, a Japanese journalist, who spent more than a decade perfecting it. Today, it’s recognized as one of the most trustworthy tools in any technical chart. It’s also known as ‘Ichimoku Kinko Hyo,’ meaning ‘one look equilibrium chart.’ Let’s break down its five fundamental elements and explore the Ichimoku Trading strategy AFL code.

Explore AFL coding and create your own trading systems here.

Understanding the Ichimoku Trading Strategy Elements

Tenkan-sen (Conversion Line): This is calculated as the average of the highest and lowest prices over a 9-period, divided by 2.

Kijun-sen (Base Line): This is calculated as the average of the highest and lowest prices over a 26-period, divided by 2.

Senkou Span A (Leading Span A): It’s the average of the Conversion Line and the Base Line, divided by 2.

Senkou Span B (Leading Span B): This is calculated as the average of the highest and lowest prices over a 52-period, divided by 2.

Chikou Span (Lagging Span): It represents the closing price plotted 26 days behind its actual value.

Implementing the Ichimoku Trading Strategy with AFL Code


//  Formula Name:    Ichimoku Trading system
//  Website:

_N(Title = StrFormat("{{NAME}} – {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 
_SECTION_BEGIN("Ichimoku Hayo Kinko");

//Initial Parameters
SetTradeDelays( 1,1,1, 1 );
SetOption( "InitialEquity", 200000);
SetOption("FuturesMode" ,True);
SetOption( "AllowPositionShrinking", True );

GraphXSpace =1;
prds = Optimize("Standard Line Periods?", 12,5,26,1);
prds1 = Optimize("Turning Line Periods?", 3,3,10,1);
prds2 = Optimize("Delayed Line Periods?", 11,4,25,1);
prds3 = Optimize("Spans Periods?", 18,10,52,1);
TL = ( HHV( H, prds1) + LLV( L, prds1) )/2;
SL = ( HHV( H, prds) + LLV( L, prds) )/2;
DL = Ref( C, prds2);
Sp1 = Ref( ( SL + TL )/2, -prds2);
Sp2 = Ref( (HHV( H, prds3) + LLV(L, prds3))/2, -prds2);
SetChartOptions( 0, chartShowDates | chartShowArrows | chartLogarithmic | chartWrapTitle );
_N( Title = StrFormat( "{{NAME}} - " + SectorID( 1 ) + " - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) Vol " + WriteVal( V, 1.0 ) + " {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ) );
Plot( C, "Close", colorBlack, styleCandle | styleNoTitle | ParamStyle( "Style" ) | GetPriceStyle() );
if ( ParamToggle( "Tooltip shows", "All Values|Only Prices" ) )
ToolTip = StrFormat( "Open: %g\nHigh: %g\nLow: %g\nClose: %g (%.1f%%)\nVolume: " + NumToStr( V, 1 ), O, H, L, C, SelectedValue( ROC( C, 1 ) ) );
Buy = Cross(Close,IIf(sp1>sp2,sp1,sp2));
Short = Cross(IIf(sp1<sp2,sp1,sp2),Close);

/* exrem is one method to remove surplus strade signals*/
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);

printf("\nBuy : " + Buy );  
printf("\nSell : " + Sell );  
printf("\nShort : " + Short );  
printf("\nCover : " + Cover );  

PlotOHLC (Sp1,Sp1,Sp2,Sp2,"Cloud",IIf(Sp1>Sp2,ParamColor("Span1 Color", ColorRGB(0,255,0)),ParamColor("Span2 Color",ColorRGB(255,104,32))),styleCloud);
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);

if( Status("action") == actionIndicator ) 
Title = EncodeColor(colorWhite)+ "NICK MA Swing System" + " - " +  Name() + " - " + EncodeColor(colorRed)+ Interval(2) + EncodeColor(colorWhite) +
 "  - " + Date() +" - "+"\n" +EncodeColor(colorRed) +"Op-"+O+"  "+"Hi-"+H+"  "+"Lo-"+L+"  "+
"Cl-"+C+"  "+ "Vol= "+ WriteVal(V)+"\n"+ 
WriteIf (Buy , " GO LONG / Reverse Signal at "+C+"  ","")+
WriteIf (Sell , " EXIT LONG / Reverse Signal at "+C+"  ","")+"\n");

The Ichimoku Trading Strategy is a complete trading system in itself. It plots the Ichimoku cloud and generates Buy/Sell signals directly on the chart. When the price is above the cloud, it signals an uptrend with a green cloud. Conversely, when the price is below the cloud, it indicates a downtrend with a red cloud. Some of the standard Ichimoku parameters have been adjusted to reduce false signals.

Ichimoku Trading System


Leave a Reply