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

 
Alexey Viktorov:

Yeah and I looked it up to answer you too.

I couldn't - I was writing from my phone and it's quicker just to write the question :)

 
Alexey Viktorov:

It's not imposed by the developers, but by one moderator. As for the BB values, so Artem told you that it's easier to get everything directly... the sequence is like this...

  1. Declared Handle variables and arrays to get indicator values. If necessary, 3 at most. If we don't need an average, two arrays will be enough.
  2. In OnInit() we received the indicator handle...
  3. In OnTick() or in some other function CopyBuffer() for each line separately, as many as necessary.
  4. From these arrays you get the values of indicator lines on those bars which are interesting...

THAT'S IT. Why bother with OOP¿¿¿¿¿? Unfortunately, I can't answer your question directly, because I'm not using it. It's easier for me as I described. There are only 4 actions.

Please tell me why it does not work in Inite? And how do I make it work?


#property strict

//--- индикаторные буферы
double         UpperBuffer[];
double         LowerBuffer[];
double         MiddleBuffer[];
//--- переменная для хранения хэндла индикатора iBands
int    bb_handle;

int OnInit(){//////////////***OnInit()****///*************OnInit()*******/////////***/////////////////////////OnInit()

bb_handle=iBands(NULL, 0, 20, 0, 2.0, PRICE_CLOSE);

Print("bb_handle ", bb_handle);

Print("OnInit()  ", BB_up(0), "  ", BB_mi(0), "  ", BB_lo(0));

return(INIT_SUCCEEDED);
}
void OnTick(){




Print("OnTick()  ", BB_up(0), "  ", BB_mi(0), "  ", BB_lo(0));

}
//-------------------------------------------------------1
double BB_up(int in_shift){
   CopyBuffer(bb_handle, 1, in_shift, 1, UpperBuffer);
   return UpperBuffer[0];
}
double BB_mi(int in_shift){
   CopyBuffer(bb_handle, 0, in_shift, 1, MiddleBuffer);
   return MiddleBuffer[0];
}
double BB_lo(int in_shift){
   CopyBuffer(bb_handle, 2, in_shift, 1, LowerBuffer);
   return LowerBuffer[0];
}
 
Andrey Sokolov:

Can you tell me why it doesn't work in the Inite? And how do I make it work?


iBands - Technical Indicators - MQL5 Reference - Algorithmic/Automatic Trading Language Reference for MetaTrader 5
Документация по MQL5: Технические индикаторы / iBands
Документация по MQL5: Технические индикаторы / iBands
  • www.mql5.com
iBands - Технические индикаторы - Справочник MQL5 - Справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
 
Andrey Sokolov:

so why isn't it working?

Do you want to talk? - Or do you want to work on yourself?

 
SanAlex:

Do you want to talk? - Or would you like to work on yourself?

I see. Thank you. Can anyone else suggest something?

 
Andrey Sokolov:

Can you tell me why it doesn't work in the Inite? And how do I make it work?


Because the indicator has not yet been calculated.

https://www.mql5.com/ru/docs/series/barscalculated


the OnInit() section is not the best place to get the terminal environment, I think it works logically and correctly
 
Igor Makanu:

because the indicator has not yet been calculated

https://www.mql5.com/ru/docs/series/barscalculated

👍

 
Igor Makanu:


the OnInit() section is not the best place to get the terminal environment, I think it works logically and correctly

Inite because you need to do calculations on history at startup, added a wait as in the example, all is fine, thanks

 
Andrey Sokolov:

added a wait, as in the example, everything is fine.

Just don't be surprised when it stops workingor worksintermittently.