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

 
Vladimir Karputov:

You provided the code - I checked: no errors.

Want to ask a question: please provide the code.

I believe that the problem was clearly posed from the beginning, but I understand that making an extra effort on your part could be a nuisance, so here is an emblematic case I refer to...

//+------------------------------------------------------------------+
//|                                                    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                AMAperiod1= 30;     
input int                AMAfast1  = 100;     
input int                AMAslow1  = 20;     

input int                AMAperiod2= 50;     
input int                AMAfast2  = 90;     
input int                AMAslow2  = 40;     

int ENVhandle,AMA1handle, AMA2handle;
double ENVarrayUpper[],ENVarrayLower[];
double AMA1array[],AMA2array[];

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

int OnInit()
   {
      ENVhandle     = iEnvelopes(NULL,0,ENVperiod,0,ENVmethod,ENVPrice1/*applied price or handle*/,ENVDeviation);
      AMA1handle = iCustom(NULL,0,"Examples\\AMA",AMAperiod1,AMAfast1,AMAslow1,0,ENVhandle);
      AMA2handle = iCustom(NULL,0,"Examples\\AMA",AMAperiod2,AMAfast2,AMAslow2,0,ENVhandle);
      ArraySetAsSeries(ENVarrayUpper,true);
      ArraySetAsSeries(ENVarrayLower,true);
      ArraySetAsSeries(AMA1array,true);
      ArraySetAsSeries(AMA2array,true);
   
   return(INIT_SUCCEEDED);
   }

void OnTick()
   {
      barscc++;
      ENV_Upper=0;   
      ENV_Lower=0;
      AMAUpper=0;   // smooth on Envelope Upper buffer      
      AMALower=0;   // smooth on Envelope Lower buffer
   
      //bufferS: 0 - UPPER_LINE, 1 - LOWER_LINE.
      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());}
      
      // CASE 0
      // try to smooth AMA on Envelope Upper buffer
      if(CopyBuffer(AMA1handle,0,0,5,AMA1array)>0) {
         AMAUpper = AMA1array[1]; 
         Print("Time:",TimeCurrent()," AMAonUpper:",DoubleToString(NormalizeDouble(AMAUpper,6),6));
         }
      else {Print("Copy-AMA1array(Upper) error =",GetLastError());}
      
      // CASE 1
      // try to smooth AMA on Envelope Lower buffer
      if(CopyBuffer(AMA2handle,1,0,5,AMA2array)>0) {
         AMALower = AMA2array[1];
         Print("Time:",TimeCurrent()," AMAonLower:",DoubleToString(NormalizeDouble(AMALower,6),6));
         }
      else {Print("Copy-AMA2array(Lower) error =",GetLastError());}
   
      if (barscc>5000) TesterStop();
   }


double OnTester()
   {
   return(1);
   }


i try to calculate AMA smooth on Envelopes buffers

at CASE 1 occur 4806 i think don't find the buffer but i need to calculate second AMA on Lower Buffer of Envelopes handle

(see attached image file)

if on CASE 1 i put this  -> Copybuffer handle,0,0,5 

 // CASE 1
      // try to smooth AMA on Envelope Lower buffer
      if(CopyBuffer(AMA2handle,0,0,5,AMA2array)>0) {
         AMALower = AMA2array[1];
         Print("Time:",TimeCurrent()," AMAonLower:",DoubleToString(NormalizeDouble(AMALower,6),6));
         }
      else {Print("Copy-AMA2array(Lower) error =",GetLastError());}

it no longer gives error 4806 but returns values that are always calculated on the Upper buffer of Envelopes


and I don't understand why in the handle ENVhandle (of iEnvelopes) there are the two buffers while if I attach another indicator handle superior to the one it seems to return only one buffer and it is not clear on all documentation mql5 / codebase how to refer to the second buffer the Lower one

explained once again, if I want to get an array on indicator attached to another indicator (in the MT4 chart it is the fx "Datas of Previous indicator / First indicator") calculated on each different buffer of the first indicator, how is it possible to do?


NOW CAN YOU FINALLY HELP ME IN A SOLUTION OR ALSO THIS TIME I'M WASTING TIME?

MQL5.community - User Memo
MQL5.community - User Memo
  • www.mql5.com
You can now not only read articles and download MQL5 programs, but you can also join discussions on the forum, leave comments on articles and source codes, rate MQL5 programs and share your own developments in the Code Base, and even publish articles for a decent fee (see Become an Author at MQL5.com!). MQL5.com services are constantly...
Files:
error4806.png  13 kb
 

Before mindlessly requesting data, you need to study the indicator.

Here is the header of the 'AMA.mq5' indicator

//+------------------------------------------------------------------+
//|                                                          AMA.mq5 |
//|                   Copyright 2009-2020, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright   "2009-2020, MetaQuotes Software Corp."
#property link        "http://www.mql5.com"
#property version     "1.00"
#property description "Adaptive Moving Average"

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots   1

as you can see in the indicator ONLY ONE buffer! Question: if the indicator has ONE buffer, WHY are you trying to get data from a non-existent buffer?

// CASE 1
// try to smooth AMA on Envelope Lower buffer
   if(CopyBuffer(AMA2handle,1,0,5,AMA2array)>0)


Be more attentive next time.

 
Vladimir Karputov:

Before mindlessly requesting data, you need to study the indicator.

Here is the header of the 'AMA.mq5' indicator

as you can see in the indicator ONLY ONE buffer! Question: if the indicator has ONE buffer, WHY are you trying to get data from a non-existent buffer?


Be more attentive next time.


but I know this, I'm not a beginner, be more attentive you to my question please,

I asked how I can calculate an AMA on the lower buffer of iEnvelopes, for this I set two AMA handles on ENVhandles (which has two buffers 0 = Upper 1 = Lower) because the first array on AMA1handle is calculated correct on the Upper buffer of Envelopes (already verified) but if I also want a second array I set another handle that is AMA2handle always on ENVhandle but I don't understand how to get the array calculated this time on the Lower buffer


now do you understand or are you turning around because even you who are more experienced don't know how to solve it?


      ENVhandle     = iEnvelopes(NULL,0,ENVperiod,0,ENVmethod,ENVPrice1/*applied price or handle*/,ENVDeviation);
      

      // AMA1handle to calculate array by Copybuffer on Upper Envelopes buffer  
      AMA1handle = iCustom(NULL,0,"Examples\\AMA",AMAperiod1,AMAfast1,AMAslow1,0,ENVhandle);
        

HAVE YOU AN IDEA HOW DO IT DO THIS?

      // AMA2handle to calculate array by Copybuffer on LOWER Envelopes buffer  
      AMA2handle = iCustom(NULL,0,"Examples\\AMA",AMAperiod2,AMAfast2,AMAslow2,0,ENVhandle);



      ArraySetAsSeries(ENVarrayUpper,true);
      ArraySetAsSeries(ENVarrayLower,true);
      ArraySetAsSeries(AMA1array,true);
      ArraySetAsSeries(AMA2array,true);

......


 
Use [data folder]\MQL5\Include\MovingAverages.mqh
 
The easiest option is to split iEnvelopes into two indicators - one draws only the upper line, and the second only draws the lower line. After that, the handles of these indicators can be used when creating iAMA
 
Vladimir Karputov:
Use [data folder]\MQL5\Include\MovingAverages.mqh

i don't understand what you mean with that... i know this library

but what you mean?

 
Vladimir Karputov:
The easiest option is to split iEnvelopes into two indicators - one draws only the upper line, and the second only draws the lower line. After that, the handles of these indicators can be used when creating iAMA
Vladimir Karputov:
The easiest option is to split iEnvelopes into two indicators - one draws only the upper line, and the second only draws the lower line. After that, the handles of these indicators can be used when creating iAMA

please provide the code at yout time now, please.

      ENVhandle1     = iEnvelopes(NULL,0,ENVperiod,0,ENVmethod,ENVPrice1/*applied price or handle*/,ENVDeviation);
      ENVhandle2     = iEnvelopes(NULL,0,ENVperiod,0,ENVmethod,ENVPrice1/*applied price or handle*/,ENVDeviation);

      AMA1handle = iCustom(NULL,0,"Examples\\AMA",AMAperiod1,AMAfast1,AMAslow1,0,ENVhandle1);
      AMA2handle = iCustom(NULL,0,"Examples\\AMA",AMAperiod2,AMAfast2,AMAslow2,
1 ,ENVhandle2);

CopyBuffer(AMA1handle,0,0,5,AMA1array)>0)   // this go on Upper Buffer
CopyBuffer(AMA1handle,0,0,5,AMA1array)>0)   // this go on Upper Buffer too

how can i catch second buffer of ENVhandle2 (Lower Buffer???)

please provide the code at yout time now, please.

 
 
Vladimir Karputov:
Study:  AMA Envelopes Custom

Thanks Vladimir

I would have preferred to use only the original iEnvelopes but the same also 2 Envelopes with separate buffers called by iCustom give the same results (I had not thought about modifying the original indicator in this way .. but okay the data comes back) with this solution

Vladimir Karputov:
The easiest option is to split iEnvelopes into two indicators - one draws only the upper line, and the second only draws the lower line. After that, the handles of these indicators can be used when creating iAMA


thanks for the indication, good job

Documentation on MQL5: Constants, Enumerations and Structures / Indicator Constants / Indicators Lines
Documentation on MQL5: Constants, Enumerations and Structures / Indicator Constants / Indicators Lines
  • www.mql5.com
Some technical indicators have several buffers drawn in the chart. Numbering of indicator buffers starts with 0. When copying indicator values using the CopyBuffer() function into an array of the double type, for some indicators one may indicate the identifier of a copied buffer instead of its number.
Reason: