| New signals service! | |
|
|||||||
| Register in Forex TSD! | |
|
Trading Systems Leaders in this forum (automated trading systems) are winning more than 3000 pips in a month (30000$ investing one lot every time). Click here to register and get more information |
|
![]() |
|
|
LinkBack (1) | Thread Tools | Display Modes |
|
||||
|
How to code a iCustom indicator
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. iCustom(Symbol,TimeFrame,NameOfiCustomIndicator,Ex ternalUserSetVariables,Mode,Shift) 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. |
|
||||
|
Quote:
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! |
|
||||
|
Quote:
![]() Last edited by ralph.ronnquist; 08-15-2007 at 09:55 AM. |
|
||||
|
Ok, Here I go again!
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! |
|
||||
|
EA not trading right
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 chart2.gif N4 TF HAS Bar Example EA.mq4 |
|
|||
|
Ea
In reply to a pm.
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 08:55 AM. Reason: further details |
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
LinkBacks (?)
LinkBack to this Thread: http://www.forex-tsd.com/metatrader-4/9007-n4-tf-has-bar-coding.html
|
||||
| Posted By | For | Type | Date | |
| N4 TF Has Bar Coding ? - Forex Trading | This thread | Refback | 02-23-2008 09:19 PM | |
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Coding help please | mj_bolt | Indicators - Metatrader 4 | 2 | 05-07-2007 10:39 AM |
| A Little help coding please??? | Aaragorn | Expert Advisors - Metatrader 4 | 1 | 10-28-2006 07:01 PM |
| Coding Help | jerrymar | Indicators - Metatrader 4 | 1 | 03-23-2006 09:20 AM |
| Need help coding | jdsim1 | Suggestions for Trading Systems | 4 | 03-19-2006 10:40 PM |