Retrieve value from custom indicator

Hi everyone, I'm new to afl language my background is from mql4. There some questions that I need to ask regarding custom function.

In mql4 custom indicator can be called using a predefined function called iCustom, is there a similar function in amibroker?

The second question is when we want to retrieve value from the custom indicator. In mql4 we can retrieve it by referring to the custom indicator buffer. So, in amibroker does it works in similar manner since there's a same data window here?

Recommended readings:

thanks for the answer but I'm referring to predefined function that works similar to iCustom in mql4. The link you gave is about creating custom function not a predefined one. But, by the answer you gave me there isn't any predefined function that works similar to iCustom, is that right?


There are TWO links. Those links are about creating and calling custom function.

There is no iCustom.

You have to create yourself... as shown by the links that were given to you.

function iCustom(function_name, param1, param2, param3) {
	// re-creating something a like of iCustom of mql4
	switch (StrToLower(function_name)) {
		case "macd": 	x = MACD(param1, param2); break;
		case "stochd":	x = StochD(param1, param2, param3); break;
		// etc.
		default: 		x = 0; break;	
	return x;

val1 = iCustom("MACD", 12, 26, 0);

val2 = iCustom("StochD", 14, 3, 3);

Plot( val1, "Macd", colorRed, styleOwnScale );
Plot( val2, "StochD", colorOrange, styleOwnScale );

@ezraluandre, while the code provided by @fxshrat works, IMO, it makes little sense to approach Amibroker hoping to use it with same logic used in MQL4 (and probably it will make the learning curve steeper).

It is important to understand that Amibroker is array-based (even if, when there is no alternative, it is possible to use loops to iterate over arrays).

I suggest you to carefully read this @Tomasz's answer to a previous post (from another user coming from a different platform).
Please, spend all the time needed to study the provided links in his post, since this is ESSENTIAL to understand how AFL works.

Based on this knowledge, you will easily write you own functions and custom indicators. I suggest to search the forum - for example using "Ehlers" - to see how some fancy indicators are coded/ported to Amibroker (including them in custom functions or directly used as code snippets in formulas).

By the way, as you probably already discovered, AmiBroker provides many ready to use indicators: take a look at the "indicators" section of the categorical AFL Function Reference
You can use them directly or combine them as needed in your individually named custom functions.

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.