user1582596
user1582596

Reputation: 503

MQL4: Issue with finding low value

I am trying to get the highest and lowest value from last 20 bar. I have no issue to obtaining highest value, however my code doesn't seem to work properly in order to obtain the lowest value. Just wondering if there is any suggestion about it.

OnEveryNewBar1();

void OnEveryNewBar1()
{   PipValue = 1;
    if ( NDigits == 3 || NDigits == 5 ) PipValue = 10;
    if ( BarTime1 < Time[0] )  // we have a new bar opened
    {    BarTime1 = Time[0];   // keep the new bar open time
         TechnicalAnalysis_S();
         TechnicalAnalysis_L();
     }
}

void TechnicalAnalysis_S()
{
   int m =    2;
   int n =    3;
       l = 1000;
   while ( m <= 20 )
   {
      if ( 1 < 2 )
      {    if ( ( Close[2] > Open[2] ) || ( Close[1] > Open[1] ) ) int i = 2;
           while ( i > 0 )
           {
               if ( Low[i] < l ) l = Low[i];
               i = i - 1;
           }
           print ( "Lowest" + l );
           l = 1000;
      }
      m++;
      n++;
   }
}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void TechnicalAnalysis_L()
{    
     int m = 2;
     int n = 3;
     while ( m <= 20 )
     {
         if ( 2 > 0 )
         {
              if ( ( Close[2] < Open[2] ) || ( Close[1] < Open[1] ) ) int i=2;
              while ( i > 0 )
              {
                  if ( High[i] > h ) h = High[i];
                  i = i - 1;
              }
              print ( "Highest" + h );
              h = 0;
         }
         m++;
         n++;
     }
}

Upvotes: 1

Views: 1127

Answers (1)

user3666197
user3666197

Reputation: 1

While there are some strange parts in the code, while some variables are missing their declaration, the language has built-in functions for this.

Solution:

double   aLowestLOW_InTheLast20BARs,
       aHighestHIGH_InTheLast20BARs;
// -----------------------------------------------------------------------------    
   aLowestLOW_InTheLast20BARs =    Low[iLowest(  _Symbol,         // .self
                                                 PERIOD_CURRENT,  // .self
                                                 MODE_LOW,        // LOW
                                                 20,              // Last 20 BARs
                                                  0               // from [0]
                                                 )
                                       ];
// -----------------------------------------------------------------------------
   aHighestHIGH_InTheLast20BARs = High[iHighest( _Symbol,         // .self
                                                 PERIOD_CURRENT,  // .self
                                                 MODE_HIGH,       // HIGH
                                                 20,              // Last 20 BARs
                                                  0               // from [0]
                                                 )
                                       ];

Upvotes: 1

Related Questions