Forex
Google
New signals service!

Go Back   Forex Trading > Discussion Areas > Metatrader 4


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

Reply
 
LinkBack (1) Thread Tools Display Modes
  1 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old 08-08-2007, 04:57 AM
mikeschra's Avatar
Junior Member
 
Join Date: Jan 2007
Posts: 9
mikeschra is on a distinguished road
N4 TF Has Bar Coding ?

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.
Attached Files
File Type: mq4 N4 TF HAS Bar.mq4 (8.7 KB, 66 views)
File Type: mq4 Heiken_Ashi_Smoothed.mq4 (4.2 KB, 32 views)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 08-14-2007, 10:50 PM
mikeschra's Avatar
Junior Member
 
Join Date: Jan 2007
Posts: 9
mikeschra is on a distinguished road
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 08-15-2007, 01:02 AM
ralph.ronnquist's Avatar
Senior Member
 
Join Date: Oct 2006
Posts: 280
ralph.ronnquist is on a distinguished road
Quote:
Originally Posted by mikeschra View 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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 08-15-2007, 01:13 AM
mikeschra's Avatar
Junior Member
 
Join Date: Jan 2007
Posts: 9
mikeschra is on a distinguished road
Yep, Thats right....but as i mentioned at the end of my last post i have not concluded the hole post yet. Have wife issues at the moment!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 08-15-2007, 01:21 AM
mikeschra's Avatar
Junior Member
 
Join Date: Jan 2007
Posts: 9
mikeschra is on a distinguished road
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!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 08-15-2007, 09:49 AM
ralph.ronnquist's Avatar
Senior Member
 
Join Date: Oct 2006
Posts: 280
ralph.ronnquist is on a distinguished road
Quote:
Originally Posted by mikeschra View Post
Yep, Thats right....but as i mentioned at the end of my last post i have not concluded the hole post yet. Have wife issues at the moment!
Sorry about that. Am I too simple to recognize a rhetorical question?

Last edited by ralph.ronnquist; 08-15-2007 at 09:55 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 08-16-2007, 01:03 AM
mikeschra's Avatar
Junior Member
 
Join Date: Jan 2007
Posts: 9
mikeschra is on a distinguished road
LOL....Not a problem, just hope I have the time to finish my example tonight.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 08-16-2007, 02:25 AM
mikeschra's Avatar
Junior Member
 
Join Date: Jan 2007
Posts: 9
mikeschra is on a distinguished road
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!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 10-23-2007, 04:12 AM
mikeschra's Avatar
Junior Member
 
Join Date: Jan 2007
Posts: 9
mikeschra is on a distinguished road
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 11-10-2007, 08:50 AM
Senior Member
 
Join Date: Mar 2006
Location: La Verne,CA
Posts: 552
MrPip is on a distinguished road
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
Attached Files
File Type: mq4 N4 TF HAS Bar Example EAv2.mq4 (4.6 KB, 37 views)

Last edited by MrPip; 11-10-2007 at 08:55 AM. Reason: further details
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

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


All times are GMT. The time now is 04:53 AM.



Search Engine Friendly URLs by vBSEO 3.2.0 ©2008, Crawlability, Inc.