Help me with this part of my code - page 2

 

Ok - last post from me. If you are going to program you really should understand the data your program is working with.
a) you are assuming the data does have low and a top
b) you are not taking into account two numbers of the same value next to each other does not necessarily make a low or a top

If link I gave you has code you can download and look at which gives you an idea of how someone else solved the
problem of finding a high point and a low point.

The way the code is written makes it difficult to read and there is no explanation of the method you are
using to find a top or low, the difficult layout is not explanation enough.

Finding why a program does not work can sometimes only be done by you pretending to be the computer.

Use the print statment and look at what your program actually does rather than looking at the code and
assuming the the logic works the way you think it should.

Your condition, which may have been what you intended,
if (max==High[y]) break:
is very odd as each low or high value is unlikely to equal or be anywhere near any other low high.
Each Low[i] is the y co-ordinate of a (x,y) co-ordinate or pencil points on a graph with x-axis as
descrete points in time. However since it is your logic, for all I know this might be intentional
on your part and be part of your method.

adapting the fractal code a bit while not conclusive in finding a high you could have used
------
bFound=false;
for(i=1,i<bars-1,i++)
{
max=High[i]; // Assume my bar[i] is the highest then the two bars either side of me must be lower
if( ( max>High[i+1] ) && max>High[i-1] )
{
bFound=true; // nearest high found.
break:
}
}
------

I have not bothered to check if the breakout logic is correct.

Nobody has to answer your question. People who answer don't know how much or how little you know
nor will they necessarily understand what your intentions are.

 
I'm really sorry I wasn't in a good mood when I wrote that. I sincerely apologize and thank you for your help.
OK here is my code with the description of what it's meant to do and the logic behind it.
//here I define the variables check and check1 so that I don't get 
// several alerts for every bar.
double check,
check1;
int start()
  {
// my first goal is to find the minimum and maximum points within the closest 17 bars
// and see whether this minimum or maximum is the one exactly in the middle or not
// if so we have found the minimum or maximum we are looking for otherwise we keep
// looking. 
  double min=Low[1],
         max=High[1];
  int a=17,
      m=1,
      n=1,
      x=23,
      y=9,
      b=9;       
    //here we find the minimum value among "a" number of bars
  for(int c=m;c<a;c++)
 {
  if (Low[c]<=min)
   min=Low[c];
  if (c!=a-1)
  continue;
//at this point we have found the minimum value but we have to see if 
// it is the one exactly in the middle or in other words is it equal to Low[b]
// if so we have found it otherwise we add the values of "a" and "b" and keep on
// looking.
  if (min>=Low[b]-0.0001 && min<=Low[b]+0.0001)
   {
   if (check!=Close[1]-High[1])
   {
Alert ("min is ", min, c);
check=Close[1]-High[1];
   }
  break;
   }       
a++;
b++;
m++;
c=1;
 }
//here we find the maximum value among "x" number of bars
 for(int z=n;z<x;z++)
 {
  if (High[z]>=max)
   max=High[z];
  if (z!=x-1)
  continue;
//at this point we have found the maximum value but we have to see if 
// it is the one exactly in the middle or in other words is it equal to High[y]
// if so we have found it otherwise we add the values of "x" and "y" and keep on
// looking
  if (max>=High[y]-0.0001 && max<=High[y]+0.0001)
       { 
        if (check1!=Close[2]-High[2])
       {
Alert ("max is ", max ,z);
check1=Close[2]-High[2];
       }      
  break;
       }     
   x++;
 y++;
 n++;
 z=1;  
 }
 }
If I missed sth please let me know!
 

Hello Farhang

God gave the names of every thing and taught human to know them.
So please try the same to give the beautiful names to your program elements.
This sample may be useful: https://www.mql5.com/en/forum/124521/page4

Best regards

 
//There might be syntax errors in my alternate code as I have not tried compiling it
//The following is only to be used as a sugestion to improving on or rewriting 
//the origional code


//here I define the variables check and check1 so that I don't get 
// several alerts for every bar.
double check,
check1;
int start()
  {
// my first goal is to find the minimum and maximum points within the closest 17 bars
// and see whether this minimum or maximum is the one exactly in the middle or not
// if so we have found the minimum or maximum we are looking for otherwise we keep
// looking. 
  double min=Low[1],
         max=High[1];
  int NearBarsLow=17, //a
      LowBarStart=1,  //m
      MidBarsLow=9;   //b
      HighBarStart=1, //n 
      NearBarsHigh=23,//x
      MidBarsHigh=9,  //y
       
    //here we find the minimum value among "a" number of bars
  for(int c=LowBarStart;c<NearBarsLow;c++)
{
  if (Low[c]<=min) min=Low[c]; //My layout preference for this type of code
  if (c!=NearBarsLow-1) continue;
//at this point we have found the minimum value but we have to see if 
// it is the one exactly in the middle or in other words is it equal to Low[b]
// if so we have found it otherwise we add the values of "a" and "b" and keep on
// looking.
  if (min>=Low[MidBarsLow]-0.0001 && min<=Low[MidBarsLow]+0.0001)
   {
   if (check!=Close[1]-High[1])    //What is this for? check initialised to 0 otherwise unassigned value
      {                            //Perhaps meant Bool AlertLow=false ; then replace if (check !=Close...) with If (!AlertLow)
       Alert ("min is ", min, c);
       check=Close[1]-High[1];  //AlertLow=true;
      }
   break;
   }       
  NearBarsLow++; //increased by 1 so even number of *localbars* so MidBarsLow now has no middle
               //or is middle shifted up one deliberate?
  MidBarsLow++;
  LowBarStart++; //Has no effect as for loop has started and the varable c is set when loop initialised
  c=1; //Sets the loop start back at one - I think the intention here was c=LowBarStart Note ++ is either prefix or postfix so
     //have to be careful when using it in assignment statements
}//End for loop c

//here we find the maximum value among "x" number of bars
for(int z=HighBarStart;z<NearBarsHigh;z++)
{
  if (High[MidBarsHigh]>=max) max=High[MidBarsHigh];
  if (z!=NearBarsHigh-1) continue;
//at this point we have found the maximum value but we have to see if 
// it is the one exactly in the middle or in other words is it equal to High[y]
// if so we have found it otherwise we add the values of "x" and "y" and keep on
// looking
  if (max>=High[y]-0.0001 && max<=High[y]+0.0001)
     { 
        if (check1!=Close[2]-High[2]) //Same as coments for finding Low
         {
          Alert ("max is ", max ,z);
          check1=Close[2]-High[2];
         }      
      break;
     }     
   NearBarsHigh++;
   MidBarsHigh++;
   HighBarStart++;
   z=1;  
}//End for loop z
}//End Int Start

//-------------------Alternate code sugestion - find bar number with local lowest value and highest value
min=10000.0 ; max=0.0
for (count=1;count<=LocalBars;count++)
  {
   if (min < Low[count]) 
      {
       min=Low[count] ;
       minbar=count ;
      }
   if (max > High[count])
      {
       max = High[count] ;
       maxbar = count ; 
      }
  }
--------------------------- Alternatively
for (count=2;count<=bars-1;count++) //count must be >=2 
{
If(Low[count-1]>Low[count] && Low[count]<Low[Count+1]) 
   {
    FirstLowBar=count ;
    //check if my lowest local low if that is what is required - note that it wont find a 'flat' low or high
    break ;
   }
}
for (count=2;count<=bars-1;count++)
{
If(High[count-1]<High[count] && High[count]>High[Count+1]) 
   {  
    FirstHighBar=count ;
    break ;
   }
}
 
Ickyrus:

code for determining if the Highest bar of x number of bars is in the center : (1 statement)

bool IsMiddleBar = iHighest(NULL, 0, MODE_CLOSE, iEnd,iBegin ) == (iEnd+iBegin)/2;

Easy once you think it out before diving into the code

 

At the time I wrote this I was not aware of the iHighest function!

Reason: