Yet again: iCustom returns 2146483647 - really!

 
Hello,

I've stumbled across the problem that othares had before, but aparently none of the previously identified problems seem to be the cause...

The problem is that I made a custom indicator and it works fine. Calling it from a self-made EA however via iCustom makes it always return the number in the subject heading, which I googled means an empty buffer.

I've broken down the problem to the following code:


//--------------------------------------------------------------------
// trivial.mq4 
// 
// (c) 2010 mfeldt.mq4
//--------------------------------------------------------------------
#property indicator_chart_window    // Èíäèê. ðèñóåòñÿ â îñíîâíîì îêíå
#property indicator_buffers 1       // Êîëè÷åñòâî áóôåðîâ
#property indicator_color1 Orange   // Öâåò ïåðâîé ëèíèè

double Buf_0[];             // Îòêðûòèå èíäèêàòîðíûõ ìàññèâîâ
//--------------------------------------------------------------------
int init()                          // Ñïåöèàëüíàÿ ôóíêöèÿ init()
  {
//--------------------------------------------------------------------
   SetIndexBuffer(0,Buf_0);         // Íàçíà÷åíèå ìàññèâà áóôåðó
   SetIndexStyle (0,DRAW_LINE,STYLE_SOLID,3);// Ñòèëü ëèíèè
   return;                          // Âûõîä èç ñïåö. ô-èè init()
  }
//--------------------------------------------------------------------
int start()                         // Ñïåöèàëüíàÿ ôóíêöèÿ start()
  {
   int i,Counted_bars;            // Êîëè÷åñòâî ïðîñ÷èòàííûõ áàðîâ 
   
//--------------------------------------------------------------------
   Counted_bars=IndicatorCounted(); // Êîëè÷åñòâî ïðîñ÷èòàííûõ áàðîâ 
   i=Bars-Counted_bars-100;           // Èíäåêñ ïåðâîãî íåïîñ÷èòàííîãî
   while(i>=0)                      // Öèêë ïî íåïîñ÷èòàííûì áàðàì
     {
      
      Buf_0[i]=1.0   ;     // Çíà÷åíèå 0 áóôåðà íà i-îì áàðå

      i--;                          // Ðàñ÷¸ò èíäåêñà ñëåäóþùåãî áàðà
     }
//--------------------------------------------------------------------
   return;                          // Âûõîä èç ñïåö. ô-èè start()
  }
//--------------------------------------------------------------------

As you can see, a really simple indicator that doesn't take any external parameters, always writes the value 1.0 to buffer 0.


Now the - similarly trivial - EA:


//+------------------------------------------------------------------+
//|                                               Moving Average.mq4 |
//|                      Copyright © 2005, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#define MAGICMA  20050610


//+------------------------------------------------------------------+
//| Start function                                                   |
//+------------------------------------------------------------------+
void start()
  {
  

//---- calculate open orders by current symbol
   Print("Trivial: ",iCustom(NULL,0,"mfe_trivial",0,1   ));
//----
  }
//+--------------

It doesn't do anything but reading the indicator and writing the value to the journal.


Now here's one of the journal entries (they all look the same):


2010.11.10 13:46:51     2010.10.14 23:57  mfe_EA_trivial EURUSD,H1: Trivial: 2147483647

Why doesn't it show a 1.0 ?????

What can I try???


An additional question - I am not completely sure about the meaning of the last "1" in the call to iCustom - but I guess it's thaht I wish it return the value for tha last but one bar, i.e. tha last one that has actually been completed, right?

 

Are you sure your EA is calling the correct indicator ? It is calling to "mfe_trivial" your indicator is called just "trivial"

I copied your code for both your indicator and your EA and ran them both it returns the value: 1 every time.

You might want to change the line i=Bars-Counted_bars-100; to i=Bars-Counted_bars-1; because at 100 it is re doing the last 100 buffer entries every tick and will fill up your log file.

 
SDC:

Are you sure your EA is calling the correct indicator ? It is calling to "mfe_trivial" your indicator is called just "trivial"

I copied your code for both your indicator and your EA and ran them both it returns the value: 1 every time.

You might want to change the line i=Bars-Counted_bars-100; to i=Bars-Counted_bars-1; because at 100 it is re doing the last 100 buffer entries every tick and will fill up your log file.


Interesting - yes I'm sure, the filename is correct, only the comment line shows the wrong name.


Changing the offset from 100 to 1 did indeed help, although I do not full yunderstand why.


The idea originally was to spare the oldest 100 candles from the calculation of the original (non-trivial) indicator, because it would not be defined there...

m.

 

it is because this code

Counted_bars=IndicatorCounted(); 
   i=Bars-Counted_bars-100;

It is because you have the right idea only it is in reverse, the function IndicatorCounted() returns the amount of bars that have already been dealt with, so the -100 is the amount of bars that have already been dealt with but need to be recalculated, usually you would have this set to -1 so only the currently forming bar is recalculated as it changes every time a new tick comes. All the rest of the bars are done already and a indicator value was assigned for each of them so they dont need to be recalculated.

 
thx
 

You were right there seems to be a bug in mt4 that does this, believe it or not I have come up against the exact same thing in my indicator I returns the values from the buffers in Alerts because the indicator was not working correctly and one of my buffers intermittently returns the exact same value you were getting

Reason: