Getting the data out of a custom indicator

To add comments, please log in or register
Pasi Hakamaki
10841
Pasi Hakamaki  

Hi,

My goal is to get my simple test expert to fetch the data from my simple custom indicator. Below are the custom indicator and the expert. For some reason I can't get the data. Please help. Thanks!

//+------------------------------------------------------------------+
//|                                                     GetValue.mq5 |
//|                        Copyright 2013, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2013, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"

//--- custom indicator handle
int hCI;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   //--- get the handle of the custom indicator
   hCI=iCustom(NULL,0,"ReturnValuetoExperts");
//---
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   //--- create array to store the value of the custom indicator ReturnValuetoExperts.mq5
   double custom_buff[1];
   //--- get the data from the indicators buffer and copy it to custom_buff array
   CopyBuffer(hCI,0,0,1,custom_buff);
  }
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//|                                         ReturnValuetoExperts.mq5 |
//|                        Copyright 2013, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2013, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots 1

//--- indicator buffer
double custom_buff[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,custom_buff,INDICATOR_DATA);
//---
   return(0);
  }
//+------------------------------------------------------------------+
//| 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[])
  {
//---
   //--- assign value 1 to index 0 of indicator buffer
   custom_buff[0]=1;
   return(rates_total);
  }
//+------------------------------------------------------------------+
phi nuts
2100
phi nuts  
Candles:

Hi,

My goal is to get my simple test expert to fetch the data from my simple custom indicator. Below are the custom indicator and the expert. For some reason I can't get the data. Please help. Thanks!

This code in your indicator

//--- assign value 1 to index 0 of indicator buffer
   custom_buff[0]=1;

is assign value to buffer of the oldest bar. 

This code however,

//--- assign value 1 to index rates_total (= bars) of indicator buffer
   custom_buff[rates_total] = 1;

is assign value to buffer of the newest/current bar

 

 

Pasi Hakamaki
10841
Pasi Hakamaki  
Of course! I get it :)

Ahmed Soliman
19545
Ahmed Soliman  
phi.nuts:

This code in your indicator

is assign value to buffer of the oldest bar. 

This code however,

is assign value to buffer of the newest/current bar

 

 

You mean:

   //--- assign value 1 to index 0 of indicator buffer
   custom_buff[rates_total-1]=1;

Ahmed Soliman
19545
Ahmed Soliman  
codersguru:
You mean:


Because:

  //--- assign value 1 to index 0 of indicator buffer
   custom_buff[rates_total]=1;

Generates the error:

2013.02.15 06:55:23    ReturnValuetoExperts (EURUSD,H4)    array out of range in 'ReturnValuetoExperts.mq5' (41,15)

Documentation on MQL5: MQL5 programs / Runtime Errors
Documentation on MQL5: MQL5 programs / Runtime Errors
  • www.mql5.com
MQL5 programs / Runtime Errors - Documentation on MQL5
phi nuts
2100
phi nuts  
codersguru:

Because:

Generates the error:

2013.02.15 06:55:23    ReturnValuetoExperts (EURUSD,H4)    array out of range in 'ReturnValuetoExperts.mq5' (41,15)

You're right >_< !
To add comments, please log in or register