How to code Ichimoku based breakout cloud?

 
Hi
I want to make ea from ichimoku.
The logic is that when the price breaks the cloud it will open buy.
Logic buy is:
When the candle breaks the kumo, and a candle appears above the kumo (close and opendoes not hit the kumo) then triggers buy.

But how come my coding below doesn't work. In fact, buy appears where it shouldn't be.

Maybe someone knows where it went wrong?

Sorry im newbie in coding stuff

thank you

double tenkan_sen    =iIchimoku(NULL,0,9,26,52,MODE_TENKANSEN,0);
double kijun_sen     =iIchimoku(NULL,0,9,26,52,MODE_KIJUNSEN,0);
double senkouspanA   =iIchimoku(NULL,0,9,26,52,MODE_SENKOUSPANA,0);
double senkouspanB   =iIchimoku(NULL,0,9,26,52,MODE_SENKOUSPANB,0);
double chikouspan    =iIchimoku(NULL,0,9,26,52,MODE_CHIKOUSPAN,0);




//+------------------------------------------------------------------+
//    expert start function
//+------------------------------------------------------------------+
int start()
{
   double MyPoint=Point;
  if (Digits==3 || Digits==5) 
      {MyPoint=Point*10;}
   else                        
      {MyPoint=Point;}
  
  double TheStopLoss=0;
  double TheTakeProfit=0;
  if( TotalOrdersCount()==0 ) 
  {
     int result=0;
     if (((Open[0]>senkouspanA && Close[0]>senkouspanA)||(Open[0]>senkouspanB && Close[0]>senkouspanB))&& ((Open[1]<senkouspanA && Open[1]>senkouspanB)||(Open[1]<senkouspanB && Open[1]>senkouspanA)))
             
     {
        result=OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,0,0,"Ichi Buy",MagicNumber,0,Blue);
        if(result>0)
        {
         TheStopLoss=0;
         TheTakeProfit=0;
         if(TakeProfit>0) TheTakeProfit=Ask+TakeProfit*MyPoint;
         if(StopLoss>0) TheStopLoss=Ask-StopLoss*MyPoint;
         OrderSelect(result,SELECT_BY_TICKET);
         OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(TheStopLoss,Digits),NormalizeDouble(TheTakeProfit,Digits),0,Green);
        }
        return(0);
 
double tenkan_sen    =iIchimoku(NULL,0,9,26,52,MODE_TENKANSEN,0);
double kijun_sen     =iIchimoku(NULL,0,9,26,52,MODE_KIJUNSEN,0);
double senkouspanA   =iIchimoku(NULL,0,9,26,52,MODE_SENKOUSPANA,0);
double senkouspanB   =iIchimoku(NULL,0,9,26,52,MODE_SENKOUSPANB,0);
double chikouspan    =iIchimoku(NULL,0,9,26,52,MODE_CHIKOUSPAN,0);

Where do these appear in your code? They should be in OnTick() or start()

Learn to code. EA builders create poor quality code.

 
I put on global
 
Keith Watford:

Where do these appear in your code? They should be in OnTick() or start()

Learn to code. EA builders create poor quality code.

Im new. Im not sure how to code breakout on cloud. SO i write the code above

 


See the circle. The result of my code is totally wrong open position

 
Agus Wahyu Pratomo:
I put on global
Keith Watford:

Where do these appear in your code? They should be in OnTick() or start()

 
Keith Watford:

thanks it works

 
But i think my code about how to identifi breaking out the cloud is wrong. How i suppose to do to code that
Reason: