Download MetaTrader 5
To add comments, please log in or register
Interested in the Market activity? Come and track!
Maurice Ramaharomanana
283
Maurice Ramaharomanana 2015.11.01 21:10 

Hello,

The problem concerns the following: I've found out that using the iCustom() function makes my indicator too slow because it changes symbols after every new OnTimer() event. So i decided to turn the external indicator that i call with iCustom() into an internal function (i basically added the external indicator code as a function within the main indicator), this way all the external indicators that i use don't have to be reinitialized on each new symbol and now the mt4 terminal no longer chokes in repeated external indicator initialization because everything is already loaded within the main indicator. The problem is that the internal function variant of the external indicator (that used to be called with iCustom() isen't returning the same value as the external indicator variant does. I've tested this with the Print function and i used the classic ADX.mq4 as an example for the test. Please download the external ADX.mq4 and the ADXfunction.mq4 below, put both in the same indicator map and run the latter one. When you do so you can see that iCustom(ADX.mq4) is returning normal and different values for different timeframes (i test 6 different timeframes in the test indicator ADXfunction.mq4). The internal function variant of ADX.mq4 only returns the value 1861152494,0667 on every tested timeframe. Why is it doing this? Both codes are exactly the same. The only difference is that the second ADX is called internally while the first ADX variant is an external indicator called externally with iCustom(). Please please help me, i've spend the entire evening trying to track down the problem and i cannot find it. Help would be very much appriciated.

Thank you in advance

Files:
adx.mq4 4 kb
Maurice Ramaharomanana
283
Maurice Ramaharomanana 2015.11.01 22:00  

just an update: when i replace the eventhandler OnTimer() with int start() the internal function no longer returns 1861152494,0667  on every timeframe. The values don't exactly match those of the external adx indicator but they come close enough plus they change each time. So it has something to do with the event OnTimer which is causing the value to be 1861152494,0667. Does anyone know why? For some reason i have to add OnCalculate() too for OnTimer() to work. Perhaps OnCalculate is to blame too?


Regards,

Maurice Ramaharomanana
283
Maurice Ramaharomanana 2015.11.03 22:58  
anyone?
Keith Watford
Moderator
7869
Keith Watford 2015.11.04 05:11  

You are mixing data from different time-frames and possibly symbols in the same buffers

It is no good using  IndicatorCounted as it will not relate to the number of bars on a different time-frame.

You may need to have a separate set of buffers for every time-frame and every symbol that you use 

Maurice Ramaharomanana
283
Maurice Ramaharomanana 2015.11.05 00:45  
GumRai:

You are mixing data from different time-frames and possibly symbols in the same buffers

It is no good using  IndicatorCounted as it will not relate to the number of bars on a different time-frame.

You may need to have a separate set of buffers for every time-frame and every symbol that you use 

 

Should i use the function Bars as an alternative to IndicatorCounted() then? Also, please tell me how i can purge the indexbuffers after a timeframe iteration has been completed.

All i want the internal ADX(symbol,time) function to do is return the most recent value in the buffer (so that means returning ADXBuffer[0]), but this value is always an empty value.

I don't understand why. Please help.


Kind regards, 

Carl Schreiber
5927
Carl Schreiber 2015.11.05 09:43  

I don't know how the internal iADX() is calculated - but the way it is calculated in adx.mq4 differs from the original formula!

adx.mq4 uses the mt4 standard ema which at least (if mt4 does it that way) calculates the coefficient by 2/(n+1) Wilder e.g. uses only 1/n.

Keith Watford
Moderator
7869
Keith Watford 2015.11.05 09:59  

If you are going to purge the buffers, you may as well simply use iADX

I've not looked too deeply into the workings of the ADX, but it is possible that for ADX period n,you only need an array of n elements for each of the symbols and maybe make the array multidimensional according to the time-frames and equivalent buffer. Then "move the values along the array" when a new bar on the time-frame is opened. Then you only have to update the current bar.

/
To add comments, please log in or register