Download MetaTrader 5
To add comments, please log in or register
How to launch your trading signal and become a provider
marcoblbr
99
marcoblbr 2010.06.02 21:43 

Hi guys,


This question is simple but I couldn't find an answer to it. I built and indicator and I want to use it's return value in my robot.


// indicator code

int start ()
{
   ... // a lot of calculations

   return (3);
}


How can I use iCustom or any other method to get this value ? For what I was reading, it seems thar iCustom only return values that are on buffers, so I created a buffer and tried to put its return value on it, but it didn't work.


// code from the indicator

#property indicator_buffers  1

int value [];

int init ()
{
   SetIndexBuffer (0, value);
}

int start ()
{
   value [0] = 3;

   return (3);
}
// robot code

int start ()
{
   int i;

   i = iCustom (NULL, 0, "indicator", 0, 0);

   Print (i);

   return (0);
}


Any hints on how to get this value 3 on the indicator to be returned to the variable i in the robot ?


Thanks!! Any help is appreciated


Marco

Viffer
614
Viffer 2010.06.02 22:14  

You need to also pass the extern variables in order seperated by commas.

https://book.mql4.com/samples/shared

hth

V

marcoblbr
99
marcoblbr 2010.06.02 22:19  

Hi Viffer,


Let's say I did that. The code is actually really big, I just tried to simplify here, supposing there are no parameters at all. I still couldn't figure it out though. Passing the return value to a buffer should work, but it doesn't.

Viffer
614
Viffer 2010.06.02 22:34  
But the indicator must have an input variable...surely. A period or a bool or something?
marcoblbr
99
marcoblbr 2010.06.02 22:40  

Sure, but I still don't understand how can it be different. I changed the code!


// indicator code

#property indicator_buffers  1

extern int x = 0;

int value [];

int init ()
{
   SetIndexBuffer (0, value);
}

int start ()
{
   value [0] = x + 3;

   return (x + 3);
}
// ea code

int start ()
{
   int i;

   i = iCustom (NULL, 0, "indicator", 0, 0, 0);

   Print (i);

   return (0);
}
Viffer
614
Viffer 2010.06.02 22:47  

Sorry, apologies. I just tested it by removing the externs from an indicator and called it without passing the variables in iCustom and it worked OK.

Looked easy when I answered :). I will look some more

Viffer
614
Viffer 2010.06.02 23:05  

I'm not great on indicators, but it looks to me as though the problem is in there. I'm wondering if it's to do with the shifts and the way the indicator is set up. I'm not sure where value[0] is relative to the icustom shift. It may be that is the first bar on the chart and icustom is looking at the last... not sure though. I'm more familiar with indicators set up like...

int start()
  {

    int i;
    int    counted_bars = IndicatorCounted();
    i = CountBars - 1;
//----
    while(i >= 0)
      {
      value [i] = 3;
      }
      

//----
   
//----
   return(0);
  }

As I say, indicators are not my strongpoint though

V

cameo
464
cameo 2010.06.03 07:39  
marcoblbr:


Sure, but I still don't understand how can it be different. I changed the code!

Hi marco & Viffer, try this...

// indicator code
#property indicator_buffers 1

extern int x = 0;
int Buf_1[];

int init()
  {
   SetIndexBuffer(0, Buf_1);
   return(0);
  }
int start()
  {
   int counted_bars = IndicatorCounted();
   if( counted_bars < 0 ) return(-1);
   if( counted_bars > 0 ) counted_bars--;
   int limit = Bars - counted_bars - 1;
   
   for(int i=limit; i>=0; i--) Buf_1[i] = x + 3;
   return(0);
  }

// EA code
extern string Indy_name = "";
extern int buf_index = 0;
int EA_output0, EA_output1, EA_output2;

int start()
  {
   EA_output0 = iCustom(NULL,0,Indy_name,0,buf_index,0);
   EA_output1 = iCustom(NULL,0,Indy_name,0,buf_index,1);
   EA_output2 = iCustom(NULL,0,Indy_name,0,buf_index,2);
   
   Alert(" EA_output2 = ",EA_output2);
   Alert(" EA_output1 = ",EA_output1);
   Alert(" EA_output0 = ",EA_output0);
   return(0);
  }
I haven't test it....but it should be ok
rondoubledogg
5
rondoubledogg 2011.10.19 15:18  

Hello

I am having the same problem.

I have 3 lines of code at the beginning of my start function.

They run at every tick.

Basically it says

Takein0 = icustom(........."fib"....0)

Takein1 = icustom(........."fib"....1)

Takein2 = icustom(........."fib"....2)

the function is properly filled with the variables, so no problem there.

Also the variables are accessible by any part of the program..

The only thing is that only Takein0 gives me updated values. Takein1 and Takein2 never change....

any idea??anyone?

thanks
Simon Gniadkowski
Moderator
17972
Simon Gniadkowski 2011.10.19 15:40  
strive4more:

any idea??anyone?

thanks
Yes, please don't double post . . .
whroeder1
13929
whroeder1 2011.10.19 17:22  
marcoblbr:
This question is simple but I couldn't find an answer to it. I built and indicator and I want to use it's return value in my robot.
// indicator code
int start ()
{
   ... // a lot of calculations

   return (3);
}
How can I use iCustom or any other method to get this value ?

You can't. The return value from start is IGNORED.

You'll have to add another buffer and put the value in there.

/ /12
To add comments, please log in or register