Skip to main content

Ichimoku with Buy & Sell for Amibroker (AFL)

hizari almost 16 years ago Amibroker (AFL)

  • Rating:
    4 / 5 (Votes 12)
  • Tags:
    trading system, amibroker, ichimoku

Ichimoku Kinko Hyo usually just called ichimoku is a technical analysis method that builds on candlestick charting to improve the accuracy of forecasted price moves. Developed in the late 1930s by Goichi Hosoda, a Japanese journalist, who used to be known as Ichimoku Sanjin, something that can be translated as “What a man in the mountain sees”. He spent thirty years perfecting the technique before releasing his findings to the general public in the late 1960s.

Ichimoku Kinko Hyo translates to ‘one glance equilibrium chart’ or ‘instant look at the balance chart’ and is sometimes referred to as ‘one glance cloud chart’ based on the unique ‘clouds’ that feature in ichimoku charting.

Ichimoku is a moving average-based trend identification system and because it contains more data points than standard candlestick charts, provides a clearer picture of potential price action. The main difference between how moving averages are plotted in ichimoku as opposed to other methods is that ichimoku’s lines are constructed using the 50% point of the highs and lows as opposed to the candle’s closing price.

Screenshots

Indicator / Formula

Copy & Paste Friendly
_SECTION_BEGIN("i");
/* ICHIMOKU CHART */ 
n1 = Param("Èøèìîêó: ïåðèîä 1",9,1,200,1); 
n2 = Param("Èøèìîêó: ïåðèîä 2",26,1,400,1); 
n3 = Param("Èøèìîêó: ïåðèîä 3",52,1,600,1); 

TenkanSen   =(HHV(H,n1)+LLV(L,n1))/2;            // Tenkan-sen (Òåíêàí-ñåí) – ýòî ñðåäíåå çíà÷åíèå öåíû çà ïåðâûé ïðîìåæóòîê âðåìåíè (ðàâíà (high+low)/2, ãäå high è low – ìàêñèìóì è ìèíèìóì çà ïåðèîä). 
KijunSen    =(HHV(H,n2)+LLV(L,n2))/2;            // Kijun-sen (Êèäæóí-ñåí) – ýòî ñðåäíåå çíà÷åíèå öåíû çà âòîðîé ïðîìåæóòîê. 
ChinkouSpan =Ref(C,-n2);                          // Chinkou Span (×èêîó ñïåí) - öåíà çàêðûòèÿ òåêóùåãî áàðà, ñäâèíóòàÿ íàçàä íà âåëè÷èíó âòîðîãî âðåìåííîãî èíòåðâàëà. 
Cks         = Close;                             // Ãðàôè÷åñêèé Chinkou Span, ñäâèã íàçàä çàñ÷åò îòðèñîâêè. 
SenkouSpanA =Ref((KijunSen+TenkanSen)/2,-n2);    // Senkou Span A (Ñåíêîó ñïåí À) / Up Kumo - ñåðåäèíà ðàññòîÿíèÿ ìåæäó Tenkan-sen è Kijun-sen, ñäâèíóòîå âïåðåä íà âåëè÷èíó âòîðîãî âðåìåííîãî èíòåðâàëà. 
SpA         =(KijunSen+TenkanSen)/2;             // Ãðàôè÷åñêèé Senkou Span A , ñäâèã âïåðåä çàñ÷åò îòðèñîâêè. 
SenkouSpanB =Ref((HHV(H,n3)+LLV(L,n3))/2,-n2);   // Senkou Span B (Ñåíêîó ñïåí Â) / Down Kumo - ñðåäíåå çíà÷åíèå öåíû çà òðåòèé âðåìåííîé èíòåðâàë, ñäâèíóòîå âïåðåä íà âåëè÷èíó âòîðîãî âðåìåííîãî èíòåðâàëà. 
SpB         =(HHV(H,n3)+LLV(L,n3))/2;            // Ãðàôè÷åñêèé Senkou Span B, ñäâèã âïåðåä çàñ÷åò îòðèñîâêè. 
DL = Ref( C, 25 );


Cond1 =  Ref(Close > Max(SenkouSpanA,SenkouSpanB),-1);  //öåíà âûøå îáëàêà  -- áû÷üå íàñòðîåíèå 
Cond2 =  Ref(Close < Min(SenkouSpanA,SenkouSpanB),-1);  //öåíà íèæå îáëàêà  -- ìåäâåæüå íàñòðîåíèå 
Cond3 =  Ref(Cross(TenkanSen,KijunSen),-1);  //ïåðåñå÷åíèå Òåíêàí è Êèäæóí -- ñèãíàë íà ïîêóïêó 
Cond4 =  Ref(Cross(KijunSen,TenkanSen),-1);  //ïåðåñå÷åíèå Òåíêàí è Êèäæóí -- ñèãíàë íà ïðîäàæó 
Cond5 =  Ref(Cross(Close,ChinkouSpan ),-1);  //ïåðåñå÷åíèå ×èêîó è öåíû 
Cond6 =  Ref(Cross(ChinkouSpan ,Close),-1);  //ïåðåñå÷åíèå ×èêîó è öåíû 
Cond7 =  Ref(Cross (Close , Max(SenkouSpanA,SenkouSpanB)),-1);  //öåíà âûõîäèò ââåðõ èç îáëàêà  -- ñèãíàë íà ïîêóïêó 
Cond8 =  Ref(Cross ( Min(SenkouSpanA,SenkouSpanB), Close),-1);  //öåíà âûõîäèò âíèç  èç îáëàêà  -- ñèãíàë íà ïðîäàæó 
Cond9 = Close > TenkanSen AND TenkanSen > KijunSen AND KijunSen > Max(SenkouSpanA,SenkouSpanB); // ñèãíàë òðåõ ëèíèé ââåðõ 
Cond10= Close < TenkanSen AND TenkanSen < KijunSen AND KijunSen < Min(SenkouSpanA,SenkouSpanB); // ñèãíàë òðåõ ëèíèé âíèç 
RemCond9=ExRem(Cond9,NOT Cond9);                  
RemCond10=ExRem(Cond10,NOT Cond10); 

ColSenk =IIf (Cond1,colorGreen, IIf(Cond2,colorRed,colorLightGrey)); // çàäàåò öâåò, åñëè öåíà âûøå/íèæå/âíóòðè îáëàêà. 
Flat  =  TenkanSen == Ref(TenkanSen,-1) OR (NOT(Cond1) AND NOT(Cond2)) ; 

for( i = 0; i < BarCount; i++ ) //ðàñêðàøèâàåò ñðåäíþþ ëèíèþ èíäèêàòîðà ïî âçàèìîðàñïîëîæåíèþ è íàïðàâëåíèÿ äâèæåíèÿ TenkanSen, öåíû è îáëàêà. 
{ 
   if (Flat[i]) 
      ColTenk[i] = colorLightGrey; 
   else 
   { 
if (Cond1[i] AND TenkanSen[i] > TenkanSen[i-1]) 
     ColTenk[i] = colorGreen; 
if (Cond1[i] AND TenkanSen[i] < TenkanSen[i-1]) 
     ColTenk[i] = colorRed; 
if (Cond2[i] AND TenkanSen[i] < TenkanSen[i-1]) 
     ColTenk[i] = colorRed; 
if (Cond2[i] AND TenkanSen[i] > TenkanSen[i-1]) 
     ColTenk[i] = colorGreen; 
   } 
} 


AlertIf( Cond3 OR Cond4, "SOUND c:/WINDOWS/Media/notify.wav", "ïåðåñå÷åíèå Òåíêàí è Êèäæóí",0,1+2+4+8); 
AlertIf( Cond5 OR Cond6, "SOUND c:/WINDOWS/Media/notify.wav", "ïåðåñå÷åíèå ×èêîó è öåíû",0,1+2+4+8); 
AlertIf( Cond7 OR Cond8, "SOUND c:/WINDOWS/Media/notify.wav", "öåíà âûõîäèò  èç îáëàêà",0,1+2+4+8); 
AlertIf( RemCond9 OR RemCond10, "SOUND c:/WINDOWS/Media/notify.wav", "ñèãíàë òðåõ ëèíèé",0,1+2+4+8); 

//PlotShapes(IIf(Cond7, shapeSmallUpTriangle ,shapeNone),colorGreen,0,H,10);              
//PlotShapes(IIf(Cond8, shapeSmallDownTriangle ,shapeNone),colorRed,0,L,10); 
//PlotShapes(IIf(Cond3, shapeHollowSmallUpTriangle,shapeNone),colorGreen,0,H,12);              
//PlotShapes(IIf(Cond4, shapeHollowSmallDownTriangle ,shapeNone),colorRed,0,L,12); 
//PlotShapes(IIf(Cond5, shapeSmallCircle ,shapeNone),colorGreen,0,H,4);              
//PlotShapes(IIf(Cond6, shapeSmallCircle + shapePositionAbove ,shapeNone),colorRed,0,L,4); 
//PlotShapes(IIf(RemCond9 , shapeHollowSquare ,shapeNone),colorGreen,0,H,18);              
//PlotShapes(IIf(RemCond10, shapeHollowSquare + shapePositionAbove ,shapeNone),colorRed,0,L,18); 

//Plot (C,"Close",colorBlack,styleThick); 
Plot (C,"Bars",colorBlack,styleCandle); 
Plot (TenkanSen,"Tenkan-sen",colorRed); 
Plot (KijunSen, "Kijun-sen", colorBlue); 
Plot (Cks,"Chinkou Span",colorLime, style = styleLine,0,0,-n2); 
Plot (SpA,"SenkouSpanA",colorOrange,styleDashed,0,0,n2); 
Plot (SpB,"SenkouSpanB",colorViolet,styleDashed + styleThick,0,0,n2); 
PlotOHLC (SpA,SpA,SpB,SpB,"Cloud",IIf (SpA > SpB,colorPink,colorLavender),styleCloud, 10, 10, n2 ); 
above = IIf(KijunSen>SenkouSpanA AND TenkanSen>SenkouSpanB,1,0);
within = IIf(KijunSen>SenkouSpanA AND TenkanSen<SenkouSpanB,1,0);
below = IIf(TenkanSen<SenkouSpanA AND TenkanSen<SenkouSpanB,1,0);
Buy = Cross(TenkanSen,KijunSen) AND (DL>Close);
Sell = Cross(KijunSen,TenkanSen) AND (DL<KijunSen);
StrongBuy = Buy AND above;
MediumBuy = Buy AND within;
WeakBuy = Buy AND below;
StrongSell = Sell AND below;
MediumSell = Sell AND within;
WeakSell = Sell AND above;

IIf( (StrongBuy),PlotShapes(shapeUpTriangle*StrongBuy,colorGreen),0);
IIf( (MediumBuy),PlotShapes(shapeUpArrow*MediumBuy,colorGreen),0);
IIf( (WeakBuy),PlotShapes(shapeHollowUpArrow*WeakBuy,colorIndigo),0);
IIf( (StrongSell),PlotShapes(shapeDownTriangle*StrongSell,colorRed),0);
IIf( (MediumSell),PlotShapes(shapeDownArrow*MediumSell,colorRed),0);
IIf( (WeakSell),PlotShapes(shapeHollowDownArrow*WeakSell,colorBrown),0);


// Ãîðèçîíòàëüíàÿ öâåòíàÿ èíäèêàòîðíàÿ ïîëîñà (ïðèìåð). 


Plot( 1, "Ribbon", ColTenk, styleOwnScale|styleArea|styleNoLabel, -2, 200 );   // èíäèöèðóåò ôëýò íà TenkanSen. 
Plot( 4, "Ribbon", ColSenk, styleOwnScale|styleArea|styleNoLabel, -1, 200 );   // èíäèöèðóåò ïîëîæåíèå öåíû îòíîñèòåëüíî îáëàêà
_SECTION_END();

18 comments

almost 14 years ago

Thanks! Very nice. It has even got authentic Japanese comments. (Pity, I can’t read Japanese).

almost 14 years ago

No to ichimoku as this gives horrible signals for trading. May be good for investment on daily charts

thanks
viswanath

almost 14 years ago

Hi, I have tried all other strategies, but alas, ichimoku seems to be only reliable strategy for making profits with 85% success ratio though it gives little late signals. I have tested & tradede extensively on this.

Do you have buy sell AFL for

1) kumo breakout
2) kumo twist
3) CS line crossing

If you have kindle upload the AFL with exploration

Thanks
Viswanath

over 13 years ago

Dear hazari,

If you have/developed for other ichimoku trading startegies as mentioned above, kindly update in this forum.

My question is : Is this mentioned startegy ie tenken & kiyun cross is enough for trading and not required to trade other ichimoku trading startegies? Is this reason you have developed AFL for tenken & kiyun cross strategy alone?

Many many thanks & regards,
Viswanath

over 11 years ago

I agree with klubow

The buy signal looks into the future: ref(close,50)>close;

What a pity!

9. mehdi-0
about 11 years ago

hi

in ichimoku system when kijensen is flated for 1 to 20 day ago and in the 1 to 20 day ago tekensen croosed kijensen.

and last candle kijensen will uptrend.

i want this program

for example

i want to get signal in codition 2

codition1: cross (tenkensen, kijensen); // max 20 candle ago

codition2: kijensen > ref (kijensen , -1) ; // last candle today

i want to get signal in condition 2

i write this whit “exrem”

but this has a lot of mis.

program must be check today to 2o day ago for cross(tenkensen,kijensen); and get signal when kijensen is uptrend

plz send afl program for this .

thanks

10. parfumeur
about 11 years ago

This is a sample of what I see on my computer:

Ãðàôè÷åñêèé Chinkou Span, ñäâèã íàçàä çàñ÷åò îòðèñîâêè.

So, could the author be so kind as to use Google translate to English and post in the Pastie section of the board, or re send the afl?? THANK YOU.
===========
そこで、著者はとても親切Googleは、ボードの貼り付けサイトのセクションに英語とポストに変換使用するか、またはAFLを送る再ようにだろうか?

11. sankarjv
about 11 years ago

This afl is correct for ichimoku compared to the one given by amibroker
It gives a snap short of present market with both past and future data
You can not trade with this as it looks into future just like zig-zag

over 10 years ago

Dear Developer I see this error message when I run it on daily data of all stocks
"
Error 29.
Variable ‘coltenk’ used without having been initialized.
"

Can you pls help to correct it, thanks
Sonchoy

15. MotaSheth
about 10 years ago

Hi,

Great effort at a very good trading system.

However, i find signals getting re-painted…..

Hence its not possible to trade real time,

Can you look into it and remove this re-painting of signals ?

thanks,

18. jakz
over 5 years ago

hey The signal are repainting And what does DL means Im kindly new to Amibroker and how exactly its taking entries of buy and sell can anyone please explain

Leave Comment

Please login here to leave a comment.