Questions from Beginners MQL5 MT5 MetaTrader 5 - page 807

 
DCodec:

Honestly, I don't understand anything. I need indicator top line values on Close[2], Close[1] and that's it.

How to draw these values from ANY indicator so as not to "mess up" the code of the indicator.


You can get values of any indicator buffer on any BAR, not on Close... SeeiCustom help:

iCustom

Returns the handle of the specified custom indicator.

Procedure:

  • In OnInit() create an indicator handle
  • in OnTick() or OnTime() get indicator data at the specified BAR number from the required INDICATOR buffer.

 
Vladimir Karputov:

You can get the values of any indicator buffer on any BAR, not on Close... SeeiCustom help:

iCustom

Returns the handle of the specified custom indicator.

Procedure:

  • In OnInit() create an indicator handle
  • in OnTick() or OnTime() get indicator data at the specified BAR number from the required INDICATOR buffer.

Yes, I got it wrong. I need the indicator values on the first and second bars. But let's say Bollinger Bands has three lines. Which line it returns value to me? I apologise for the stupid questions, but I'm really confused.
 
DCodec:
Yes, I misspoke. I want indicator values on the first and second bars. But let's say Bollinger Bands has three lines. Which line is it returning to me? I apologise for the stupid questions, but really STUPOR.

Just a moment ...

Here is the function to retrieve values from iBands:

//+------------------------------------------------------------------+
//| Get value of buffers for the iBands                              |
//|  the buffer numbers are the following:                           |
//|   0 - BASE_LINE, 1 - UPPER_BAND, 2 - LOWER_BAND                  |
//+------------------------------------------------------------------+
double iBandsGet(const int buffer,const int index)
  {
   double Bands[1];
//ArraySetAsSeries(Bands,true);
//--- reset error code 
   ResetLastError();
//--- fill a part of the iBands array with values from the indicator buffer that has 0 index 
   if(CopyBuffer(handle_iBands,buffer,index,1,Bands)<0)
     {
      //--- if the copying fails, tell the error code 
      PrintFormat("Failed to copy data from the iBands indicator, error code %d",GetLastError());
      //--- quit with zero result - it means that the indicator is considered as not calculated 
      return(0.0);
     }
   return(Bands[0]);
  }

The function is truncated - its purpose is to get always ONLY ONE value from the indicator buffer "buffer" on bar number "index".

All three lines of iBands have their own constants:

//|   0 - BASE_LINE, 1 - UPPER_BAND, 2 - LOWER_BAND                  |
 
Vladimir Karputov:

Just a moment ...

Here is the function to retrieve values from iBands:

The function is truncated - its purpose is to get always ONLY ONE value from the indicator buffer "buffer" on bar number "index".

All three iBands lines have their own constants:

Yes...yes. That's just how I don't understand how to apply

//|   0 - BASE_LINE, 1 - UPPER_BAND, 2 - LOWER_BAND  

It's probably from narrow-mindedness. I'm still thinking like in MQL4.

 
DCodec:

Yes... yes. That's how I don't understand how to apply

It's probably due to narrow-mindedness. I'm still thinking in terms of MQL4.


Example of using iBands from KodoBase:Bollinger Bands RSI

 
DCodec:

...


Any luck? Or create a topic with a step-by-step write up of getting data from the indicator?

 
Vladimir Karputov:

How's it going? Or create a topic with a step-by-step write-up of how to retrieve data from the indicator?

You are amused. I'm just now realizing that I'm in

CopyBuffer

That's what I need.

CopyBuffer(handle_iBands,buffer,index,1,Bands)

Thank you.

 

I have one more question. How can I disable a line in an indicator that I don't need?

Let's say to disable UPPER_LINE in iEnvelopes.

 
DCodec:

You are laughing. And I have only now realized that I am not funny.

that's what I need.

Thank you.


You're imagining things. I wasn't laughing, I was asking seriously. For example, I have this topic:Simple Expert Advisor. Checking bar size. Buy/sell.


DCodec:

I will allow myself one more question. How do I disable the line in the indicator that I do not need?

Let's say to disable UPPER_LINE in iEnvelopes.


The question is not clear. Describe more precisely WHERE and WHAT you want to do.

 
Vladimir Karputov:

You imagined it. I wasn't laughing, I was asking seriously. For example, I have this topic:Simple Expert Advisor. Checking bar size. Buy/Sell.



The question is not clear. Describe more precisely WHERE and WHAT you want to do.

When an EA receives an indicator handle in OnInit() ...

int OnInit()
  {
//--- Получить хэндл индикатора Envelopes_upper для отрисовки верхней линии
   EnvHandle_upper=iEnvelopes(NULL,0,Period_upper,0,MODE_SMA,PRICE_MEDIAN,Deviation_upper);

....terminal draws both lines, I need only the top line.

How to disable drawing of this line? I.e. change its colour to CLR_NONE, or change the line style to DRAW_DONE?