Articles by: David Williams

Any kid can chatter, few can inform

Man, I’ve got a lot of respect for people who can speak more than one language.

I wasn’t exactly an overachiever in high school, and since I didn’t have to study a foreign language, I didn’t.

Also, and due in part because I was a goof-off in high school, I didn’t start college until I was older.

Now listen to this.  The university I went to in New York required  engineering students to take two semesters of a foreign language.  I remember thinking “uh-oh“.

I decided to take Spanish because I heard it was easy.  Now who takes Spanish in college?  Kids – smart kids – who studied Spanish in high school.

So here I was, the big older dummy in an introductory Spanish class, asking the professor over and over again to repeat a sentence during an oral exam.  The rest of the students understood the first time.  I must have asked about 8 times.  Not the highlight of my academic career.

But I did learn that I’m not good at some things.  Hey, maybe I needed to be immersed in the language or maybe I needed to learn it at an earlier age.  But at the end of the day, the truth is,  I’m just not good at learning a foreign language.

So, why am I talking to you about this?  Well, just like I’m not good at certain things, computers are not good at certain things either.

I bring this up because I don’t want you to be disappointed or frustrated at a later time.  When I talk about computers, I’m including MQL and MetaTrader, and yes, even VTS.

Computers are not good at qualitative decisions. When you say something natural like “open a Buy position when the ADX is rising”, a computer will have trouble with that.  In this case, your computer needs an exact definition of what “rising” means.

Sure, you know what “rising” means just by looking at a chart. But your brain is actually filtering out a lot of noise and making some assumptions.

For example, suppose the price is rising except for a few declines here and there.  Or suppose a few candles are missing.  A computer gets stuck on this kind of stuff.

When you sit down and design your Expert Advisor, one of the first steps is to describe how the trading system works.

If your description includes words like “rising”, “falling”, “strong”,  “weak”, try to write an exact definition of what these terms mean.  It will save a lot of time in the long run.

NOTE:  The subject line of this email is from a song named “It’s Hard” by the rock band The Who:

Any gang can scatter, few can form.  

Any kid can chatter, few can inform. 

It’s hard. It’s very, very, very, very hard.

A Bar is Born: The MQL Shift

A Bar is Born: The MQL Shift

I’m asked a lot of questions about the MQL shift parameter.

If you’re not sure about the shift parameter, don’t worry, you’ve got lots of company.  Plus, I’ve got a great way to explain it.

But let’s back up first.  Every bar (or candle) on a MetaTrader price chart has a number.

Get this – the bars are numbered from right to left!  Yup, that’s right.  Backwards for us Arabic-based-language readers.

But this does make sense.  The bar on the right-most side of the chart, the one  that is being drawn, is always bar number 0  (we’ll call it bar#0 for short).

Remember, it takes some time for a bar to be drawn.  How long?

Depends on the price chart.  1 minute on a 1-minute chart, 15 minutes on a 15-minute chart, and so on.  I’m sure you get it.

Also, recall that a bar (or candle) has 4 price values: open, high, low and close. The bar isn’t complete until the close value is known, and that happens at the very end of the period.

So, when bar#0 is finished, 3 things happen:

  1. It moves one spot to the left
  2. Its number is incremented (it becomes bar#1)
  3. A new bar#0 is born!

This is happening all the time (when the market is open).  A new bar is added at the end of each time period and the rest of the bar numbers are incremented by one.

What does this have to do with the shift parameter?  Well, what I call the bar number, basically is the shift.

For example, the MQL function iOpen gives you the value of the open price of any bar.  The iOpen function has a shift parameter:

  • If the shift parameter is 0, you get the open value of  the     current, right-most  bar
  • If the shift parameter is 1, you get the open value of  the bar to the left of the current bar
  • If the shift parameter is 2, you get the open value of  the bar       that is 2 bars to the left of the current bar
  • and so on and so on …

And this same shift parameter is used in every MetaTrader  Indicator, including custom indicators.

It has the same meaning: shift = 0 calculates the indicator value for the current bar, shift = 1 calculates the indicator value for the bar to the right, etc. etc.

I’ve written a simple Expert Advisor that draws the number of each bar on a price chart. It really helps to see this concept in action.

I’ve posted the plain MQL code, so you don’t need VTS or anything to load the EA.  Also you are welcome to edit the code if you like.

Click or copy and paste this link into your browser to get to the BarLabel Expert Advisor:

http://www.iexpertadvisor.com/forum/messages.aspx?TopicID=222&MessageID=655#post655 

FREE MQL COURSE:  If your interested in learning more about MQL, I’ve put together a free email MQL programming course. You can sign up here: http://www.iexpertadvisor.com/free-metatrader4-mql-course.html

VTS UPDATE: I’ve added this entry-screen to VTS for every Shift parameter.  To see it, use the pull-down menu next to the Shift parameter on any Indicator configuration screen, scroll up and select the “choose” menu item.

MQL Shift Entry Screen