Welcome to Forex-TSD!, one of the largest Forex forums worldwide, where you will be able to find the most complete and reliable Forex information imaginable.
From the list below, select the forum that you want to visit and register to post, as many times you want. It’s absolutely free. Click here for registering on Forex-TSD.
Exclusive Forum
The Exclusive Forum is the only paid section. Once you subscribe, you will get free access to real cutting-edge Trading Systems (automated and not), Indicators, Signals, Articles, etc., that will help and guide you, in ways that you could only imagine, with your Forex trading.
Elite Section
Get access to private discussions, specialized support, indicators and trading systems reported every week.
Advanced Elite Section
For professional traders, trading system developers and any other member who may need to use and/or convert, the most cutting-edge exclusive indicators and trading systems for MT4 and MT5.
First off, I would like to thank all the coders on this form for all their great work! Your teachings are invaluable!
Got a question for a coder. Im new to codeing and dont understand iCustom that much yet but her it goes. I get lost when the indicator is not returning a number value and returns an arrow with a color. I would like to use the N4 TF Has Bar custom indicator in my code and know how to use the arrow or color of the returned value but I am having a pore understanding of what this indicator is giving as its value. I think I got the syntax of the indicator of :
iCustom(NULL,0,"N4 TF Has Bar",MaMetod,MaPeriod,MaMetod2,MaPeriod2,BarWidth, BarColorUp,BarColorDown,TextColor,MaxBars,HasBarPe riod,1);
What value does this code return? I would like to use this code for a color or arrow change of a bar on a time like:
HasColor=iCustom(NULL,0,"N4 TF Has Bar",MaMetod,MaPeriod,MaMetod2,MaPeriod2,BarWidth, BarColorUp,BarColorDown,TextColor,MaxBars,HasBarPe riod,1);
or
HasArrow=iCustom(NULL,0,"N4 TF Has Bar",MaMetod,MaPeriod,MaMetod2,MaPeriod2,BarWidth, BarColorUp,BarColorDown,TextColor,MaxBars,HasBarPe riod,1);
if(HasColor==Blue)
or
if(HasArrow==up)
Hascolor = color of previous bar of the 3rd highest time frame on the indicator and "HasBarPeriod" = one of the 4 time frames on the indicator.
HasArrow = up of previous bar of the 3rd highest time frame on the indicator and "HasBarPeriod" = one of the 4 time frames on the indicator.
So if the previous arrow is up (Blue) on the 3rd highest time frame of the indicator it would buy but I would like to enter the trade on the color or arrow change of the indicator.
PS: Coders guru Thank you so much for all your lessons on MQL4.
WOW!
After a lot of research I have concluded there is not much information on coding a iCustom indicator, and I never found an example. So I’m going to make my best attempt at explaining what I have found. (Please, any coder out their let me know if any of this info is wrong, just want to make a valuable contribution to this site)
First we need to understand the syntax of the iCustom function. I will be referencing the N4 TF HAS Bar and Heiken Ashi Smoothed indicators in my examples.
Symbol: is the currency pair you want to work with. NULL means current symbol of the chart you have your EA attached to. So the syntax code starts like this: iCustom(Null
TimeFrame: The chart time frame you want to work with. 0 means current time frame of the chart your EA is attached to. Continued syntax code adding the TimeFrame: iCustom(Null,0
NameOfiCustomIndicator: The name of the Icustom indicator you are using. In my example it will be “N4 TF HAS Bar”. Use quotations before and after the name. Continued syntax code adding the NameOfiCustomIndicator: iCustom(Null,0, “N4 TF HAS Bar”
ExternalUserSetVariables: This is all of the extern parameters of the indicator you are using listed in order they appear in the code of the indicator. In our case we are using the N4 TF HAS Bar indicator. Open this indicator code in MetaEditor and you will find the following code:
extern int MaMetod = 2;
extern int MaPeriod = 6;
extern int MaMetod2 = 3;
extern int MaPeriod2 = 2;
extern int BarWidth = 0;
extern color BarColorUp = Blue;
extern color BarColorDown = Red;
extern color TextColor = White;
extern int MaxBars=500;
Every extern parameter now needs to be included in the syntax code IN THE ORDER LISTED IN THE INDICATOR CODE. Continued syntax code adding the ExternalUserSetVariables: iCustom(Null,0, “N4 TF HAS Bar”,MaMetod,MaPeriod,MaMetod2,MaPeriod2,BarWidth, BarColorUp,BarColorDown,TextColor,MaxBars
The mode parameter needs a close look at so we will continue this in the next post.
iCustom(NULL,0,"N4 TF Has Bar",MaMetod,MaPeriod,MaMetod2,MaPeriod2,BarWidth, BarColorUp,BarColorDown,TextColor,MaxBars,HasBarPe riod,1);
What value does this code return?
The iCustom(..) function returns the value of an entry in a buffer of the indicator. The last two arguments tell buffer number and index into that buffer.
So it is: iCustom(..., BufferNumber, Index )
You have to refer to the indicator code to know which buffer to read off. Usually you can see this by opening the Data Window (with the indicator attached), and then count from 0. I.e., buffer number 0 refers to the first
indicator buffer, 1 to the second etc.
Then you tell which Indexm i.e. for which bar into the past to get the value. Index 0 is the currently building bar, Index 1 the most recently completed bar, etc.
Mode: This is the iCustom indicators vale it out puts to the chart and the data we will need for our EA code. Go grab a beer and get comfortable!
The parameters used for Mode are: 0,1,2,3,4,5,6,7. So we have up to 8 to choose from. Now here is the hard part, you need to dig into the iCustom indicator to figure out what the indicator is returning as a value. NOTE THE HARD PART!
Also you may not use all 8 values. Let’s figure out how many we will use first. In the icustom code of the N4 TF HAS Bar you will find a line of code like this, #property indicator_buffers 8, this tells us we will us all 8 values(Mode values=0,1,2,3,4,5,6,7)
Now we need to look at the N4 TF HAS Bar code to find the SetIndexBuffer syntax and we find the following code, notice the SetIndexBuffer is also associated with other parameters also used with the Mode value:
SetIndexStyle(0,DRAW_ARROW,0,BarWidth,BarColorUp);
SetIndexArrow(0,ArrSize);
SetIndexBuffer(0,buf1_up);
SetIndexEmptyValue(0,0.0);
SetIndexStyle(1,DRAW_ARROW,0,BarWidth,BarColorDown );
SetIndexArrow(1,ArrSize);
SetIndexBuffer(1,buf1_down);
SetIndexEmptyValue(1,0.0);
SetIndexStyle(2,DRAW_ARROW,0,BarWidth,BarColorUp);
SetIndexArrow(2,ArrSize);
SetIndexBuffer(2,buf2_up);
SetIndexEmptyValue(2,0.0);
SetIndexStyle(3,DRAW_ARROW,0,BarWidth,BarColorDown );
SetIndexArrow(3,ArrSize);
SetIndexBuffer(3,buf2_down);
SetIndexEmptyValue(3,0.0);
SetIndexStyle(4,DRAW_ARROW,0,BarWidth,BarColorUp);
SetIndexArrow(4,ArrSize);
SetIndexBuffer(4,buf3_up);
SetIndexEmptyValue(4,0.0);
SetIndexStyle(5,DRAW_ARROW,0,BarWidth,BarColorDown );
SetIndexArrow(5,ArrSize);
SetIndexBuffer(5,buf3_down);
SetIndexEmptyValue(5,0.0);
SetIndexStyle(6,DRAW_ARROW,0,BarWidth,BarColorUp);
SetIndexArrow(6,ArrSize);
SetIndexBuffer(6,buf4_up);
SetIndexEmptyValue(6,0.0);
SetIndexStyle(7,DRAW_ARROW,0,BarWidth,BarColorDown );
SetIndexArrow(7,ArrSize);
SetIndexBuffer(7,buf4_down);
SetIndexEmptyValue(7,0.0);
So lets take this one at a time. The first SetIndexBuffer Syntax set of code we come across is:
SetIndexStyle(0,DRAW_ARROW,0,BarWidth,BarColorUp);
SetIndexArrow(0,ArrSize);
SetIndexBuffer(0,buf1_up);
SetIndexEmptyValue(0,0.0);
So what is this telling us? Notice the first 0 in side all of the Brackets () ? This ties together all of the parameters of Mode=0. 0 is the Mode out put value of the SetIndexBuffer used in this example for the iCustom function for the parameter of MODE. In this case MODE = 0! Or iCustom (Null,0, “N4 TF HAS Bar”,MaMetod,MaPeriod,MaMetod2,MaPeriod2,BarWidth, BarColorUp,BarColorDown,TextColor,MaxBars,0
(Please do some digging into the MetaEditor library for more info on all of the SetIndex functions.)
So now we know that if we use MODE = 0 that it will produce a value of “buf1_up” on its chart! See above code for this: SetIndexBuffer(0,buf1_up); as buf1_up is the value of MODE = 0 seen on the iCustom indicators chart.
(Also note that SetIndexEmptyValue(0,0.0); is set to 0, This will make more sense latter)
Now what value does this return? To find this out we must go deeper into the N4 TF HAS Bar indicator code to find this:
case 1:buf1_down[i]=EMPTY_VALUE;buf1_up[i]=EMPTY_VALUE; if (haOpen>=haClose) buf1_down[i] = 1; else buf1_up[i] = 1; break;
So with this said it will return a value of buf1_up of 0 or 1 and buf1_down of 0 or 1.
(Hint: EMPTY_VALUE always = 0 also please see SetIndexEmptyValue)
Confused yet? Yep, time to grab another beer! Chug it. Then a bathroom break! Don’t forget another beer, then reread this. LOL, I had to!
Still more to come as soon as I can get the wife and kids to let me back on this PC!
OK lets break this down:
case 1:buf1_down[i]=EMPTY_VALUE;buf1_up[i]=EMPTY_VALUE; if (haOpen>=haClose) buf1_down[i] = 1; else buf1_up[i] = 1; break;
It tells us buf1_down and buf1_up have initial values of EMPTY_VALUE!
So I trust every one has looked into “do some digging into the MetaEditor library for more info on all of the SetIndex functions”, right? Lol
Lets take a look at this: SetIndexEmptyValue(0,0.0);
This is telling us that SetIndexBuffer of 0 (buf1_up ) will equal 0.0 for the buf1_up value as defult. This is also true for the other 7 SetIndexBuffer parameters will also equal 0.0 but (remember that the SetIndexBuffer value returtned is the data we are using to code our EA and for this indicator and we have 8 total!)
So now we look at this:
“case 1:buf1_down[i]=EMPTY_VALUE;buf1_up[i]=EMPTY_VALUE; if (haOpen>=haClose) buf1_down[i] = 1; else buf1_up[i] = 1; break;”
Witch means :buf1_down AND buf1_up always = 0.0(EMPTY_VALUE ). So if the open is greater than or equal to the close, buf1_down will = 1 else this happens--- else buf1_up will =1!. Remember buf1_down is our Mode of 1(SetIndexBuffer(1,buf1_down)
So now we know that for the lowest time frame of the N4 TF HAS Bar we will use for our mode value of 0 or 1. One will produce a value of 0.0 and the other will produce a value of 1.
Here is a quick example of how you would code this.
Bar1Up=iCustom(NULL,0," N4 TF HAS Bar ",MaMetod,MaPeriod,MaMetod2,MaPeriod2,BarWidth,Bar ColorUp,BarColorDown,TextColor,MaxBars,0,0);
Bar1Down=iCustom(NULL,0," N4 TF HAS Bar ",MaMetod,MaPeriod,MaMetod2,MaPeriod2,BarWidth,Bar ColorUp,BarColorDown,TextColor,MaxBars,1,0);
Continued syntax code adding the MODE: iCustom(Null,0, “N4 TF HAS Bar”,MaMetod,MaPeriod,MaMetod2,MaPeriod2,BarWidth, BarColorUp,BarColorDown,TextColor,MaxBars,0
Shift: This is how many bars ago or the current bar you want to use. 0 = current bar (Note that using current bar values change throughout the time frame you are on. Example: if your code uses a current bar on close….well…when does a current bar close? Its close is the last tick for that bar! So every tick for the bar you are on is the close of that bar.)
Continued syntax code adding the Shift: iCustom(Null,0, “N4 TF HAS Bar”,MaMetod,MaPeriod,MaMetod2,MaPeriod2,BarWidth, BarColorUp,BarColorDown,TextColor,MaxBars,0,0)
This completes the syntax code for the N4 TF HAS Bar.
Here’ some code to help untangle the rest.
Values returned by Has Bar Indicator
Bar1UpOrDown == 1 or Empty, Bar2UpOrDown == 2 or Empty
Bar3UpOrDown == 3 or Empty, Bar4UpOrDown == 4 or Empty
Bar1Up=iCustom(NULL,0," N4 TF HAS Bar ",MaMetod,MaPeriod,MaMetod2,MaPeriod2,BarWidth,Bar ColorUp,BarColorDown,TextColor,MaxBars,0,0;
Bar1Down=iCustom(NULL,0," N4 TF HAS Bar ",MaMetod,MaPeriod,MaMetod2,MaPeriod2,BarWidth,Bar ColorUp,BarColorDown,TextColor,MaxBars,1,0;
Bar2Up=iCustom(NULL,0," N4 TF HAS Bar ",MaMetod,MaPeriod,MaMetod2,MaPeriod2,BarWidth,Bar ColorUp,BarColorDown,TextColor,MaxBars,2,0;
Bar2Down=iCustom(NULL,0," N4 TF HAS Bar ",MaMetod,MaPeriod,MaMetod2,MaPeriod2,BarWidth,Bar ColorUp,BarColorDown,TextColor,MaxBars,3,0;
Bar3Up=iCustom(NULL,0," N4 TF HAS Bar ",MaMetod,MaPeriod,MaMetod2,MaPeriod2,BarWidth,Bar ColorUp,BarColorDown,TextColor,MaxBars,4,0;
Bar3Down=iCustom(NULL,0," N4 TF HAS Bar ",MaMetod,MaPeriod,MaMetod2,MaPeriod2,BarWidth,Bar ColorUp,BarColorDown,TextColor,MaxBars,5,0;
Bar4Up=iCustom(NULL,0," N4 TF HAS Bar ",MaMetod,MaPeriod,MaMetod2,MaPeriod2,BarWidth,Bar ColorUp,BarColorDown,TextColor,MaxBars,6,0;
Bar4Down=iCustom(NULL,0," N4 TF HAS Bar ",MaMetod,MaPeriod,MaMetod2,MaPeriod2,BarWidth,Bar ColorUp,BarColorDown,TextColor,MaxBars,7,0;
Hope some one finds this helpful! Now I need that 4th beer!
Well I wrote a simple ea that does not work. Any ideas from anyone why it does not follow the rules.
The Rules: On a M5 Chart when the second line from the bottom of the N4 TF HAS Bar (M15 Line) Changes from blue to red go short & when it changes from red to blue to go long. This is not on the current bar of the chart but one bar back as to avoid the current bar from changing from blue to red then back to blue. As you can see in my examples its not following these rules at all, not even close and since im not a coder I have no clue why. Any assistance would be great! chart.gif
Here is the modified EA that should work correctly. Do not know if it will make profit but it will read the HAS correctly for trade direction.
Please note that when using the value from the 15 minute chart on the 5 minute chart the colors for 3 bars are for the corresponding open candle on the 15 minute chart. The EA is coded to only look at the current chart timeframe. So it does not follow your rules exactly as stated.
Robert
Last edited by MrPip; 11-10-2007 at 09:55 AM.
Reason: further details