iCustom give a wrong output

 

Hi,

     I am porting my EA from MQL4 to MQL5. In that I am using iCustom() function. It returns a very different data. The output is

2013.07.01 13:23:48 test (EURUSD,H1) Sell = 4035.0

2013.07.01 13:23:48 test (EURUSD,H1) Buy = 4034.0

It is supposed to be 0 and 1 to 1.9. Cuz it is been used in EURUSD. Please help with this. Thanks in Advance.

void OnTick()
  {
     double Buy_Signal = iCustom(_Symbol,PERIOD_H1,"BFS_Stoc",0,1);
     double Sell_Signal = iCustom(_Symbol,PERIOD_H1,"BFS_Stoc",1,1);
     Print("Buy = ", Buy_Signal);
     Print("Sell = ", Sell_Signal);
         
  }
Documentation on MQL5: Technical Indicators / iCustom
Documentation on MQL5: Technical Indicators / iCustom
  • www.mql5.com
Technical Indicators / iCustom - Documentation on MQL5
 
krishna_gopal_2:

Hi,

     I am porting my EA from MQL4 to MQL5. In that I am using iCustom() function. It returns a very different data. The output is

2013.07.01 13:23:48 test (EURUSD,H1) Sell = 4035.0

2013.07.01 13:23:48 test (EURUSD,H1) Buy = 4034.0

It is supposed to be 0 and 1 to 1.9. Cuz it is been used in EURUSD. Please help with this. Thanks in Advance.

Please read the documentation for the functions you are using,  do not assume they work as they do in mql4,  most do not . . .  iCustom()  "The function returns the handle of a specified custom indicator."
 
RaptorUK:
Please read the documentation for the functions you are using,  do not assume they work as they do in mql4,  most do not . . .  iCustom()  "The function returns the handle of a specified custom indicator."
Please, don't multiply the topics on the same issue. You already received the answers to this issue.
 
angevoyageur:
Please, don't multiply the topics on the same issue. You already received the answers to this issue.

/////////////Global/////////////
double preBuy = 0;
double preSell = 0;
double Sell_Signal[]; 
double Buy_Signal[];
////////////////Inside OnTick()///////////////
if(WithIndicator)
      {
         int Stoc_Handler = iCustom(_Symbol,PERIOD_H1,"Examples\\BFS_Stoc");
         int iBuy = CopyBuffer(Stoc_Handler,1,1,1,Buy_Signal);
         int iSell = CopyBuffer(Stoc_Handler,0,1,1,Sell_Signal);
         if(Buy_Signal[0] != Sell_Signal[0] && (Buy_Signal[0] != preBuy || Sell_Signal[0] != preSell))
         {
            Print("Buy = ", Buy_Signal[0]);
            preBuy = Buy_Signal[0];
            Print("Sell = ", Sell_Signal[0]);
            preSell = Sell_Signal[0];
         }
         sIndi = "Indicator,";
      }

Sorry for multiplying posts. I have a doubt in iCustom again. Please have a look in the code given below. 

~~~~~~~~~~~~~~~~Second Signal~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 

 2013.07.02 18:59:03 2013.01.02 12:00:00   Sell = 1.3278175

2013.07.02 18:59:03 2013.01.02 12:00:00   Buy = 0.0

~~~~~~~~~~~~~~~~~First Signal~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 

2013.07.02 18:58:50 2013.01.02 07:00:00   Sell = 9.881312916824931e-324

2013.07.02 18:58:50 2013.01.02 07:00:00   Buy = 0.0

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 

 I get the above output.  There is no first signal. But I get some garbage value when I start the tester. Tell me whats wrong with this code.

 
krishna_gopal_2:

~~~~~~~~~~~~~~~~Second Signal~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 

 2013.07.02 18:59:03 2013.01.02 12:00:00   Sell = 1.3278175

2013.07.02 18:59:03 2013.01.02 12:00:00   Buy = 0.0

~~~~~~~~~~~~~~~~~First Signal~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 

2013.07.02 18:58:50 2013.01.02 07:00:00   Sell = 9.881312916824931e-324

2013.07.02 18:58:50 2013.01.02 07:00:00   Buy = 0.0

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 

 I get the above output.  There is no first signal. But I get some garbage value when I start the tester. Tell me whats wrong with this code.

You probably have to use something like :

if((Buy_Signal[0] != EMPTY_VALUE && Buy_Signal[0] != preBuy) || (Sell_Signal[0] != EMPTY_VALUE && Sell_Signal[0] != preSell))

The value printed show maybe an empty value for the Sell buffer of your indicator. Not sure as this is value is weird (by default EMPTY_VALUE = DBL_MAX). If that doesn't work the issue is probably in your indicator.

 
angevoyageur:

You probably have to use something like :

The value printed show an empty value for the Sell buffer of your indicator.

But I checked the indicator. All values are initialized as zero before starting. And Data window confirms it. 

      SellBuffer[bar]=0.0;
      BuyBuffer[bar]=0.0;

.

 
krishna_gopal_2:

But I checked the indicator. All values are initialized as zero before starting. And Data window confirms it. 

.

Then try to check the returned value of CopyBuffer :

if (iBuy==1 && iSell==1 ....
 
angevoyageur:

Then try to check the returned value of CopyBuffer :

2013.07.02 20:12:47 2013.01.02 04:07:59   Sell = 9.881312916824931e-324
2013.07.02 20:12:47 2013.01.02 04:07:59   Buy = 0.0

Sorry to disturb you. Again same issue. Even after adding "if (iBuy==1 && iSell==1 ...."


 
krishna_gopal_2:

Sorry for multiplying posts. I have a doubt in iCustom again. Please have a look in the code given below. 

~~~~~~~~~~~~~~~~Second Signal~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 

 2013.07.02 18:59:03 2013.01.02 12:00:00   Sell = 1.3278175

2013.07.02 18:59:03 2013.01.02 12:00:00   Buy = 0.0

~~~~~~~~~~~~~~~~~First Signal~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 

2013.07.02 18:58:50 2013.01.02 07:00:00   Sell = 9.881312916824931e-324

2013.07.02 18:58:50 2013.01.02 07:00:00   Buy = 0.0

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 

 I get the above output.  There is no first signal. But I get some garbage value when I start the tester. Tell me whats wrong with this code.

Don't you need to resize your array and set it as a series array ?  you are writing an EA not an Indicator,  there are no buffers in EAs,  you have to look after the arrays yourself.
 
RaptorUK:
Don't you need to resize your array and set it as a series array ?  you are writing an EA not an Indicator,  there are no buffers in EAs,  you have to look after the arrays yourself.

In theory yes, but here he is only read 1 value so that doesn't make a difference.

krishna_gopal_2:
2013.07.02 20:12:47 2013.01.02 04:07:59   Sell = 9.881312916824931e-324
2013.07.02 20:12:47 2013.01.02 04:07:59   Buy = 0.0

Sorry to disturb you. Again same issue. Even after adding "if (iBuy==1 && iSell==1 ...."

I don't understand your problem, I can try to help you if you can provide the indicator's code.
 
angevoyageur:

In theory yes, but here he is only read 1 value so that doesn't make a difference.

I don't understand your problem, I can try to help you if you can provide the indicator's code.
   Here I have attached the indicator.
Files:
BFS_Stoc.mq5  8 kb