Download MetaTrader 5
To add comments, please log in or register
Are you accustomed to using the standard library? MQL5 has one!
Timerider
78
Timerider 2015.05.01 18:34 

Hi guys,

I´ve programmed a very simple indicator. It should return the value a, which is previously defined. Here it is:

//+------------------------------------------------------------------+
//|                                                     EaTestEa.mq4 |
//|                        Copyright 2015, MetaQuotes Software Corp. |
//|                                              https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2015, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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[])
  {

int a;
if(iOpen("EURUSD",2,1)>iClose("EURUSD",2,1))
 a=1;
if(iOpen("EURUSD",2,1)<iClose("EURUSD",2,1))
 return(a);


  }
//+------------------------------------------------------------------+

 So if i want to get the value of a with the iCustom() function, which is here

iCustom(NULL,0,"EaTestEa",0,0,0);

it always returns the value 0 even if Open[1]<Close[1]. Maybe you know how to solve my problem.

Thanks for your help 








Timerider
78
Timerider 2015.05.01 18:37  

Sorry should look like this

int a;
if(Open[1]>Close[1])
 a=1;
if(Open[1]<Close[1])
 a=0
 return(a);
Keith Watford
Moderator
7862
Keith Watford 2015.05.01 20:40  

iCustom gets the value of a buffer

Your indicator does not have any buffers, so iCustom cannot retrieve a value 

Timerider
78
Timerider 2015.05.02 20:55  
GumRai:

iCustom gets the value of a buffer

Your indicator does not have any buffers, so iCustom cannot retrieve a value 

Hi GumRai,

thanks for your support. Can you maybe show me how i can store a in a Buffer and then call it with the iCustom function?

Keith Watford
Moderator
7862
Keith Watford 2015.05.02 21:33  

If you open a new indicator in the metaeditor, the wizard allows you to set up the buffers as you require them.

There are lots of examples in the code base that you can look at to find out how to store a value in a buffer 

/
To add comments, please log in or register