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

 
lottamer:

i looked at it. it will take me a week to study it in details. but what's worse, i couldn't find any places that would be relevant to my task. i don't color indicators, and i don't modify them in any way. i just want to find maxima and minima on n-last bars. there's a hint of similarity in RSI_Extremums_Sample.mq4 but i can't handle this code. it's too much unnecessary, the indicator DRAWNS.... and i don't need it...


3173
artmedia70 27.10.2013 15:42 #
Forexman77:

Is it possible with the " ArrayMaximum" function, to calculate the nearest maximum of a custom indicator?

Or do I need other functions for that?

I have tried it this way:

And nothing comes out. Gurus, can you tell me how to do it?

   for (i=2; i<nBars; i++) {                    
      double a=iCustom(NULL, 0, "EMAF",0,0,i+1);
      double b=iCustom(NULL, 0, "EMAF",0,0,i);
      double c=iCustom(NULL, 0, "EMAF",0,0,i-1);
      if ((a-b)*(b-c)<0) {
         if (b<c) {                                
            // Нашли донышко
            }
         if (b>c) {                           
            // Нашли пичок
            }
         }
      }   
To search in the EA. NOT in an indicator.

 
lottamer:

The only thing I don't understand is how to calculate extrema of the MACD indicator, for example, instead of extrema of the price over n periods ?

I think I need to change HIGH and LOW to MACD in the key block... But I don't understand how ... all my attempts to goof around ended in nulling.

I understand that I need to create a MACD array...

double MACDBuffer[];

I've also seen such a string in other Expert Advisors

but I can't just measure one on the other...

Please, advise how to do it?


Article.
 

found something similar in Kim's

//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 17.05.2008                                                     |
//|  Описание : Возвращает значение максимального элемента массива.            |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    x - массив значений числового ряда                                      |
//+----------------------------------------------------------------------------+
double ArrayMax(double& x[]) {
  if (ArraySize(x)>0) return(x[ArrayMaximum(x)]);
  else {
    Print("ArrayMax(): Массив пуст!");
    return(0);
  }
}

question: how do I create an array of indicator values?

 
lottamer:

found something similar in Kim's

Question: how do I create an array of indicator values?

i reread what was asked, i got it wrong at first (

to get a buffer of indicator data, you can

1) run a loop with collecting iMACD values in the buffer

2) take the source code from the MACD, there is a buffer there

int start()
  {
   int limit;
   int counted_bars=IndicatorCounted();
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
//---- macd counted in the 1-st buffer
   for(int i=0; i<limit; i++)
      MacdBuffer[i]=iMA(NULL,0,FastEMA,0,MODE_EMA,PRICE_CLOSE,i)-iMA(NULL,0,SlowEMA,0,MODE_EMA,PRICE_CLOSE,i);
//---- signal line counted in the 2-nd buffer
   for(i=0; i<limit; i++)
      SignalBuffer[i]=iMAOnArray(MacdBuffer,Bars,SignalSMA,0,MODE_SMA,i);
//---- done
   return(0);
  }
 
ALXIMIKS:

reread what was asked, got it wrong at first(

To get a buffer with the data of an indicator you can:

1) run a loop with collecting iMACD values in the buffer

2) take the source code from the MACD where the buffer is


How do I visualize the buffer, otherwise I don't understand what to do with it....

Print(MACDBuffer[1]); ?? it prints zero... why? in theory it should be the value of the 1st bar....

and another thing... why calculate MACD using MA when there is a direct function iMACD ???

 
lottamer:


and how do i visualise the buffer otherwise i don't understand what to do with it....

Print(MACDBuffer[1]); ?? it prints zero...why? it should be the value of the 1st bar....

and another thing... why calculate MACD using MA, when there is a direct function iMACD ???


Please tell me what you need,

but it should be clearer, so that even a dumb person can understand it.

 
ALXIMIKS:


Please tell me what you want,

but in a clear way, so that even the dumb one understands.

I need to determine the minimum (as on the picture) and maximum values of the MACD indicator for a given number of bars. (20 in this case).

I found the code that does this for the price, and stupidly tried to replace HIGH LOW with MACD. but nothing worked....



 
artmedia70:
It is the job of the DCs to give a good story. They are lazy and always blame the MCs.


Thank you!
 
lottamer:

I need to determine the minimum (as shown in the picture) and maximum MACD indicator value for a given number of bars. (20 in this case).

I found a code that does this for price, and stupidly tried to replace HIGH LOW with MACD. but nothing worked....

Insert at the end of the custom MACD.
   int max,min,maxlast,minlast;
   max = ArrayMaximum(MacdBuffer,20,1);
   min = ArrayMinimum(MacdBuffer,20,1);
   if (max!=maxlast){
      ObjectDelete  ("highline");   
      ObjectCreate  ("highline",1,WindowOnDropped( ) ,0,MacdBuffer[max],0,0);
   }
   if (min!=minlast){
      ObjectDelete  ("lowline");   
      ObjectCreate  ("lowline",1,WindowOnDropped( ) ,0,MacdBuffer[min],0,0);
   }

PS. although this is more correct and better:

   int max,min;
   static double maxlast,minlast;
   max = ArrayMaximum(MacdBuffer,20,1);
   min = ArrayMinimum(MacdBuffer,20,1);
   if (MacdBuffer[max]!=maxlast){
      maxlast=MacdBuffer[max];
      ObjectDelete  ("highline");   
      ObjectCreate ("highline",1,WindowOnDropped( ) ,0,MacdBuffer[max],0,0);
   }
   if (MacdBuffer[min]!=minlast){
      minlast=MacdBuffer[min];
      ObjectDelete  ("lowline");   
      ObjectCreate ("lowline",1,WindowOnDropped( ) ,0,MacdBuffer[min],0,0);
   }
 
lottamer:

I need to determine the minimum (as shown in the picture) and maximum MACD indicator value for a given number of bars. (20 in this case).

I found a code that does this for price, and stupidly tried to replace HIGH LOW with MACD. but nothing worked....


Copy the MACD data you need into massMACD[20] array and find the minimum ArrayMinimum(massMACD); and
maximum ArrayMaximum(massMACD); values in that array.