Problem with output values of indicators - has anybody noticed it ?

 

Hi,

I'm new to mql4 coding, and have a problem with output values of indicators when coding my EA, for example stochastics or CCI.

I noticed that there is a remarkable difference between the values of an indicator seen on the chart after a backtest and the value the program "read" and use.

For exemple, for the CCI, i can read a value of 55 on the chart at a precise bar, let's say 6h the 20/04/2010 (on a H1 period) and if i read the value of the CCI on the journal at the same time (with the print operator) value can be randomly between around 35 to 75 !

This keep happening and make my EA ineficient because the value it takes to operate are inacurate.

Has anybody noticed it or could explain me how to solve this very strange thing ?

Thank you very much !

keyrama

 
Nobody believes it could be very annoying ?
 
keyrama wrote >>
Nobody believes it could be very annoying ?

yes, and that is why i do not use indicators in ea anymore...
 

Merci Gachette.

Any other more optimistic solution ?

 
keyrama wrote >>

Merci Gachette.

Any other more optimistic solution ?


Code your indicators as custom indicators. It's actually beneficial in many regards, forcing you to understand the fundamental mathematical basis of the indicator as well as empowering you to ensure the output is logical.
 
keyrama:

I noticed that there is a remarkable difference between the values of an indicator seen on the chart after a backtest and the value the program "read" and use.

Has anybody noticed it or could explain me how to solve this very strange thing ?

When the indicator and the Icustom values don't match, it's usually the indicator external values or buffer index is wrong in the Icustom.

Otherwise it is the EA using the indicator's initial values of a new bar which can vary wildly

 

Basically, what I'm saying is that mt4 do not use the same values for drawing the graph (who are correct) and for using in the EA(who are near random and i dont understand why). NO MATTER it is a icustom or NOT, no matter the parameters, buffers....etc used.


This is means if this problem cant be solved, MT4 is totally USELESS !!!

Nobody cares ????

 

I'm not sure I properly comprehend your dilemna...RSI, moving average, fractals, etc all work for me. Are you sure you aren't introducing a bug unknowingly at some point with your code?

 

It's not that nobody care, more that nobody concurrs. If an indicator and EA are properly coded, the values between the two will match.

I'm not sure what you mean by "near random" in your EA, but if you take a print of the value of an indicator sometime during index 0 ie when the bar is still forming, then you can't expect a figure based on the latest tick to match the figure based upon the tick at the close of the bar when you look back in history. Think of it this way, if you take a position at a price on a forming bar, it is unlikely that the price you accept will equal the price at the close of the bar. Load up an ATR with period 2 and watch how much the indicator moves during the formation of the latest bar. If your ea and indicator are referencing index 1 and there is a variance... there will be a difference in the input paramaters.

 

Let le be more clear. You can do the steps by yourself just to verify i'm telling the truth :

1 - call a CCI in an ea, a blank ea if you want ( blank ea's are properly coded i guess ?...)
2 - print the values of the EA.

3 - compare the values printed in the journal and the graph of CCI mt4 drawed.

Backtest on bar, so there is no problem with tick thing.

Values the mt4 gives on the journal are not same values mt4 gives on the graph. Randomly around 1 to 30 pts different.

 
keyrama:

Let le be more clear. You can do the steps by yourself just to verify i'm telling the truth :

1 - call a CCI in an ea, a blank ea if you want ( blank ea's are properly coded i guess ?...)
2 - print the values of the EA.

3 - compare the values printed in the journal and the graph of CCI mt4 drawed.

Backtest on bar, so there is no problem with tick thing.

Values the mt4 gives on the journal are not same values mt4 gives on the graph. Randomly around 1 to 30 pts different.

OK, I ran this...
int start()
  {
//----
   double val=iCCI(NULL,0,14,PRICE_CLOSE,0);
   Print(val);
//----
   return(0);
  }

for every tick and paused on a visual backtest. Confirmed the parameters in the EA matched indicator properties, started it, paused it and then checked the print in Journal with the data window value for the indicator. They are identical. I see no problem... Are you sure you used PRICE_CLOSE (or appropriate price enumeration) rather than MODE_CLOSE.... I have mixed them up before and it will run but give wiered results.

V


EDIT: And just to be clear, there aren't any problems when I run this on control point or open prices either.

Reason: