Problem with iCustom

 
I have an Expert Advisor that uses iCustom to retrieve the values of a custom indicator. iCustom is returning values that are causing the EA to move in and out of trades when, if I were trading manually, I would have stayed in a particular trade until the indicator flashed the true signal.

At the end of the backtest, the plotted indicator's values are different from the values in the EA's Print statements, which are obtained from iCustom. The plotted indicator clearly indicates that no trade should have been signaled, yet the values from iCustom are signaling trades, causing the EA to move in and out of positions inappropriately. Needless to say, this is a huge problem - I cannot trust the EA to properly trade the system.

Here are snippets of the pertinent code:
The indicator (with variables names and values modified by me to suit my preferences)
//+------------------------------------------------------------------+ 
//| Slope Direction Line RR.mq4 
//| Copyright © 2006 WizardSerg <wizardserg@mail.ru>, ?? ??????? ForexMagazine #104 
//| wizardserg@mail.ru 
//| Revised by IgorAD,igorad2003@yahoo.co.uk |   
//| Personalized by iGoR AKA FXiGoR for the Trend Slope Trading method (T_S_T) 
//| Link: 
//| contact: thefuturemaster@hotmail.com                                                                         
//+------------------------------------------------------------------+
#property copyright "MT4 release WizardSerg <wizardserg@mail.ru>, ?? ??????? ForexMagazine #104" 
#property link      "wizardserg@mail.ru" 

//---- input parameters 
extern int     MA_Length = 10; 
extern int     MA_Method = MODE_SMMA;   // Smoothed Moving Average 
extern int Applied_Price = PRICE_CLOSE;

--------------------------------------------------------------------------------
The Expert Advisor
//+------------------------------------------------------------------+
//|Slope System v0.1.mq4                                             |
//|Basic reversal system using the Slope Direction Line RR indicator |
//|                                                                  |
//+------------------------------------------------------------------+
#include <stdlib.mqh>

#property copyright "Copyright 2010 by Neil D. Rosenthal and Michael Moses"

#define  MODE_UP	0
#define  MODE_DOWN	1

//---- input parameters
extern string    SI_Name = "Slope Direction Line RR";
extern int     MA_Length = 10; 
extern int     MA_Method = MODE_SMMA;   // Smoothed Moving Average
extern int Applied_Price = PRICE_CLOSE;

SI_Up_Current = iCustom(CurrencyPair,0,SI_Name,MA_Length,MA_Method,Applied_Price,MODE_UP,1); //Value of Uptrend from the just-closed bar
SI_Up_Previous = iCustom(CurrencyPair,0,SI_Name,MA_Length,MA_Method,Applied_Price,MODE_UP,2); //Value of Uptrend from the previous bar
SI_Down_Current = iCustom(CurrencyPair,0,SI_Name,MA_Length,MA_Method,Applied_Price,MODE_DOWN,1); //Value of Dntrend from the just-closed bar
SI_Down_Previous = iCustom(CurrencyPair,0,SI_Name,MA_Length,MA_Method,Applied_Price,MODE_DOWN,2); //Value of Dntrend from the previous bar
Print("SI_Up_Current = ",SI_Up_Current);
Print("SI_Up_Previous = ",SI_Up_Previous);
Print("SI_Down_Current = ",SI_Down_Current);
Print("SI_Down_Previous = ",SI_Down_Previous);

That's it. You can see that I have matched the input parameter set of the indicator within the function call to iCustom, yet the values of the plotted indicator do not match the values from the function call. The values returned from iCustom are causing trades to be signaled incorrectly.

Is this a bug within iCustom/MT4? Is there a work-around? This problem is confounding, and makes the EA useless, which is unfortunate, because it shows such promise.

All help is greatly appreciated.

scratchman
 
i cannot see any error, you are only querying closed bars that shouldn't change anymore if the indicator does not repaint. a bug in mt4 is unlikely since thousands of others would have experienced the same problems too in this case. A bug or design flaw somewhere in your code is more likely. Did you try to slowly run it in visual mode to see what actually happens at these moments?
 

the following works for me:

check how many 'IndexBuffers' there are in the Custom Indicator, then call that specific Buffer number in iCustom in the second last value, ie number 1 for buffer 1. the last number is the shift value for the indicator.

see below:

   double L_1 =iCustom(NULL,0,"rocseparate",H,P2,B,A,1,0);  // the second last number, "1" is for buffer no.1
   
hope it works.
 
That's it. You can see that I have matched the input parameter set of the indicator within the function call to iCustom, yet the values of the plotted indicator do not match the values from the function call. The values returned from iCustom are causing trades to be signaled incorrectly.

Is this a bug within iCustom/MT4? Is there a work-around? This problem is confounding, and makes the EA useless, which is unfortunate, because it shows such promise.
You appear to have matched the call correctly. (Indicator code at http://www.fxfisherman.com/forums/forex-metatrader/system-coding/2947-slope-system-ea.html) Three external int's and three buffers (up=0, dn=1, IMA)

It is NOT a bug within iCustom/MT4. It IS a bug in YOUR code.

What is the problem, you don't say. What are the values, you don't say. Looking at the code I see
    if (trend[x]>0)
    { Uptrend[x] = ExtMapBuffer[x]; 
      if (trend[x+1]<0) Uptrend[x+1]=ExtMapBuffer[x+1];
      Dntrend[x] = EMPTY_VALUE;
    }
Are you checking for EMPTY_VALUES?
Do you really want to check bar0, that may change many times until bar end?
Reason: