Education

What is the MetaTrader SHIFT parameter?

What is the MetaTrader SHIFT parameter?

The SHIFT parameter is used to identify a candle (or bar) on a MetaTrader price chart.

  • The currently forming candle has a shift value of  0.
  • The last fully formed candle has a shift value of 1.
  • The candle formed before that one has a shift value of 2, and so and so on

So when you look at a  MetaTrader price chart, the candle-shift-values read from 0 to N, from right to left. Where the candle with a shift of 0 (zero) is the candle at the far right edge of the chart.

This concept of a candle being identified by its shift-value runs deep in the MQL language.

Any of the 4 price values  (High, Low, Open, Close) can be obtained using a shift value as an index to the built-in price series that are available in MQL.

For example:

  • High[0] : This is the high value of the currently forming candle.
  • Close[1]: This is the close value of the last fully formed candle.
  • Open[5]: This is the open price from 5 candles ago

The price series arrays only offer  the price of a candle on the current chart (defined by its Symbol and Time-frame).  MQL also offers functions to get the price value for a candle from any chart.  These functions are named iHigh, iLow, iOpen and iClose.

The parameters for these functions are the symbol, timeframe and yes, of course, the shift:

double iHigh( string symbol, int timeframe, int shift)

This will get you the high value of the last fully formed candle on a EURUSD 1 minute chart:

iHigh( “EURUSD”, PERIOD_H1, 1)

We’re almost done. Finally, every technical indicator provides a shift value as well, for the same reason.

For example, here is the RSI function:

double iRSI( string symbol, int timeframe, int period, int applied_price, int shift)

To get the RSI value for the last candle, set the shift parameter to 1.

In the VTS-MetaTrader EA builder, every shift parameter offers a visual selection menu. To find it, just scroll up in the parameter pull-down menu and select the first item “choose…“.

IMPORTANT note about shift of zero!

When you use a shift of zero,  understand that the value can change on each incoming change in price (tick).

For example, for a candle, the only value that will not change for a shift of zero is the open price.  The high and low values may change on each tick; and the close value does change on each tick.

Since nearly all indicators use the basic price values for their calculations, you can count on an indicator value changing on each tick if its shift parameter is zero.

WARNING: If you have logic that tests if an indicator value is greater or less than some value, and the shift is 0, the logic may be true for exactly 1 tick and then become false again.  Generally, it is safer to use a shift of 1 to avoid this “bouncing”, but it can inject a delay in your EA.  Look into the “Power Tab” on the Logic element to address these advanced situations.

Here is a forum post with more info:

MQL Shift Parameter

 

Fail-Forward Forex

Failing Forward on the Forex Market

25 years ago I failed college algebra.

Actually, I got a D. This is not technically failing, but since you needed a C average to get into the engineering school, it was not good news.

Now getting a D in college algebra might not be the end of the world for an art student, or a business major, or even pre-law, but for an engineering candidate it was devastating.

You see, the list of “required courses” for an engineering degree did not even include college algebra.  You know why?  Because it’s so basic, so trivial, they assumed you already knew algebra if you were even considering engineering as a major!

Seriously, it’s not even a pre-requisite.  It’s a pre-pre-requisite.  (I’m not making this up. Pre-calculus is a pre-requisite, and college algebra is the pre-requisite for pre-calculus!)

So, needless to say, I was depressed.  But I didn’t give up.  I’m not even sure why I didn’t give up – stubbornness – or maybe just refusing to fail.

When I look back on that experience, it reminds me of a saying I came across just the other day:

“Failure is not the opposite of success,  it is a step towards success.”

In this case, it’s true.  I learned from that failure. Among other things, I learned to never take a math course early in the morning again.  Ever.

I’m serious.  8:00 AM is just way too early for my brain to be solving equations.

Anyway, I really like that saying.  And I think it applies perfectly to Forex trading.

Let me tell you right now: If you are not ready to fail, then Forex trading is not for you.  Don’t even try it.

You and I (and every other trader) are looking for the same thing. To build that ultimate trading system that never loses and just wins, wins, wins.  The so-called “Holy Grail” of trading.

But if you think it’s just gonna happen without coming up with some seemingly great ideas, falling in love with those same ideas and then systematically destroying them, well, you are dead wrong.

And let me tell you, destroying those ideas hurts.

It really does.  Because you think your idea is so clever and it makes so much sense and it’s based on rock-solid logic.

Then you implement it and it fails horribly. Ouch.

But where would you rather be?  Still dreaming about an idea that’s bound to fail?  Or would you like to have failed-forward and be working on your next idea?

Whatever tools you use to build your Expert Advisor, make sure you can move quickly from your idea to implementation.

As sadistic as it sounds, the faster you can crush your ideas, the faster you’ll move toward success.

NOTE: I should clarify, I don’t believe there is such a thing as a “Holy Grail” trading system and I don’t really search for one, but I do continually try to improve my systems to make them as good as they can be.  And yeah, the holy grail system is fun to dream about.