EA creates multiple indicator instances using iCustom

 

 I'm developing an EA, I'm reading a custom indicator using iCustom as the usual, but it creates multiple instances of the same indicator at backtest. 

Usual issue, indicator works absolutely fine when applied to a chart, however when i attempt to use via iCustom in an EA I have multiple instances being applied on my back testing. Could you help me?

Indicator Corola

#property indicator_separate_window
#property indicator_buffers  2
#property indicator_plots    2
#property indicator_label1   "Short"
#property indicator_type1    DRAW_LINE
#property indicator_color1   clrSilver
#property indicator_width1   2
#property indicator_label2   "Long"
#property indicator_type2    DRAW_LINE
#property indicator_color2   clrRed
#property indicator_width2   2

//
//
//

input int                inpPeriodShort = 20;          // Short period
input int                inpPeriodLong  = 40;          // Long period
input ENUM_APPLIED_PRICE inpPrice       = PRICE_CLOSE; // Price

double vals[],vall[]; int _longPeriod, _shortPeriod;
double SSyy,SSy,LSyy,LSy,_ts2,_tl2;
//------------------------------------------------------------------
//
//------------------------------------------------------------------
//
//
//

int OnInit()
{
   SetIndexBuffer(0,vals,INDICATOR_DATA); 
   SetIndexBuffer(1,vall,INDICATOR_DATA); 
      
      //
      //
      //

EA

void OnTick()
  {
string signal="";
double short_period[];
double long_period[];
ArraySetAsSeries(long_period,true);
ArraySetAsSeries(short_period,true);
int CorrelationDefination=iCustom(NULL,Period(),"Corola.ex5",20,40,PRICE_CLOSE,0,0,0,0,0,0,0,0);
CopyBuffer(CorrelationDefination,0,0,3,short_period);
CopyBuffer(CorrelationDefination,1,0,3,long_period);
double shortValue0=short_period[0];
double longValue0=long_period[0];
double shortValue1=short_period[1];
double longValue1=long_period[1]; 
if (longValue0<-0.8&&shortValue0<-0.8) 
if ((shortValue0<longValue0) && (shortValue1>longValue1))
{
signal="Buy";
}
if (longValue0>0.8&&shortValue0>0.8) 
if ((shortValue0>longValue0) && (shortValue1<longValue1))
{
signal="Sell";
}
Comment("Signal: ",signal);
  }
Step on New Rails: Custom Indicators in MQL5
Step on New Rails: Custom Indicators in MQL5
  • www.mql5.com
Finally we've got an opportunity to try the new trade terminal - MetaTrader 5 . No doubt, it is noteworthy and has many new features as compared to its predecessor. The important advantages of this platform among others are: Essentially modified language allowing now to use the object-oriented programming, still allowing to use the rich...
 
Silverveins :

  I'm developing an EA, I'm reading a   custom indicator  using iCustom as the usual, but it creates multiple instances of the same indicator at backtest. 

Usual issue, indicator works absolutely fine when applied to a chart, however when i attempt to use via iCustom in an EA I have multiple instances being applied on my back testing. Could you help me?

Indicator Corola

EA

Finally start reading the help. In MQL5, the indicator handle SHOULD BE CREATED ONLY ONCE !!! The indicator handle is created in OnInit ().

 
Vladimir Karputov:

Finally start reading the help. In MQL5, the indicator handle SHOULD BE CREATED ONLY ONCE !!! The indicator handle is created in OnInit ().

Didn´t work!

 
Silverveins :

Didn´t work!

If it didn’t work, then you didn’t do anything.

Please attach ( Attach file) two files: the indicator file and the FIXED advisor file.

 
Vladimir Karputov:

Se não funcionou, você não fez nada.

Anexe ( ) dois arquivos: o arquivo do indicador e o arquivo do orientador FIXED.

I attached the files, can you help or not?
Files:
Coro1.mq5  1 kb
Corola.ex5  27 kb
 
Silverveins :

Correct your code:

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnInit()
  {
   int CorrelationDefination=iCustom(NULL,Period(),"Corola.ex5",20,40,PRICE_CLOSE);
   return(INIT_SUCCEEDED);
  }

void OnTick()

  {
   string signal="";
   double short_period[];
   double long_period[];
   ArraySetAsSeries(long_period,true);
   ArraySetAsSeries(short_period,true);
   CopyBuffer(CorrelationDefination,0,0,3,short_period);
   CopyBuffer(CorrelationDefination,1,0,3,long_period);
   double shortValue0=short_period[0];
   double longValue0=long_period[0];
   double shortValue1=short_period[1];
   double longValue1=long_period[1];
   if(longValue0<-0.8&&shortValue0<-0.8)
      if((shortValue0<longValue0) && (shortValue1>longValue1))
        {
         signal="Buy";
        }
   if(longValue0>0.8&&shortValue0>0.8)
      if((shortValue0>longValue0) && (shortValue1<longValue1))
        {
         signal="Sell";
        }
   Comment("Signal: ",signal);
  }
//+------------------------------------------------------------------+

Read the help ( iCustom ). Correct the mistake. Your code won't compile.


Read the help. Look at the code formatting rules - don't be lazy and add the file name. Example:

//+------------------------------------------------------------------+
//|                                                  Accelerator.mq5 |
//|                   Copyright 2009-2017, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright   "2009-2017, MetaQuotes Software Corp."
#property link        "http://www.mql5.com"
#property description "Accelerator/Decelerator"

//---- indicator settings
#property indicator_separate_window
#property indicator_buffers 6
#property indicator_plots   1
#property indicator_type1   DRAW_COLOR_HISTOGRAM
#property indicator_color1  Green,Red
#property indicator_width1  2
#property indicator_label1  "AC"
//--- indicator buffers
double ExtACBuffer[];
double ExtColorBuffer[];
double ExtFastBuffer[];
double ExtSlowBuffer[];
double ExtAOBuffer[];
double ExtSMABuffer[];
//--- handles for MAs
int    ExtFastSMAHandle;
int    ExtSlowSMAHandle;
//--- bars minimum for calculation
#define DATA_LIMIT 37
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void OnInit()
  {
Documentation on MQL5: Technical Indicators / iCustom
Documentation on MQL5: Technical Indicators / iCustom
  • www.mql5.com
[in]  Custom indicator name. If the name starts with the reverse slash '\', the EX5 indicator file is searched for relative to the MQL5\Indicators indicator root directory. Thus, when calling FirstIndicator"...), the indicator is downloaded as MQL5\Indicators\FirstIndicator.ex5. If the path contains no file, the error 4802...
 
Vladimir Karputov:

Correct your code:



Read the help ( iCustom ). Correct the mistake. Your code won't compile. Read the help. Look at the code formatting rules - don't be lazy and add the file name. Example:

Lazy??? Are you kidding??? If I knew the answer and had no doubts I wouldn't be in this forum. In fact, there would be no need for a forum if everyone knew everything.If you don't want to help, don't disturb
 
Silverveins:
Lazy??? Are you kidding??? If I knew the answer and had no doubts I wouldn't be in this forum. In fact, there would be no need for a forum if everyone knew everything.If you don't want to help, don't disturb

Just to remind -

Forum on trading, automated trading systems and testing trading strategies

Please fix this indicator or EA

Sergey Golubev, 2017.03.24 07:23

And this is my other suggestion (which came from tsd 2010 and from tsd 2008):

----------------

Just to remind:

Coders (any coder) are coding for free:

  • if it is interesting for them personally, or
  • if it is interesting for many members of this forum.

and Freelance section of the forum should be used in most of the cases.



 
Sergey Golubev:

Só para lembrar -


Just to remind:

My code works, ok!!!?I attached.

And what's the difference with this post https://www.mql5.com/en/forum/217617 ???????? AND THIS https://www.mql5.com/en/forum/329733 ?????

Good Job !!!

EA creates multiple instances using iCustom
EA creates multiple instances using iCustom
  • 2017.10.16
  • www.mql5.com
Hi there, Here's the thing, I'm developing an EA, I'm reading a custom indicator (WT_TMA) using iCustom as the usual, but it creates multiple insta...
Files:
Corola.ex5  27 kb
Coro.mq5  1 kb
 
Silverveins :
Lazy??? Are you kidding??? If I knew the answer and had no doubts I wouldn't be in this forum. In fact, there would be no need for a forum if everyone knew everything. If you don't want to help, don't disturb

I advise you to communicate correctly.

Your actions: compile -> see if there are any errors?

And the error is:


Click the error and the cursor will move to the code (to the line in the code where this error is) - you refer to the 'CorrelationDefination' variable - but this variable is not declared anywhere.

 
Silverveins :


Here's a good reference:

Visibility Scope and Lifetime of Variables

Documentation on MQL5: Language Basics / Variables / Visibility Scope and Lifetime of Variables
Documentation on MQL5: Language Basics / Variables / Visibility Scope and Lifetime of Variables
  • www.mql5.com
A variable declared outside all functions is located into the global scope. Access to such variables can be done from anywhere in the program.These variables are located in the global pool of memory, so their lifetime coincides with the lifetime of the program. A variable declared inside a block (part of code enclosed in curly brackets) belongs...
Reason: