[MT4] Strange problems with custom EA and iCustom

To add comments, please log in or register
mwfx108
18
mwfx108  

Hello,


I've got a Custom Indicator which outputs Entry Signals on the chart. In the Data Window I can see that the Indicator has 5 "Index Buffers" and outputs "Buy", "Sell", "Entry", "SL" and "TP".


I want to query this Indicator in an EA via iCustom.


The Indicator has several parameters. Mostly "Int" type, some "String" type separators, some "Double" type and some "Color" type. For instance:


Indicator Settings


And a few more. But let's assume these are all the parameters.


I use iCustom to call the Indicator like this:


extern int Ind_Min_Pattern_Length = 20;                        // Min. Pattern Length, points
extern int Ind_Min_Candles_Between = 36;                       // Min. Candles Between Signals
extern int Ind_Min_Clean_Candles = 36;                         // Min. Clean Candles
extern int Ind_Clean_Candles_Extra_Dist =5;                    // Clean Candles Extra Distance, points
extern double Ind_Min_TP_Ratio = 2.0;                          // Min. TP Ratio
extern double Ind_SL_Offs = 10.0;                              // Stop Loss Offset, points
extern string sep04 = "Slow MA";                               // ==== Slow MA ====
extern int Ind_SlowMA_Period = 200;                            // Period
extern ENUM_MA_METHOD Ind_SlowMA_Method = MODE_EMA;            // Method
extern ENUM_APPLIED_PRICE Ind_SlowMA_Appl_Price = PRICE_CLOSE; // Applied Price
extern int Ind_SlowMA_Shift = 0;                               // MA Shift

const int Data_Index_Buy = 0;

// ...

double result = iCustom( _Symbol, PERIOD_CURRENT, Ind_Path_Name,
  Ind_Min_Pattern_Length,       // Min. Pattern Length, points
  Ind_Min_Candles_Between,      // Min. Candles Betwen Signals
  Ind_Min_Clean_Candles,        // Min. Clean Candles
  Ind_Clean_Candles_Extra_Dist, // Clean Candles Extra Distance, points
  Ind_Min_TP_Ratio,             // Min. TP Ratio
  Ind_SL_Offs,                  // Stop Loss Offset, points
  "",                           // ==== Slow MA ====
  Ind_SlowMA_Period,            // Period
  Ind_SlowMA_Method,            // Method
  Ind_SlowMA_Appl_Price,        // Applied Price
  Ind_SlowMA_Shift,             // MA Shift
  Data_Index_Buy,               // Index Buffer Buy = 0
  1                             // Shift = 1 = Previous bar
);


When the Indicator finds a valid (buy) signal, the result of querying the "Index Buffer" 0 (Buy) is the current bid price of the Symbol, otherwise EMPTY_VALUE (2147483647).


Now the strange problem is, it all works perfectly fine in backtests. The EA receives A LOT of signals from the Indicator all over the test period. Also when I put the Indicator separately on the chart during the backtest to see if the EA and the Indicator match up, they do so perfectly fine. The Indicator outputs a signal, and on the next tick the EA receives the same signal with the same values via iCustom and opens a trade.


However, during forward testing on a Live / Demo account, only the Indicator works and does its job. The EA doesn't seem to work, even though all settings for the Indicator and the EA are the same. During Live testing, the EA always receives EMPTY_VALUE from iCustom all the time, while the Indicator outputs signals on the chart. And sometimes, in like 1 of 10 cases, the EA receives the signal from the Indicator and opens a trade. As said before: The Indicator and the EA use exactly the same settings for the parameters (Min Pattern Length, Min Candles Between, ...). The path to the Indicator passed to iCustom is correct, etc.


Unfortunately, the only thing I can do to debug the problem is output the values I receive via iCustom. And they are mostly EMPTY_VALUE. So it doesn't help that much. I don't have the code of the Indicator, because it was given to me by a friend who kind of purchased it a while ago and asked me if I could wrap an EA around it. And the programmer of the Indicator seems to have left the scene. I can't attach the Indicator here, because of the Licensing reasons and thus was asked to not do so.

  • Have you ever seen such a behavior of iCustom?

  • What could be the cause that the EA can query the Indicator perfectly fine in the backtest, but doesn't seem to receive any valid results from iCustom during forward testing?

  • Do I miss something? Am I making something wrong?

  • Can an Indicator know if it was queried via iCustom and return garbage values?

  • I assume that you need to pass ALL parameters on the iCustom call, also the String separators?

Thanks a lot in advance for your time and help!

Seng Joo Thio
1215
Seng Joo Thio  
mwfx108:
  • Have you ever seen such a behavior of iCustom?

  • What could be the cause that the EA can query the Indicator perfectly fine in the backtest, but doesn't seem to receive any valid results from iCustom during forward testing?

  • Do I miss something? Am I making something wrong?

  • Can an Indicator know if it was queried via iCustom and return garbage values?

  • I assume that you need to pass ALL parameters on the iCustom call, also the String separators?

You either pass in ALL parameters, or you pass in NONE, in which case default values will be used - so that's something you can try out:

double result = iCustom( _Symbol, PERIOD_CURRENT, Ind_Path_Name,
                        Data_Index_Buy,               // Index Buffer Buy = 0
                        1                             // Shift = 1 = Previous bar
);

On your second qn, an indicator can know whether it is running in backtest or not, and decide how to behave in each case... but without any code, we can only guess. Similarly, for your 4th qn, there is no way, as far as I'm aware of, but again, we can only guess... LOL

If you can attach your complete EA code, that might shed some lights... or trigger off more ideas for testing... of course, that is making the assumption that there is nothing unusual going on within the indicator "black-box"...

mwfx108
18
mwfx108  

Thanks for your time to reply. :)

Yes, you are right. Without having the code for the Indicator it is a "needle in the haystack" search. :/


Seng Joo Thio:

You either pass in ALL parameters, or you pass in NONE, in which case default values will be used - so that's something you can try out:

Yes, I do pass in ALL parameters. Just didn't want to clutter the forum with 30+ parameters. The default values of the Indicator are all 0. So calling iCustom without any parameters wouldn't lead to anything.

Besides some trade logic, this actually is - more or less - the core for the EA. The result from iCustom is returned from a function, so that I don't need to repeat the code for the other Index Buffers. And if the result from Data_Index_Buy (0) or Data_Index_Sell (1) is other than EMPTY_VALUE, it opens a particular trade with the given SL and TP prices.

As I said, the strange thing is:

  • If you put the Indicator alone on the chart in a live / demo account, it works fine.
  • If you put the Indicator alone on the chart in a backtest, it also works fine.
  • If you call iCustom to query the Indicator from the EA - with all the same parameters - during backtest, it also works perfectly fine.
  • If you put the Indicator on the chart during backtest of the EA, you can see they match up perfectly. The Indicator signals a Trade and in the next tick the EA receives the same Trade Signal via iCustom and opens a trade.
  • BUT if you have the EA running on a live / demo account, it receives nothing but EMPTY_VALUE all the time from iCustom. Even when the same Indicator with the same parameters on the same chart outputs a Trade Signal, the EA still receives EMPTY_VALUE ... ?!

In a nutshell:

  • Parameters for the Indicator and the EA are all the same.
  • All parameters are getting passed to the Indicator on iCustom call.
  • Indicator works fine on a live / demo account.
  • Indicator works fine in backtest.
  • EA works perfectly fine during backtest.
  • EA doesn't work on a live / demo account. Even when the Indicator signals a trade, the EA still receives EMPTY_VALUE from either Data_Index_Buy (0) and Data_Index_Sell (1).
  • "Auto Trading" etc. is (of course) enabled.
I already tried to use different values for "Shift", like 0 or 2, but this only resulting in the EA not even working anymore in the backtest. So 1 seems to be the right value.

William Roeder
20228
William Roeder  
mwfx108:
I already tried to use different values for "Shift", like 0 or 2, but this only resulting in the EA not even working anymore in the backtest. So 1 seems to be the right value.

This leads me to think that it is repainting. If one works, two should one bar later.
Alain Verleyen
38701
Alain Verleyen  
Seng Joo Thio:

You either pass in ALL parameters, or you pass in NONE, in which case default values will be used - so that's something you can try out:

...

It's not totally exact, ALL/NONE are correct, but you can also pass any number of parameters, provided they are in the right order (1st, 2nd,...), the missing parameters will use the default values.

Seng Joo Thio
1215
Seng Joo Thio  
Alain Verleyen:

It's not totally exact, ALL/NONE are correct, but you can also pass any number of parameters, provided they are in the right order (1st, 2nd,...), the missing parameters will use the default values.

Thanks for pointing that out - I never considered this possible, and never even tried it out... not sure why though... 

And the right ordering part simply motivates programmers to declare parameters that are more dynamic, first. 

mwfx108
18
mwfx108  

Ok, we solved it. Problem was:

The EA was designed to query the Indicator once every new bar.

However, the Indicator seems to work differently: It doesn't give the signal on a new bar, but rather on a tick-basis. It seems to wait for confirmation and then gives the signal during the candle.

I changed the EA to also query the Indicator on every tick and this seems to work reliably now. :)

To add comments, please log in or register