iCustom parameters problems to change indicator style and label

Back to topics list To post a new topic, please log in or register
avatar
16
dbarnabe 2016.01.22 13:47
 

Hi,

I've been studying iCustom to implement a customized EMA indicator on a EA and I have a problem on changing the indicator style and label.

Each time I call iCustom on the EA I would like to set the parameters to the EMA indicator: period, label and color. My intention is to put this customized properties on the EA side ans have as many EMAs I want. Tipycally  I want 3 EMAs (short, long and vlong) and my idea is to have only one indicator and call it each time.

The iCustom has worked before I implemented SetIndexStyle and the SetIndexLabel on the indicator and changed the iCustom call on the EA to include the input parameters: EMAShort = iCustom(NULL,0,"EMACustom_v1",5,"clrBlue","EMA_Short",0,0);

 I have read that SetIndexStyle and SetIndexLabel can´t be used on EAs, so the doubts are:

- Can I use this iCustom parameters to define indicator style and label?

- On EA side I have to define property indicator style and label to the iCustom indicator?

- Is theres a way to abdicate the OnCalculate() on the EA side? I'm not using it...

 

The Custom indicator:

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots   1
//--- plot Label1
#property indicator_label1  "EMA_Custom"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrBlueViolet
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- External parameters
extern int period;
extern string indicatorcolor;
extern string indicatorlabel;
//--- indicator buffers
double Label1Buffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int Init()
  {
//---- indicator buffers mapping
   SetIndexBuffer(0,Label1Buffer);// Assigning an array to a buffer
//---- drawing settings
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1,StringToColor(indicatorcolor));
//---- drawing settings
   SetIndexLabel(0,indicatorlabel);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
int start()
  {
//---
   int i;
   int counted_bars;
   counted_bars = IndicatorCounted();
  //---- check for possible errors
     if(counted_bars>0) counted_bars--;
     i=Bars-counted_bars-1;
  //---- main loop
     while(i>=0)
       {
        //---- ma_shift set to 0 because SetIndexShift called abowe
        Label1Buffer[i]=iMA(NULL,0,period,0,MODE_EMA,PRICE_CLOSE,i);//https://book.mql4.com/samples/icustom
        i--;
       }
  //--- return value of prev_calculated for next call
   return(0);
  }
//+------------------------------------------------------------------+

 

and the EA code: 

#define EMACustom "EMACustom_v1"

#property strict
//--- Indicadores
#property indicator_chart_window
//#property indicator_buffers 2
//Indicador Buffers
//double EMAShortBuffer[];
//double EMALongBuffer[];
//+------------------------------------------------------------------+
//| Global Variable                                   |
//+------------------------------------------------------------------+
static datetime LastBar, ActBar;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   ActBar = Time[1];
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
  double EMAShort, EMALong;
//---
  LastBar = Time[0];
  if(ActBar != LastBar)
    {
     LastBar = ActBar;
     Print("Nova Barra");
     EMAShort = iCustom(NULL,0,"EMACustom_v1",5,"clrBlue","EMA_Short",0,0); //https://www.mql5.com/en/articles/1497
     EMALong = iCustom(NULL,0,"EMACustom_v1",50,"clrRed","EMA_Long",0,0);
    }
  }
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
   
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+

 

 Thanks for your help.

Best regards. 

avatar
13004
WHRoeder 2016.01.22 14:33 #
 
Not going to work. The indicator running from the iCustom call is not visible.
avatar
16
dbarnabe 2016.01.22 17:10 #
 
WHRoeder:
Not going to work. The indicator running from the iCustom call is not visible.

WHRoeder,

can you explain how "the indicator running from the iCustom call is not visible."? I'm not understanding... On MQL4 docs it says " name of the custom indicator, parameters should go in a strict accordance with the declaration of input variables of this custom indicator." and I think that is what I have... 

After seeing another topic in the forum I have changed few things:

Add variables input on EA side: 

int period;
string indicatorcolor;
string indicatorlabel;

 and changed the iCustom call:

 period = 5;
 indicatorcolor = "clrBlue";
 indicatorlabel = "EMA_Short";
 EMAShort = iCustom(NULL,0,"EMACustom_v1",period,indicatorcolor,indicatorlabel,0,0);
 period = 50;
 indicatorcolor = "clrRed";
 indicatorlabel = "EMA_Long";
 EMALong = iCustom(NULL,0,"EMACustom_v1",period,indicatorcolor,indicatorlabel,0,0);

 

but still doesn't work. 

avatar
1110
Ovo 2016.01.23 07:56 #
 
dbarnabe:

WHRoeder,

can you explain how "the indicator running from the iCustom call is not visible."? I'm not understanding... On MQL4 docs it says " name of the custom indicator, parameters should go in a strict accordance with the declaration of input variables of this custom indicator." and I think that is what I have... 

After seeing another topic in the forum I have changed few things:

Add variables input on EA side: 

 and changed the iCustom call:

 

but still doesn't work. 

The iCustom call suppresses the graphical output completely.
avatar
16
dbarnabe 2016.01.24 00:57 #
 
Ovo:
The iCustom call suppresses the graphical output completely.

 Ovo,

Before i have made the change to customize color and label on iCustom call, I have it fixed on indicator code and it worked and draw 2 EMA on the graphics with to calls of iCustom. The first version is similar to the previous code:

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots   1
//--- plot Label1
#property indicator_label1  "EMA_Custom"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrBlueViolet
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- External parameters
extern int period;
//--- indicator buffers
double Label1Buffer[];
int OnInit()
  {
   SetIndexBuffer(0,Label1Buffer);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
int start()
  {
//---
   int limit;
   int counted_bars;
   counted_bars = IndicatorCounted();
  //---- check for possible errors
     if(counted_bars<0) return(-1);
     if(counted_bars>0) counted_bars--;
     limit=Bars-counted_bars;
     for(int i=0; i<limit; i++)
       {
        Label1Buffer[i]=iMA(NULL,0,period,0,MODE_EMA,PRICE_CLOSE,i);
       }
   return(0);
  }

 and draw the 2 EMAs:

 EMAs iCustom

 

The only thing that have changed is the two arguments: color and label on iCustom call...

If you could help also on the others questions, I appreciatte:

  - On EA side I have to define property indicator style and label to the iCustom indicator?

- Is theres a way to abdicate the OnCalculate() on the EA side?

 

Thanks for your attention. 

 

avatar
1110
Ovo 2016.01.24 06:22 #
 

The only place you can see plotting of the buffers from iCustom() is the Strategy Tester. If you are talking about the Strategy Tester, you should have mentioned the fact. No graphical output is generated from iCustom() during normal EA operation.

The OnCalculate() is not the EA method. And no, you cannot avoid it in indicators called by the iCustom(), OnCalculate() is invoked once for a unique set of input parameters.

avatar
16
dbarnabe 2016.01.26 00:53 #
 
Ovo:

The only place you can see plotting of the buffers from iCustom() is the Strategy Tester. If you are talking about the Strategy Tester, you should have mentioned the fact. No graphical output is generated from iCustom() during normal EA operation.

The OnCalculate() is not the EA method. And no, you cannot avoid it in indicators called by the iCustom(), OnCalculate() is invoked once for a unique set of input parameters.

Ovo,

 You are right! Sorry... I didn't mentioned that I was talking about STester because I didn't know that it only works there! I was thinking that it was going to work in normal EA operation. Thanks...

 

So, considering that I want to change colors and label using iCustom on STester, can I use this type of call?

EMAShort = iCustom(NULL,0,"EMACustom_v1",5,"clrBlue","EMA_Short",0,0)

 

 and on indicator side use?

//---- drawing settings
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1,StringToColor(indicatorcolor));
//---- drawing settings
   SetIndexLabel(0,indicatorlabel);

 

Where is the issue?


avatar
125
zirkoner 2016.01.26 18:48 #
 
Ovo:
The iCustom call suppresses the graphical output completely.
Not exactly, the graphical output using buffers is suppressed, but if you are using graphical objects they are still drawn.
avatar
125
zirkoner 2016.01.26 18:49 #
 
dbarnabe:

Ovo,

 You are right! Sorry... I didn't mentioned that I was talking about STester because I didn't know that it only works there! I was thinking that it was going to work in normal EA operation. Thanks...

 

So, considering that I want to change colors and label using iCustom on STester, can I use this type of call?

 

 and on indicator side use?

 

Where is the issue?


It's not possible. Use a template.
avatar
16
dbarnabe 2016.01.27 01:15 #
 
zirkoner:
It's not possible. Use a template.

Zirkoner,

When I use a template in an new chart, manually though, it overrides the symbols that I have created with the EA! Will not append the same when i call the template load function?

 

I want to have 3 EMAs displayed on the chart and on the EA work with EMAs values... In your opinion do I use iCustom with 3 EMAs or use iMA indicator and load the template?

Will iCustom works with 3 EMAs?  I'm little confused...

Thanks. 

 

 

avatar
16
dbarnabe 2016.01.30 11:17 #
 

Hii,

Can anybody help me on the last post? I would appreciatte! :)

  

Back to topics list  

To add comments, please log in or register