complex operator question

 

Hi,

I  have a set of MT4 indicators that draws alert dots on the chart, histograms and lines. The indicators generate an alert signal and then some other indicators are used for confirmation.

We can enter a trade when all confirming conditions are met at or after a max of 3 bars after the candle where the alert dot appeared.

What I am trying is to combine the indicator results into a new indicator that draws simple arrows when all indicators are confirming the trade.

To do this I have to use a (for me) complex if ... else ... combined with && (AND) and || (OR) operators.

But not all arrows appear at the moment that all conditions are met. So I suppose I have an error somewhere, but I an unable to find it.

For the sake of this post, I've simplified the code below a bit to make it more readable. The code below is the BUY part of the code. Scenario #3 is where I have a 2 situation choice where one of the two must match, so I used an OR operator. But that does not produce the correct results.

I 'm not asking for a complete solution to my problem, but more if someone can show me how the structure works with multiple and nested if / else's combined with && and || operators.

Thanks...

 

       // Indicator Buffer 2 GREEN BUY
      if   // Scenario #1 - All conditions are met at the Alerter dot bar
      (
         (
            (
               // Signal 1 - Alerter Arows (This detects if an alert arrow has been drawn)
                  iCustom(NULL, PERIOD_CURRENT, "My Alerter v6.04p", 40, true, "alert1.wav", 1,   i) < 1000
            )

         &&

            (
               // Confirmation 1 - Heiken Ashi Current Bar turned blue
                  iCustom(NULL, PERIOD_CURRENT, "My Heiken Ashi v6.04p", 0,   i) == 1 // Blue

               // Confirmation 2 - Heiken Ashi Previous 3 Bars
               && iCustom(NULL, PERIOD_CURRENT, "My Heiken Ashi v6.04p", 0, 1+i) == 0 // Red
               && iCustom(NULL, PERIOD_CURRENT, "My Heiken Ashi v6.04p", 0, 2+i) == 0 // Red
               && iCustom(NULL, PERIOD_CURRENT, "My Heiken Ashi v6.04p", 0, 3+i) == 0 // Red

               // Confirmation 3 - Trigger
               && iCustom(NULL, PERIOD_CURRENT, "My Trigger v6.04p",0,i) > iCustom(NULL, PERIOD_CURRENT, "My Trigger v6.04p",1,i)

               // Confirmation 4 - My Timer
               && iCustom(NULL, PERIOD_CURRENT, "My Timer v6.04p",1,i) != EMPTY_VALUE
            )
         )

      ||  // Scenario #2 - All conditions are met at bar 1 after the Alerter dot

         (
            (
               // Signal 1 - Alerter Arows
                  iCustom(NULL, PERIOD_CURRENT, "My Alerter v6.04p", 40, true, "alert1.wav", 1, 1+i) < 1000
            )

         &&

            (
               // Confirmation 1 - Heiken Ashi Current Bar is blue
                  iCustom(NULL, PERIOD_CURRENT, "My Heiken Ashi v6.04p", 0,   i) == 1 // Blue

               // Confirmation 2 - Heiken Ashi Previous 3 Bars are Red
               && iCustom(NULL, PERIOD_CURRENT, "My Heiken Ashi v6.04p", 0, 1+i) == 0 // Red
               && iCustom(NULL, PERIOD_CURRENT, "My Heiken Ashi v6.04p", 0, 2+i) == 0 // Red
               && iCustom(NULL, PERIOD_CURRENT, "My Heiken Ashi v6.04p", 0, 3+i) == 0 // Red

               // Confirmation 3 - My Trigger is Green
               && iCustom(NULL, PERIOD_CURRENT, "My Trigger v6.04p",0,i) > iCustom(NULL, PERIOD_CURRENT, "My Trigger v6.04p",1,i)

               // Confirmation 4 - My Timer is Green
               && iCustom(NULL, PERIOD_CURRENT, "My Timer v6.04p",1,i) != EMPTY_VALUE
            )
         )

      || // Scenario #3 - All conditions are met at 2 bars after the Alerter dot

         (
            // Signal 1 - Alerter Arows
               iCustom(NULL, PERIOD_CURRENT, "My Alerter v6.04p", 40, true, "alert1.wav", 1, 2+i) < 1000

         &&

            // Confirmation 1 - Heiken Ashi Current Bar turned blue
               iCustom(NULL, PERIOD_CURRENT, "My Heiken Ashi v6.04p", 0,   i) == 1 // Blue

         &&

            (
               (
                  // Confirmation 2 - Heiken Ashi Previous 3 Bars
                     iCustom(NULL, PERIOD_CURRENT, "My Heiken Ashi v6.04p", 0, 1+i) == 0 // Red
                  && iCustom(NULL, PERIOD_CURRENT, "My Heiken Ashi v6.04p", 0, 2+i) == 0 // Red
                  && iCustom(NULL, PERIOD_CURRENT, "My Heiken Ashi v6.04p", 0, 3+i) == 0 // Red
               )

            ||

               (
                  // OR Confirmation 2 - Heiken Ashi Previous 4 Bars
                     iCustom(NULL, PERIOD_CURRENT, "My Heiken Ashi v6.04p", 0, 1+i) == 1 // Blue
                  && iCustom(NULL, PERIOD_CURRENT, "My Heiken Ashi v6.04p", 0, 2+i) == 0 // Red
                  && iCustom(NULL, PERIOD_CURRENT, "My Heiken Ashi v6.04p", 0, 3+i) == 0 // Red
                  && iCustom(NULL, PERIOD_CURRENT, "My Heiken Ashi v6.04p", 0, 4+i) == 0 // Red
               )
            )

         &&

            // Confirmation 3 - My Trigger
               iCustom(NULL, PERIOD_CURRENT, "My Trigger v6.04p",0,i) > iCustom(NULL, PERIOD_CURRENT, "My Trigger v6.04p",1,i)

         &&

            // Confirmation 4 - My Timer
               iCustom(NULL, PERIOD_CURRENT, "My Timer v6.04p",1,i) != EMPTY_VALUE
         )

      || // Scenario #4 - All conditions are met at 3 bars after the Alerter dot
         (
            (
               // Signal 1 - Alerter Arows
                  iCustom(NULL, PERIOD_CURRENT, "My Alerter v6.04p", 40, true, "alert1.wav", 1, 3+i) < 1000
            )

         &&

            (
               // Confirmation 1 - Heiken Ashi Current Bar turned blue
                  iCustom(NULL, PERIOD_CURRENT, "My Heiken Ashi v6.04p", 0,   i) == 1

               // Confirmation 2 - Heiken Ashi Previous 3 Bars
               && iCustom(NULL, PERIOD_CURRENT, "My Heiken Ashi v6.04p", 0, 1+i) == 0
               && iCustom(NULL, PERIOD_CURRENT, "My Heiken Ashi v6.04p", 0, 2+i) == 0
               && iCustom(NULL, PERIOD_CURRENT, "My Heiken Ashi v6.04p", 0, 3+i) == 0

               // Confirmation 3 - My Trigger
               && iCustom(NULL, PERIOD_CURRENT, "My Trigger v6.04p",0,i) > iCustom(NULL, PERIOD_CURRENT, "My Trigger v6.04p",1,i)

               // Confirmation 4 - My Timer
               && iCustom(NULL, PERIOD_CURRENT, "My Timer v6.04p",1,i) != EMPTY_VALUE
            )
         )
      )

            {
               Buffer2[i] = Low[i] - ArrowPointGap * Point; // Draw arrow below candlestick low
               if(i == 1 && Time[1] != time_alert) myAlert("indicator", "buy");
               time_alert = Time[1];
            }
         else
            {
               Buffer2[i] = 0;
            }

 

Reason: