iCustom problem?

 

I have an indicator with 2 input values that gives out a "double" value of 0.0 or 1.0.

I am calling this indicator from the expert as follows:

TEST=iCustom(NULL,0,"TestInd",Average1,Average2,0,1);

if(TEST>0.5)
{
Opn_Buy=true;
Cls_Sell=true;
}
else
{
Opn_Sell=true;
Cls_Buy=true;
}

For one or the other reason, TEST remains zero and my expert only reacts on time settings and stop loss and profit settings.

This you can see in the attached chart. The indicator displays OK, but the trading is wrong because TEST stays at 0.

If I replace the TESTInd with any other digital indicator it works fine. The only difference I can see is that the TESTInd indicator is rather complex and calls other indicators. Could there be a timing problem? Or what am I overlooking?

Thanks for helping

 
sylvano45:

I have an indicator with 2 input values that gives out a "double" value of 0.0 or 1.0.

I am calling this indicator from the expert as follows:

TEST=iCustom(NULL,0,"TestInd",Average1,Average2,0,1);

if(TEST>0.5)
{
Opn_Buy=true;
Cls_Sell=true;
}
else
{
Opn_Sell=true;
Cls_Buy=true;
}

For one or the other reason, TEST remains zero and my expert only reacts on time settings and stop loss and profit settings.

This you can see in the attached chart. The indicator displays OK, but the trading is wrong because TEST stays at 0.

If I replace the TESTInd with any other digital indicator it works fine. The only difference I can see is that the TESTInd indicator is rather complex and calls other indicators. Could there be a timing problem? Or what am I overlooking?

Thanks for helping

Here is the picture...

 
sylvano45:

TEST=iCustom(NULL,0,"TestInd",Average1,Average2,0,1);

For one or the other reason, TEST remains zero

  1. Since you didn't show the indicator's code, there's no way for us to know whither the iCustom call is correct.
  2. Since you know there's a problem, why didn't you print GetLastError() after the iCustom() so you know which reason "or other."
 
WHRoeder:

  1. Since you didn't show the indicator's code, there's no way for us to know whither the iCustom call is correct.
  2. Since you know there's a problem, why didn't you print GetLastError() after the iCustom() so you know which reason "or other."


There is no error .The error code returned is 0.

Also when I use iCustom to call the same indicator with the code hereafter, it is displayed correctly. So, that is why I can not understand why it is not working in the expert part.

#property indicator_separate_window
extern int Average1=30;
extern int Average2=30;

double TEST[];
//---------------------------------------------------------------
int init()
  {   
   IndicatorBuffers(1);
   SetIndexBuffer(0,TEST);
   SetIndexStyle(0,DRAW_LINE);
  }
//------------------------------------------------------------------
int start()
{         
    int a,limit;
    int counted_bars=IndicatorCounted();
    if(counted_bars>0) counted_bars--;
    limit=Bars-counted_bars;
    for(a=limit; a>=0; a--) TEST[a]=iCustom(NULL,0,"TESTInd",Average1,Average2,0,a);
return(0);
}
 
sylvano45:


There is no error .The error code returned is 0.

Also when I use iCustom to call the same indicator with the code hereafter, it is displayed correctly. So, that is why I can not understand why it is not working in the expert part.

I s there somewhere an explanation about the exact iCustom behaviour when used as follows in an EA?

double TEST=iCustom(NULL,0,"TestInd",0,1);

There is clearly something within the indicator that allows it to work perfect as an indicator, but it gives problems when called as above in an EA.

 

For me, these kinds of questions aren't easy to answer. The person asking the question usually posts limited information thinking it's enough for the so-called pro's to solve their problems. In my opinion, there's Not enough information to help solve your problem. If I were asking for answer to something like this, I'd post the code for the EA and the Indicator. I'd explain what I'm trying to accomplish vs what I'm getting and what I've done.

Is there somewhere an explanation about the exact iCustom behaviour when used as follows in an EA?

No.

There is clearly something within the indicator that allows it to work perfect as an indicator, but it gives problems when called as above in an EA.

You're assuming the Indicator's the problem. Why not the EA?

If you don't want to show all your codes as most ppl are paranoid to do then. Do the following. print out the indicator's value. I wanna see it going from 0.0 to 1.0. (I have an indicator with 2 input values that gives out a "double" value of 0.0 or 1.0.).

Next, print out the values of Opn_Buy and Opn_Sell at the end of the EA (right b4 it returns(0) from the start). I also wanna see which order send is sent last. Buy or Sell. I think it's fairly obvious where I'm going with this. Do those things and see if it helps.

 
ubzen:

For me, these kinds of questions aren't easy to answer. The person asking the question usually posts limited information thinking it's enough for the so-called pro's to solve their problems. In my opinion, there's Not enough information to help solve your problem. If I were asking for answer to something like this, I'd post the code for the EA and the Indicator. I'd explain what I'm trying to accomplish vs what I'm getting and what I've done.

Is there somewhere an explanation about the exact iCustom behaviour when used as follows in an EA?

No.

There is clearly something within the indicator that allows it to work perfect as an indicator, but it gives problems when called as above in an EA.

You're assuming the Indicator's the problem. Why not the EA?

If you don't want to show all your codes as most ppl are paranoid to do then. Do the following. print out the indicator's value. I wanna see it going from 0.0 to 1.0. (I have an indicator with 2 input values that gives out a "double" value of 0.0 or 1.0.).

Next, print out the values of Opn_Buy and Opn_Sell at the end of the EA (right b4 it returns(0) from the start). I also wanna see which order send is sent last. Buy or Sell. I think it's fairly obvious where I'm going with this. Do those things and see if it helps.


Let me try once more...

I assume the MT4 programmers know how iCustom works and it would be logical that the behaviour is documented somewhere.

I use always the same EA. The only difference is which indicator is called with iCustom and the condition that is set (see my first message). This works fine for all my other EA and indicators.

Now I have that same EA I always use and that always works with all other indicators and I have an indicator that displays correctly on the chart on it's own.

If I start playing around and simplify the indicator the EA it will start working. But I still have not figured out which part in the EA has this effect. Reason why a detailed explanation of how iCustom works could help me and probably others.

And no I do not yet want to post my indicator as long as I have not tested it as an EA. And because somebody else wrote the MT4 code first that I have modified now, from my original code.

Maybe someone had a similar experience?

Kind regards,

 

Let me try once more:

If you don't want to show all your codes as most ppl are paranoid to do then. Do the following. print out the indicator's value. I wanna see it going from 0.0 to 1.0. (I have an indicator with 2 input values that gives out a "double" value of 0.0 or 1.0.).

Next, print out the values of Opn_Buy and Opn_Sell at the end of the EA (right b4 it returns(0) from the start). I also wanna see which order send is sent last. Buy or Sell. I think it's fairly obvious where I'm going with this. Do those things and see if it helps.

Here's the docs for iCustom() -(but I bet you wouldn't find the below helpful)- Anything more comes with experience. What do you want us to say, "iCustom have a bug when being called within an EA or Indicator?". What I learned from programming - when the codes don't work as expected, it's 99.999% chance myFault. Not the fault of the Instruments which have been tried and tested by everyone for years. And if I'm wrong, oh-well big deal. You've just found a Bug in iCustom. I hope a Guru comes along and confirm your find.

double iCustom( string symbol, int timeframe, string name, ..., int mode, int shift)
Calculates the specified custom indicator and returns its value. The custom indicator must be compiled (*.EX4 file) and be in the terminal_directory\experts\indicators directory.
Parameters:
symbol - Symbol the data of which should be used to calculate indicator. NULL means current symbol.
timeframe - Timeframe. It can be any of Timeframe enumeration values. 0 means the current chart timeframe.
name - Custom indicator compiled program name.
... - Parameters set (if necessary). The passed parameters and their order must correspond with the desclaration order and the type of extern variables of the custom indicator.
mode - Line index. Can be from 0 to 7 and must correspond with the index used by one of SetIndexBuffer functions.
shift - Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago).
Sample:
  double val=iCustom(NULL, 0, "SampleInd",13,1,0);

Reason: