Reference to an Indicator

 

Hi 

I have an indicator(A.ex5) and I want to reference it in an include file (C.mqh) or another indicator (B.ex5) But I always receive error code 4806 and 4802

As I'm new in MQL5, at first I want to know the procedure of referencing an indicator (to be sure I have done it correct) then what's the solution, as I have searched it's a kind of MQL5 bugs.

OOP in MQL5 by Example: Processing Warning and Error Codes
OOP in MQL5 by Example: Processing Warning and Error Codes
  • www.mql5.com
The article describes an example of creating a class for working with the trade server return codes and all the errors that occur during the MQL-program run. Read the article, and you will learn how to work with classes and objects in MQL5. At the same time, this is a convenient tool for handling errors; and you can further change this tool according to your specific needs.
 
  1. Here is a quick introduction to MQL5: https://www.mql5.com/de/articles/496
  2. To get custom indicator values in MQL5 you have to use iCustom() - there is an example in the reference (in the editor place the above iCustom and press F1!)
  3. To find and correct problems use this:
    Code debugging:  https://www.metatrader5.com/en/metaeditor/help/development/debug
    Error Handling and Logging in MQL5:  https://www.mql5.com/en/articles/2041
    Tracing, Debugging and Structural Analysis of Source Code, scroll down to: "Launching and Debuggin": https://www.mql5.com/en/articles/272

Schnelleinstieg oder Kurzanleitung für Anfänger
Schnelleinstieg oder Kurzanleitung für Anfänger
  • www.mql5.com
Liebe Leser, in diesem Artikel möchte ich Ihnen vermitteln und zeigen, wie man sich möglichst schnell und einfach die Grundlagen der Erstellung automatischer Handelssysteme, wie die Arbeit mit Indikatoren u. a., erschließt. Der Beitrag richtet sich an Neueinsteiger, in ihm kommen weder komplizierte noch schwer zu verstehende Beispiele zur Anwendung.
 
Carl Schreiber #:
  1. Here is a quick introduction to MQL5: https://www.mql5.com/de/articles/496
  2. To get custom indicator values in MQL5 you have to use iCustom() - there is an example in the reference (in the editor place the above iCustom and press F1!)
  3. To find and correct problems use this:
    Code debugging:  https://www.metatrader5.com/en/metaeditor/help/development/debug
    Error Handling and Logging in MQL5:  https://www.mql5.com/en/articles/2041
    Tracing, Debugging and Structural Analysis of Source Code, scroll down to: "Launching and Debuggin": https://www.mql5.com/en/articles/272

thanks for your consideration,

of Corse I have read all above links, but it doesn't solve anything. it's a MQL5 bug and I need something else to achieve it.

 
Asa Sh #:

thanks for your consideration,

of Corse I have read all above links, but it doesn't solve anything. it's a MQL5 bug and I need something else to achieve it.

It will be your code,  so if you want help you will need to post your code, along with the error description.  use the code button </>  or Alt+S to post code

 
Paul Anscombe #:

It will be your code,  so if you want help you will need to post your code, along with the error description.  use the code button </>  or Alt+S to post code

My Indicator A's name is "A0_Legs_0" and it is in MQL5\Indicators and also it works fine, I reference it by bellow line in to my Include file (C.mqh)

#resource "\\Indicators\\A0_Legs_0.ex5"

the bellow function is in my Include file (C.mqh) refers to iCustom

//+------------------------------------------------------------------+
//|                                                                                 |
//+------------------------------------------------------------------+
double Legs(long A_ChID,
            string A_MySymbol,
            int t, //t:timeframe,
            int d, //d:buffers number in my indicator A (my indicator A has more than 1 buffer and I need several buffer)
            int i) //i:Candle number
{
   int Handle = iCustom(A_MySymbol, MyTimeFramesMQL4(t), "A0_Legs_0.ex5");
   int err0 = GetLastError();
   double p = 0;
   double MyLegsIndicator[];
   int copy = 0;
   copy = CopyBuffer(Handle, d, i, 1, MyLegsIndicator); //iBars(A_MySymbol, MyTimeFramesMQL4(t)) - 1
   int err = GetLastError();
   if(copy == -1)// && err == 4806)
   {
      if(err == 4806)
      {
         //--- wait till the data is uploaded
         for(int j = 0; j < 10000; ++j)
            if(BarsCalculated(Handle) > 0)
               break;
         copy = CopyBuffer(Handle, d, i, 1, MyLegsIndicator);
         err = GetLastError();
      }
   }
//--- check coying result
   if(copy == -1)
   {
      Print("Error when trying to get --A0_Legs_0-- values, last error is ", err0, "_", err, " bars ", i, " buffurs ", d, " TF ", MyTimeFrameNames[t]);
      return(0);
   }
   p = MyLegsIndicator[0];
   return(p);


then I use bellow code to get my Indicator buffers data every where else, in the include file(C.mqh) functions or in another indicator(B) that has #include <C.mqh>

Legs(A_ChID, A_MySymbol, t, 3, i)
I always receive copy = -1 then error code 4806
 
iCustom will nearly always fail unless you add the parameters to the call which would be the input variables in the indicator
 
Asa Sh #:

My Indicator A's name is "A0_Legs_0" and it is in MQL5\Indicators and I reference it by bellow line in to my Include file (C.mqh)

the bellow function is in my Include file (C.mqh) refers to iCustom

then I use bellow code to get my Indicator buffers data every where else, in the include file(C.mqh) functions or in another indicator(B) that has #include <C.mqh>

As per the documentation you need to reference the resource correctly...

   int Handle = iCustom(A_MySymbol, MyTimeFramesMQL4(t), "::Indicators\\A0_Legs_0");


no idea what this is suppose to be, it is not how you access indicator data, read about copybuffer

Legs(A_ChID, A_MySymbol, t, 3, i)

https://www.mql5.com/en/docs/runtime/resources

Documentation on MQL5: MQL5 programs / Resources
Documentation on MQL5: MQL5 programs / Resources
  • www.mql5.com
Programs in MQL5 allow working with sound and graphic files: PlaySound() plays a sound file; ObjectCreate() allows creating user interfaces using...
 
Paul Anscombe #:
int Handle = iCustom(A_MySymbol, MyTimeFramesMQL4(t), "::Indicators\\A0_Legs_0.ex5");

I have tried it and gets error code 4802

Paul Anscombe #:
Legs(A_ChID, A_MySymbol, t, 3, i)

this is my simple way to get data.


is there any way to you to write a simple custom indicator(A.ex5) and then call it in a simple Include file (C.mqh) and use it's data in one of the functions in C.mqh ? would you pls do it and send me the code?

 
Asa Sh #:

I have tried it and gets error code 4802

this is my simple way to get data.

is there any way to you to write a simple custom indicator(A.ex5) and then call it in a simple Include file (C.mqh) and use it's data in one of the functions in C.mqh ? would you pls do it and send me the code?

my bad, I left the .ex5 in, you need to remove it when referencing the resource.

int Handle = iCustom(A_MySymbol, MyTimeFramesMQL4(t), "::Indicators\\A0_Legs_0");

your simple way to get data is meaningless as you have presented it. 

given that you can barely code MQL5 why are you trying to complicate it so much, you shouldn't need to use include files at your stage of knowledge.

life would be easier if you posted the whole code...
 
Paul Anscombe #:
int Handle = iCustom(A_MySymbol, MyTimeFramesMQL4(t), "::Indicators\\A0_Legs_0");

It doesn't work unfortunately.

Paul Anscombe #:

your simple way to get data is meaningless as you have presented it. 

given that you can barely code MQL5 why are you trying to complicate it so much, you shouldn't need to use include files at your stage of knowledge.

life would be easier if you posted the whole code...

:), I know but, I need the data in a lots of functions so I can't write iCustom and copybuffer every time.

I have attached 3 files, 2 indicators and one C.mqh

put B.mq5 in D1 chart, it should print the data of A.mq5 in candle 10 MN (Print(Function0(ChartID(), ChartSymbol(), 7, 0, 10))) but it refers error.

Files:
A.mq5  10 kb
B.mq5  2 kb
C.mqh  3 kb
 
Conor Mcnamara #:
iCustom will nearly always fail unless you add the parameters to the call which would be the input variables in the indicator
put B.mq5 in the chart, it should print the data of A.mq5 in candle but it refers error.
Files:
C.mqh  3 kb
A.mq5  10 kb
B.mq5  2 kb
Reason: