Current Value of Senkou Span

 

Hi, I'm playing around with using the Ichimoku indicator on my EA but have ran into an issue when opening a trade based on the value of the Senkou Span lines.

Basically I want to open a Buy order when the price opens inside the kumo cloud, then closes above it. Then I want to open a sell order when the price opens inside the kumo cloud, then closes below it. Basically simulating a breakout strategy.

void buildIchimoku() {
   Tenkansen = iIchimoku(NULL,0,9,26,52,MODE_TENKANSEN,1);
   Kijunsen = iIchimoku(NULL,0,9,26,52,MODE_KIJUNSEN,1);
   Senkouspana = iIchimoku(NULL,0,9,26,52,MODE_SENKOUSPANA,1);
   Senkouspanb = iIchimoku(NULL,0,9,26,52,MODE_SENKOUSPANB,1);
   Chikouspan = iIchimoku(NULL,0,9,26,52,MODE_CHIKOUSPAN,1);
   
   double KumoTop = MathMax(Senkouspana, Senkouspanb);
   double KumoBottom = MathMin(Senkouspana, Senkouspanb);
   
   if ((Open[1] < KumoTop) && (Open[1] > KumoBottom) && (Close[1] > KumoTop)) {
      priceBreakLong = true;
   } else if ((Open[1] > KumoBottom) && (Close[1] < KumoTop) && (Close[1] < KumoBottom)) {
      priceBreakShort = true;
   }
}

I run this function in the onTick() function.

buildIchimoku();

Then trigger the order depending on whether priceBreakLong() or priceBreakShort() are true.

The problem I have (and it's reaaally annoying me) is that the EA is opening/closing trades based on the values of the Senkou Span 26 periods ahead, not of the current candle. When ran in visual mode the price is nowhere near the cloud when the trades are actioned as can be seen in the attached picture.

I know it's probably a very simply mistake, but I really can't work out what I'm doing wrong! 

Any help would be greatly appreciated!

Ichimoku Kinko Hyo - Trend Indicators - MetaTrader 5 Help
Ichimoku Kinko Hyo - Trend Indicators - MetaTrader 5 Help
  • www.metatrader5.com
Ichimoku Kinko Hyo Technical Indicator is predefined to characterize the market Trend, Support and Resistance Levels, and to generate signals of...
 

I know this is way late, but I think if you shift your senkou spans 26 places, you should get the current bar's kumo (or, the kumo that the bar 26 bars back predicted for this bar).

   Senkouspana = iIchimoku(NULL,0,9,26,52,MODE_SENKOUSPANA,26);
   Senkouspanb = iIchimoku(NULL,0,9,26,52,MODE_SENKOUSPANB,26);

I am not a pro, but I think this should work! I hope it helps anyone with this problem in the future.

 
  1. jdgibbons88 #: I am not a pro, but I think this should work! I hope it helps anyone with this problem in the future.

    Invalid call for MT4. This is the MT4 forum.


  2. 150070:

       if ((Open[1] < KumoTop) && (Open[1] > KumoBottom) && (Close[1] > KumoTop)) {
          priceBreakLong = true;
       } else if ((Open[1] > KumoBottom) && (Close[1] < KumoTop) && (Close[1] < KumoBottom)) {
          priceBreakShort = true;

    Do you ever set the variables to false?

       priceBreakLong  = Open[1] < KumoTop    &&  Open[1] > KumoBottom && Close[1] > KumoTop;
       priceBreakShort = Open[1] > KumoBottom && Close[1] < KumoTop    && Close[1] < KumoBottom;
    Why are you using open in one and close in the other?