For Loop keeps counting past false condition ?

 

Help me correct my logic on this. 


int upcount,downcount;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   macdcount();
   Print(" upcount ",upcount);
   Print (" downcount ", downcount);
  }
//+------------------------------------------------------------------+


void macdcount()
   {
   for (int i=0; i < 50; i++)
      {
      double histo = iCustom(NULL,0,"MACD True",2,i);
      //double val1=iFractals(NULL, 0, MODE_UPPER, i);
      
      if (histo > 0)
         { 
         upcount= i;
         }
      else return;     

/*
      if(histo < 0)
         {
         downcount=i;
         }
      else return;
*/
      }

    }

Without the else return I don't really understand why upcount continues to get assigned i++ up to 49 where the for loop terminates. 

When the if condition is false shouldn't it stop assigning i++ count to downcount ? 


Please advise. 
Thanks

 
Agent86: Without the else return I don't really understand why upcount continues to get assigned i++ up to 49 where the for loop terminates.
  1. Because the MACD are all positive.

  2. Use the debugger or print out your variables, including _LastError and prices and find out why. Do you really expect us to debug your code for you after three years?
              Code debugging - Developing programs - MetaEditor Help
              Error Handling and Logging in MQL5 - MQL5 Articles (2015)
              Tracing, Debugging and Structural Analysis of Source Code - MQL5 Articles (2011)
              Introduction to MQL5: How to write simple Expert Advisor and Custom Indicator - MQL5 Articles (2010)

 
William Roeder #:
  1. Because the MACD are all positive.

  2. Use the debugger or print out your variables, including _LastError and prices and find out why. Do you really expect us to debug your code for you after three years?
              Code debugging - Developing programs - MetaEditor Help
              Error Handling and Logging in MQL5 - MQL5 Articles (2015)
              Tracing, Debugging and Structural Analysis of Source Code - MQL5 Articles (2011)
              Introduction to MQL5: How to write simple Expert Advisor and Custom Indicator - MQL5 Articles (2010)

This MACDTrue indicator is a positive/negative double depending on above or below the 0 line.

macd>0 is positive double
macd<0 is negative double

IE: Printing out the variables results like this:

below 0 = EURUSD,H1: histo -5.722246927945219e-05

above 0 = EURUSD,H4: histo 0.0001497693524631791

 
Shouldn't these both exit the if condition when false ? 


      
      if (histo > 0)
         { 
         upcount= i;
         }
      else return;             //this returns upcount as expected

//Versus

         
      if (histo > 0)
         { 
         upcount= i;
         }
				//this one does not. 
I understand why "i" will keep counting up to 49, but I do not understand why upcount continues to get assigned i++ even after the condition is false.