iCustom Question

526
2009.12.10 13:53

I have an indicator which compares several values. I which to bring those values into my EA. So far, what I've found, of the use of iCustom function is; calling the name of the indicator and comparing two different time periods of the same MA. How would I use iCustom to compare two different values of the same indicator.

103
2009.12.10 14:29
Change the shift, or the period, Depends on what you want to do?!
526
2009.12.10 19:38

Let's say that I have an MA of the average of the High and Low for a 15 min Period, and a MA of Close Price over 13 Periods, in the same Indicator. Let's say that I want to place a Buy, in my EA, when the MA of the Close Price crosses under the MA of the average of High/ Low, in the Indicator.

How would I utilize the iCustom Function to capture a state which occurs between two different MAs in the same Indicator?

103
2009.12.10 20:47

```int    counted_bars=IndicatorCounted();
int    i=Bars-counted_bars-1;

// loopig

double MaOfTheClosePreviousBar=iCustom(NULL,0,"",0,i+1);
double MaOfTheAverageHighLowPreviousBar=iCustom(NULL,0,"",0,i+1);

double MaOfTheCloseCurrentBar=iCustom(NULL,0,"",0,i);
double MaOfTheAverageHighLowCurrentBar=iCustom(NULL,0,"",0,i);

if (MaOfTheClosePreviousBar > MaOfTheAverageHighLowPreviousBar) && (MaOfTheCloseCurrentBar < MaOfTheAverageHighLowCurrentBar
{
// Sell
}

//Loop is Finished```
526
2009.12.11 16:06

My question, though, is with reqards to a single Custom Indicator which utilizes several different MAs. I want to compare the relationship of two of the MAs ( even their relationship to a third MA ) for my decisions regarding positioning of Buy and Sell Orders.

How would I utilize the iCustom Function, so that I can call and compare the relationship of two MAs, from within the same Custom Indicator.

Since I can't execute orders from an Custom Indicator, I have to bring these values into an EA.

double MaOfTheClosePreviousBar=iCustom(NULL,0,"",0,i+1);

double MaOfTheClosePreviousBar - Is the name of a value which I'm assigning within my EA.

iCustom(NULL,0,"",0,i+1); - Is the function which calls the Custom Indicator named between the quotes. The remaining values relate to this Indicator.

Calling a Custom Indicator with the iCustom Function is not the problem. The problem is that, when I call the indicator, how do I then call a specific MA or MAs for use within my EA.

If my Custom Indicator only had one MA, I would have no problems.

Do I have to take my Custom Indicator, with several MAs, and convert it to several indicators with one MA?

232
2009.12.11 16:43
Yellowbeard:

Hi Yellowbeard!

MA is a technical indicator and can be called by your EA, reading it's index buffers for data.

iCustom() is a command that can be used to access a custom built indicator.   That custom indicator can have one or several algorithms contained within it, and the result of those calculations routed to it's index buffers.  The iCustom() command can then be used to access the index buffers of your custom indicator.  The custom indicator can have multiple MA calculations within it, and each result assigned to any of the eight index buffers a custom indicator can contain, in MQL4.

If you already have the custom indicator built with two or three or more MA's, then you need to know which MA result is assigned to which index buffer.  Then use the iCustom() command in your EA to access the index buffers in your custom indicator... addressing the specific index buffer you need to import data from.

Now if you have 3 MA's in your custom indicator, and want to read a single phase from each, then your EA will use 3 iCustom() statements to import data for each phase from it's assigned index buffer.  One iCustom() call will not read all three index buffers simultaneously.  "For" loops are commonly used to rotate through what may appear to be a single iCustom() call.  In actuality the iCustom() statement is being accessed repeatedly, with a value incremented to address the next index buffer... so you could access say... three index buffers with one iCustom() call, but that statement is repeated and updated each pass through the "For" loop in your EA code.

Once the EA has captured the data from the indicator it is accessing, possibly using one or more iCustom() calls, then that data can be compared within the EA code and a buy or sell decision made.

However, if you are building an indicator that contains three MA's, then the comparison can be made in the indicator itself... which is actually better to do for a variety of reasons.  In that case, the indicator simply issues a buy or sell signal, using one of it's index buffers, instead of transmitting data for the EA to have to process.  Then you can use the custom indicator as a source of a "buy" or "sell" signal, and that is what you will be reading from the index buffers and not MA data.

I think this is what you are asking about... could be wrong, but hope this helps to clear things up for you.

526
2009.12.11 18:34
Yellowbeard wrote >>

Thanks for the help! Getting closer! Something seems to be missing, or I'm not quit doing it right. Am able to capture first MA but getting value of 0 for second.

Val1 = iCustom(NULL,0,"First_MA",13,3,0);
Val2 = iCustom(NULL,0,"Second_MA",0,6,0);

11:19:39 Test iCustom EURUSD,M1: Val1 = 30.11376832 : Val2 = 0.00000000

If I set Val1 at 0 for period I get: Val1 = 0.00000000 : Va2 = 0.00000000

But, no matter what value I set Val2 for period I get " Val2 = 0.00000000 "

232
2009.12.13 03:25
Yellowbeard:

Thanks for the help! Getting closer! Something seems to be missing, or I'm not quit doing it right. Am able to capture first MA but getting value of 0 for second.

Val1 = iCustom(NULL,0,"First_MA",13,3,0);
Val2 = iCustom(NULL,0,"Second_MA",0,6,0);

11:19:39 Test iCustom EURUSD,M1: Val1 = 30.11376832 : Val2 = 0.00000000

If I set Val1 at 0 for period I get: Val1 = 0.00000000 : Va2 = 0.00000000

But, no matter what value I set Val2 for period I get " Val2 = 0.00000000 "

Check to see if you actually have indicators with the file names "First_MA" and "Second_MA"... if that is the case, then

check to be sure that for "First_MA.mq4" that index buffer 3 is the correct buffer for reading it's MA data, and that for "Second_MA.mq4" that index buffer 6 is the correct buffer for reading it's MA data.

In the iCustom() statement... the actual filename minus the suffix ".mq4"  as you appear to have done correctly needs to be contained in the statement. If it doesn't have the exact filename(s), then it can't find the indicator file(s) that you are referencing.

What you are showing me is that you are using two different MA indicators, named "First_MA" and "Second_MA".  You are reading index buffer 3 for the "First_MA" indicator, and index buffer 6 for the "Second_MA" indicator.  You are reading bar 0 for both as well, and this all looks okay so far....

If everything is okay so far, then there is one more thing that you have to consider... an iCustom() statement also has to contain each external variable for the indicator you are attempting to read, in the same order as they are stated in the indicator.  You show a single external value of 13 for "First_MA" and 0 for "Second_MA".  This seems wrong to me.  Because most MA's have more than one external variable... ie  int period, int ma_shift, int ma_method, int applied_price... so, if your MA indicators have these or other external variables, then they need to be included in the iCustom() statements used to read those indicators, before you will actually read any valid data from them.

If you have any problems understanding this, then just post the code for the external variables for the MA indicators you are using, and I will put up an example of an iCustom() statement for you to read those MA's, okay?

(just copy the external variables from the .mq4 files for your indicators, and paste them here in the forum... You don't need to copy the whole indicator code)

Hope this helps.

14
2013.10.08 19:27
Hi, very interesting discussion...
what if I need daily High/Low of ab indicator?
Should I use iCustom?
Moderator
18002
2013.10.08 22:50
Denzel:
Hi, very interesting discussion...
what if I need daily High/Low of ab indicator?
Should I use iCustom?

There is a more recent thread all about iCustom . . . instead you dredge up a 4 year old thread, why ?