MQL5 - HELP How to handle Custom indicator to different buffers of iEnvelopes (and others)?

pablocode
66
pablocode  

Hi everyone,

Here’s the question:

I get buffers from example indicator multiple buffers like iEnvelopes correctly through numbering in CopyBuffer

handle1 = iEnvelopes (NULL, 0, period, 0, method, price, deviation);
CopyBuffer (handle1, buffer=0,0,3, arrayUpper)> 0)
CopyBuffer (handle1, buffer=1,0,3, arrayLower)> 0)

but if I hook an indicator with


handle2 = iCustom (NULL, 0, “… indicator2”, period2, …, 0, handle1);
(CopyBuffer (handle2, buffer=0,0,3, array2upper)> 0)
(CopyBuffer (handle2, buffer=1,0,3, array3lower)> 0)

how can i get handle2’s extracted on two different buffers of handle1-iEnvelopes ???
it seems that handle2 (indicator attached to the Envelopes) has only one buffer and therefore returns all zero values

i need to extract two different buffers from iEnvelopes (Upper and Lower) to manage by two iCustom handles

does anyone have the solution?

I hope I have explained well
thanks in advance for any help

William Roeder
23729
William Roeder  

Perhaps you should read the manual, especially the examples.
   How To Ask Questions The Smart Way. 2004
      How To Interpret Answers.
         RTFM and STFW: How To Tell You've Seriously Screwed Up.

They all (including iCustom) return a handle (an int). You get that in OnInit. In OnTick (after the indicator has updated its buffers,) you use the handle, shift and count to get the data.
          Technical Indicators - Reference on algorithmic/automated trading language for MetaTrader 5
          Timeseries and Indicators Access / CopyBuffer - Reference on algorithmic/automated trading language for MetaTrader 5
          How to start with MQL5 - General - MQL5 programming forum - Page 3 #22 2020.03.08
          How to start with MQL5 - MetaTrader 5 - General - MQL5 programming forum - Page 7 #61 2020.07.05
          How to call indicators in MQL5 - MQL5 Articles 12 March 2010
pablocode
66
pablocode  
William Roeder:

Perhaps you should read the manual, especially the examples.
   How To Ask Questions The Smart Way. 2004
      How To Interpret Answers.
         RTFM and STFW: How To Tell You've Seriously Screwed Up.

They all (including iCustom) return a handle (an int). You get that in OnInit. In OnTick (after the indicator has updated its buffers,) you use the handle, shift and count to get the data.
          Technical Indicators - Reference on algorithmic/automated trading language for MetaTrader 5
          Timeseries and Indicators Access / CopyBuffer - Reference on algorithmic/automated trading language for MetaTrader 5
          How to start with MQL5 - General - MQL5 programming forum - Page 3 #22 2020.03.08
          How to start with MQL5 - MetaTrader 5 - General - MQL5 programming forum - Page 7 #61 2020.07.05
          How to call indicators in MQL5 - MQL5 Articles 12 March 2010

Thanks William

I looked at all documentation you attached above.. precious and complete

but those documentation I already knew, infact I have several EAs that work well on many indicators,

I can not understand the case of Envelopes,  why I do the following things ...

OnInit ()
... 
handle = iEnvelopes (NULL, 0, period, 0, method, price, deviation);
custom1handle = iCustom (NULL, 0, "indicator name", params ......, 0, handle);

      ArraySetAsSeries (arrayUpper, true); 	// Envelopes Upper Buffer
      ArraySetAsSeries (arrayLower, true);	// Envelopes Lower Buffer	
      ArraySetAsSeries (custom1array, true);	// custom1array copying Upper Buffer
      ArraySetAsSeries (custom2array, true);	// custom2array copying Lower Buffer
...

and so

OnTick ()
...
CopyBuffer (handle,0,0,3, arrayUpper)... to get arrayUpper "OK"; ...{Print ("Copy-arrayUpper error =", GetLastError ());}
CopyBuffer (handle,1,0,3, arrayLower)... to get arrayLower "OK"; 
... {Print ("Copy-arrayLower error =", GetLastError ());}

// and when I try to handle the custom indicator on the two Envelopes buffers I get an error on the second buffer

CopyBuffer (custom1handle,0,0,3, custom1array)... to handle UpperBuffer "OK"; 
... {Print ("Copy-custom1array (Upper) error =", GetLastError ());}
CopyBuffer (custom1handle,1,0,3, custom2array)... to handle LowerBuffer "ERROR"; 
... {Print ("Copy-custom2array (Lower) error =", GetLastError ());}
...

but in the end this error occurs for 

CopyBuffer (custom1handle,1,0,3, custom2array)

ERR_INDICATOR_DATA_NOT_FOUND

4806

Requested data not found


the question that comes to mind is:

on the custom indicator when it hooks handles of the first indicator Envelopes (which has two buffers) are both buffers are replicated? because it seems that only one is replicated on the handled custom indicator.


thanks

pablocode
66
pablocode  

why nobody reply?

i spent lot of time on forums here mql5.com and others but seems no one has a solution for that!

can anyone answer here?

thanks

Vladimir Karputov
Moderator
224703
Vladimir Karputov  
pablocode :

why nobody reply?

i spent lot of time on forums here mql5.com and others but seems no one has a solution for that!

can anyone answer here?

thanks

Take the trouble to create a minimal example that you can compile and test. Take the trouble to describe trading conditions: symbol, timeframe, date ...

pablocode
66
pablocode  

Hi Vladimir Karputov

here minimal code


at line 52

if i declare the copybuffer on 1 ---> CopyBuffer(DEMA2handle,1,0,5,DEMA2array)>0

when i try to use Lower Buffer on handle Envelopes, obtain 4806 with other smoothing indicator


if i declare the copybuffer on 0 ---> CopyBuffer(DEMA2handle,0,0,5,DEMA2array)>0

obtain bad datas because are calculated on default buffer Upper of Envelope


i need two arrays calculated on Upper and Lower Envelopes buffer, it's more clear now? 

Vladimir Karputov
Moderator
224703
Vladimir Karputov  
pablocode :

Hi  Vladimir Karputov

here minimal code


at line 52

if i declare the copybuffer on 1 --->  CopyBuffer(DEMA2handle,1,0,5,DEMA2array)>0

when i try to use Lower Buffer on handle Envelopes, obtain 4806 with other smoothing indicator


if i declare the copybuffer on 0 --->  CopyBuffer(DEMA2handle,0,0,5,DEMA2array)>0

obtain bad datas because are calculated on default buffer Upper of Envelope


i need two arrays calculated on Upper and Lower Envelopes buffer, it's more clear now? 

I will repeat once again: if you want to hear the answer - take the trouble to ask a question. Please provide the minimum MQL5 code. What you showed is a mockery and a torn piece of something incomprehensible.

pablocode
66
pablocode  

pablocode :

dear Vladimir Karputov

either there is a misunderstanding or you have problems with understanding,

1) I asked the question clearly but here it is again (what can't you understand?)

HOW CAN YOU GET THE DATA OF THE TWO ENVELOPES BUFFERS FROM A HANDLE OF A SECOND INDICATOR STICKED TO THE FIRST (a platform would be attaching a DEMA for example not to the price but to the FIRST INDICATOR IN THE CHART, and the first indicator in the chart is ENVELOPE)

if I try to use CopyBuffer on the Envelope handle but I want to use the Lower Buffer in runtime it gives me error 4806

2) I did the minimum code, I attached a zip file with EAs runnable with the code I'am talking about,

why did it disappear from the attachments in the post?


what is there that you are not able to understand ... can you put a little effort out of courtesy?

I did what you asked me to do


here I re-link the minimum code in a stackable EA d executable and I also stick it to you in the clear, so okay?


//+------------------------------------------------------------------+
//|                                                    EnvSmooth.mq5 |
//|                                  Copyright 2020,     Pablo Pisto |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, Pablo Code."
#property version   "1.00"

input int                ENVperiod    = 14;           
input ENUM_MA_METHOD     ENVmethod    = MODE_SMA;     
input ENUM_APPLIED_PRICE ENVPrice1    = PRICE_CLOSE;  
input double             ENVDeviation = 0.100;        

input int                DEMAperiod1  = 30;     
input ENUM_APPLIED_PRICE DEMAPrice1   = PRICE_CLOSE;  

input int                DEMAperiod2  = 50;     
input ENUM_APPLIED_PRICE DEMAPrice2   = PRICE_CLOSE;  

int ENVhandle,DEMA1handle,DEMA2handle;
double ENVarrayUpper[],ENVarrayLower[],DEMA1array[],DEMA2array[];

double ENV_Upper = 0, ENV_Lower = 0;
double DEMAUpper, DEMALower;
int barscc = 0;

int OnInit()
   {
      ENVhandle     = iEnvelopes(NULL,0,ENVperiod,0,ENVmethod,ENVPrice1/*applied price or handle*/,ENVDeviation);
      DEMA1handle = iCustom(NULL,0,"Examples\\DEMA",DEMAperiod1,DEMAPrice1,0,ENVhandle);
      DEMA2handle = iCustom(NULL,0,"Examples\\DEMA",DEMAperiod2,DEMAPrice2,0,ENVhandle);
      ArraySetAsSeries(ENVarrayUpper,true);
      ArraySetAsSeries(ENVarrayLower,true);
      ArraySetAsSeries(DEMA1array,true);
      ArraySetAsSeries(DEMA2array,true);
   
   return(INIT_SUCCEEDED);
   }

void OnTick()
   {
      barscc++;
      ENV_Upper=0;   
      ENV_Lower=0;
      DEMAUpper=0;   // smooth on Envelope Upper buffer      
      DEMALower=0;   // smooth on Envelope Lower buffer
   
      //bufferS: 0 - UPPER_LINE, 1 - LOWER_LINE.
      // THESE RETURN CORRECT DATA ON ENVELOPE'S HANDLE FOR BOTH BUFFERS	
      if(CopyBuffer(ENVhandle,0,0,5,ENVarrayUpper)>0)    ENV_Upper = ENVarrayUpper[1]; else {Print("Copy-ENVarrayUpper error =",GetLastError());}
      if(CopyBuffer(ENVhandle,1,0,5,ENVarrayLower)>0)    ENV_Lower = ENVarrayLower[1]; else {Print("Copy-ENVarrayLower error =",GetLastError());}
      
      // THIS RETURN CORRECT DATA ON DEMA'S HANDLE FOR UPPER ENVELOPE BUFFER
      if(CopyBuffer(DEMA1handle,0,0,5,DEMA1array)>0)     DEMAUpper = DEMA1array[1]; else {Print("Copy-DEMA1array(Upper) error =",GetLastError());}
       
      // THIS RETURN INCORRECT DATA 4806 ERROR FOR LOWER ENVELOPE BUFFER (that i need)	
      if(CopyBuffer(DEMA2handle,1,0,5,DEMA2array)>0)     DEMALower = DEMA2array[1]; else {Print("Copy-DEMA2array(Lower) error =",GetLastError());}
   
      Print("Time:",TimeCurrent()
            ," DEMAonUpper:",DoubleToString(NormalizeDouble(DEMAUpper,6),6)
            ," DEMAonLower:",DoubleToString(NormalizeDouble(DEMALower,6),6));
      if (barscc>5000) TesterStop();
   }

double OnTester()
   {
   return(1);
   }


note well,

before writing here I looked at all the mql5 documentation (iEnvelopes, iCustom, CopyBuffer, etc ...) and I can't understand why it is not possible to use the Lower buffer of Envelopes with the handle of another indicator attached

Documentation on MQL5: Timeseries and Indicators Access / CopyBuffer
Documentation on MQL5: Timeseries and Indicators Access / CopyBuffer
  • www.mql5.com
Counting of elements of copied data (indicator buffer with the index buffer_num) from the starting position is performed from the present to the past, i.e., starting position of 0 means the current bar (indicator value for the current bar). When copying the yet unknown amount of data, it is recommended to use a dynamic array as a buffer[]...
Vladimir Karputov
Moderator
224703
Vladimir Karputov  

I ran your example from a zip archive:


pablocode
66
pablocode  

OK

but with AMA the error 4806 occur if i use 

CopyBuffer(DEMA2handle,1,0,5,DEMA2array)

and if i use 

CopyBuffer(DEMA2handle,
0 ,0,5,DEMA2array)

the datas refears on Upper buffer of Envelopes (but i need the data of Lower buffer of Envelopes)


but I did what you asked me and if I tell you that errors or incorrect data come out it means that it is


soI'll ask you the question again, because that's what I need in the end


1) I set a handle on iEnvelopes to get the two buffers Upper and Lower


2) I set a second indicator attached to the Envelopes handle

but I need the final array to be calculated on the Lower buffer values and not the Upper buffer (default)


can you help me? do you know how to do it?

i don't understand why i can't get this answer


please do you know how to set the Copybuffer of an indicator (example AMA or DEMA, etc) attached to the first Envelopes indicator and calculated on its Lower buffer?


I hope I was even clearer

thanks

Vladimir Karputov
Moderator
224703
Vladimir Karputov  

You provided the code - I checked: no errors.

Want to ask a question: please provide the code.