Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 1083

 

So it's a static array

//--- создадим массив 
   double array[]; 
   int size=772; 
   ArrayResize(array,size); 
   //---  заполним его значениями индикатора 
   for(int i=0;i<size;i++) 
     { 
      array[i]=iATR(NULL,0,14,i);
     }
   //--- найдем позицию максимального элемента в массиве 
   int max_position=ArrayMaximum(array,772,0); 
   //--- теперь получим само максимальное значение в массиве 
   double max=array[max_position];
 

So, in fact I write directly - self-taught, not far in understanding of subtleties of perception of programmer's being (And the theme is called: Any question of a beginner...). I give an example, that will not be reproached that all want to get for free, without effort, and on the other hand trying to clearly define the task (not to say that we can not read minds of others).

Once again, how to get the maximal value of indicator for the given amount of last bars from the given code or may be by the grace of understanding in the personal statement of coding?

With sincere respect, deference and understanding that programmers are people from another world and such a delicate explanation is not the fact that all of the above will have to be outlined again, perhaps more than once to get the desired result.

//--- create array double array[]; int size=772; ArrayResize(array,size); //---fill it with indicator values for(int i=0;i<size;i++) { array[i]=iATR(NULL,0,14,i);
} //--- find the position of the maximal element in the array int max_position=ArrayMaximum(array,772,0); //--- now let's get the maximal value in the array itself double max=array[max_position];
 

I searched all I could but i couldn't find any solution, last hope on you guys :)

The general task was to make an indicator, which, when thrown on a chart, i.e. it is already working, we press the specified key and the trend line (date1=date2, price1=price2) appears under the current cursor position

The problem arose when I can't getif(id==CHARTEVENT_MOUSE_MOVE) to pass the coordinates of the pointer toif(id==CHARTEVENT_KEYDOWN), and the code below also does not want to pass them. I don't know how to do it, but there is another variant, but it also has a problem. Maybe somebody knows, when you throw the indicator on the chart, the initial menu appears.

#property strict
#define  VK_D             0x44 


int OnInit()
  {
//---
   ChartSetInteger(0,CHART_EVENT_MOUSE_MOVE,true);

   return(INIT_SUCCEEDED);
  }

//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
{    
 
if(id==CHARTEVENT_MOUSE_MOVE)

{     int      x     =(int)lparam;
      int      y     =(int)dparam; 
      datetime dt    =0; 
      double   price =0; 
      int      window=0;
      ChartXYToTimePrice(0,x,y,window,dt,price); 


  if(id==CHARTEVENT_KEYDOWN)
{ 
  switch(int(lparam)) 
{ case VK_D:
   
   ObjectCreate("Trend Line",OBJ_TREND,0,dt,price,dt,price);
   ObjectSetInteger(0,"Trend Line",OBJPROP_SELECTED,true); 
}   
} 
}    
}
 
Craft:

So, in fact I write directly - self-taught, not far in understanding of subtleties of perception of programmer's being (And the theme is called: Any question of a beginner...). I give an example, that will not be reproached that all want to get for free, without effort, and on the other hand trying to clearly define the task (not to say that we can not read minds of others).

Once again, how to get the maximal value of indicator for the given amount of last bars from the given code or may be by the grace of understanding in the personal statement of coding?

With sincere respect, reverence and understanding that programmers are people from another world and such a delicate explanation is not the fact that all of the above will have to be outlined again, perhaps more than once to get the desired result.


So reverse the loop and that's it.

From rates_total-1 to rates_total minus the desired_number_of_balls. If in EA, from Bars()-1 to Bars() minus...

 
K_i_r_i_t_o:

I searched all I could but i couldn't find any solution. I have no hope for you guys :)

The general task was to make an indicator, which, when thrown on a chart, i.e. it is already working, we press the specified key and the trend line (date1=date2, price1=price2) appears under the current cursor position

The problem arose when I can't getif(id==CHARTEVENT_MOUSE_MOVE) to pass coordinates of the pointer toif(id==CHARTEVENT_KEYDOWN), and the code below also does not want to pass them, I don't know how to implement it, there is another option, but it is also a problem, if anyone knows, when you throw the indicator on the chart the initial menu appears, so can I lock it somehow, so that the indicator will appear on the chart immediately?

Pay attention to the variable visibility.

I haven't delved into it deeply, but I noticed that the variables are declared inside the condition. This should not be the case.

 
AlexeyVik:

Pay attention to the visibility of variables.

I haven't delved too deeply, but I noticed that the variables are declared inside the condition. This should not be the case.

So that's the problem, how to make variables to be passed from one if to another, tried many variations, doesn't want to work...
 
K_i_r_i_t_o:
So that's the problem, how to make variables to be passed from one if to another, tried many variations, doesn't want to work...

You can read it here.

What many variations? Global level variables are visible in any part of the program, this is an extreme case.

 
AlexeyVik:

Read it here.

What are the many variations? Global level variables are visible in any part of the program, this is an extreme case.

I read it all, that's the point, I can't transfer the variable values to another function, and there's no way to collect them in one function, I'm stumped, but what about the indicator menu?
 
Craft:

Good afternoon, gentlemen.

Question on arrays. How to find the largest value of the indicator on the required number of last bars of the chart, and not the first?

It has been discussed many times (I cannot find it), but I have rarely used arrays.

Could you advise how to solve the problem with indexing, perhaps by using ArrayMaximum(array) in a more elegant way?

If there's an elementary mistake somewhere, I'm sorry, I'm self-taught.

The flow of bug fixes in MQL4 builds never fades, sothe simpler the code, the more reliable it is .

Amax=-10000;

iAmax=-1;

for(int i=0;i<size;i++) {

if (array[i]>Amax) {iAmax=i; Amax=array[i];}

}

if (iAmax<0) ...something is wrong

 
Well, does anyone know if it is possible to remove the start menu itself from the "navigator-start indicator-start menu-work indicator" chain? much needed, help!!!!!
Reason: