Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 278

 
mila.com:

I cannot make it out with my cyclops and correctly enter its indicator.

Your script returns zero at all settings. It is supposed to return a three, because now the difference between the first and the third bar is 0.005.

Maybe I wasn't clear. I want to put this in the loop.


double ma_etalon=iMA(NULL,0,...,i+1);

double ma_curr;

int shift;

for(shift=2;shift<5;shift++) {

    ma_curr=iMA(NULL,0,...,i+shift);

    if (ma_etalon-ma_curr<0.005) break; // ах ты чёрт, значение близко

}

if (shift==5) {

   // цикл досчитал до конца, то есть все значение довольно далеко
   // ... развернись плечо ...

}

 
mila.com:

Thank you, but something's not right.


0.005 is measured in what? (must be multiplied by _Point)
 

Thank you all for your help, it worked )

 
mila.com:

Thank you all for your help, it worked )

Just wondering, did you need one of these?

 double prevMA=0,currMA=0;
 for(int i=1;i<=5;i++) {
  if(i==1) currMA=iMA(Symbol(),0,14,0,MODE_EMA,PRICE_CLOSE,i);
  prevMA=iMA(Symbol(),0,14,0,MODE_EMA,PRICE_CLOSE,i);
  if(MathAbs(prevMA-currMA)>0.0005) {
   // сюда пишем в буфер
   break;
  }
 }
 
Vitaly Muzichenko:

Just wondering, was there a need for such a thing?

Yes, and how do you fit this design into the main loop of the indicator?

 
Vladimir Pastushak:

I told you clearly in trailing you put 0 instead of take

Check this option.


It works!!! :)))).... Thank you so much for putting up with us losers)))))) Thank you very much!)

 

Good afternoon.

Can you please advise how iCustom can be used to get an indicator value on another timeframe with a shift?

I.e. I am working on M5, I want to get the indicator value from M15, and from the previous candle on M15.

int start() 
{ 
  HistBar = History;
  int i,counted_bars = IndicatorCounted();
  if (counted_bars < 0) return (-1);
  if (counted_bars > 0) counted_bars--;
  int limit = MathMin(Bars-counted_bars,HistBar+100);

  for(i=limit; i>=0; i--)
   {  
   int HT1,HT2; 
        if (_Period == PERIOD_M1)  
            {HT1 = PERIOD_M5;
            HT2 = PERIOD_M15;}
        else
           {
           if (_Period == PERIOD_M5)  
            {HT1 = PERIOD_M15;
            HT2 = PERIOD_M30;}
           else
              {
              if (_Period == PERIOD_M15)  
               {HT1 = PERIOD_M30;
               HT2 = PERIOD_H1;}
               }
            }
   //MFI
   long Volume_0_0 = iVolume(NULL,0,i);
   long Volume_0_1 = iVolume(NULL,0,i+1);
   double BWMFI_0_0 = iBWMFI(NULL,0,i);
   double BWMFI_0_1 = iBWMFI(NULL,0,i+1);

   ///////// вопрос как тут указать правильно
   long Volume_1_0 = iVolume(NULL,HT1,i);
   long Volume_1_1 = iVolume(NULL,HT1,i+1);
   double BWMFI_1_0 = iBWMFI(NULL,HT1,i);
   double BWMFI_1_1 = iBWMFI(NULL,HT1,i+1);
   ....
}
 
LSM:

Good afternoon.

Can you advise how iCustom can be used to get an indicator value at another timeframe with a shift?

I am working on M5, I want to get the indicator value from M15, and I want to get the value of the previous candle on M15.

It is enough to carefully read the documentation

double  iCustom(
   string       symbol,           // имя символа
   int          timeframe,        // таймфрейм
   string       name,             // папка/имя_пользовательского индикатора
   ...                            // список входных параметров индикатора
   int          mode,             // источник данных
   int          shift             // сдвиг
   );
 
Alexey Viktorov:

Just read the documentation carefully

Edited my question, added the code. There is a loop going on. It's not clear what I get when it happens in a loop.
 
LSM:
I edited my question and added code. There is a loop going on. It's not clear what I'll get when it happens in a loop.

I'll answer my own question, in case someone needs it.)

   
   !!!!
   int y = iBarShift(NULL,HT1,Time[i]);
   
   long Volume_1_0 = iVolume(NULL,HT1,y);
   long Volume_1_1 = iVolume(NULL,HT1,y+1);
   double BWMFI_1_0 = iBWMFI(NULL,HT1,y);
   double BWMFI_1_1 = iBWMFI(NULL,HT1,y+1);
Reason: