What is Shift Parameter?

User avatar
remix919
Trader
Posts: 91
Joined: Wed Jan 23, 2013 2:42 am
Location: Some Road in the USA

What is Shift Parameter?

Post by remix919 »

Hey all, still fairly new to MQL4 and was wondering what exactly does the shift parameter do? For my example, I'm looking at the iAC() and MQL4 docs say "Index of the value taken from the indicator buffer (shift relative to the current bar the given amount of periods ago)." Not quite understanding what that means O.o
EA's are the best way to trade. Why? Because they take the emotion out of trading.
User avatar
fxdaytrader
Trader
Posts: 190
Joined: Sun Jun 10, 2012 7:03 am
Location: Poon-Town (germany, se-asia, se-europe) ...

Re: What is Shift Parameter?

Post by fxdaytrader »

shift = 0: look at the current bar
shift = 1: the bar before
and so on ...
User avatar
remix919
Trader
Posts: 91
Joined: Wed Jan 23, 2013 2:42 am
Location: Some Road in the USA

Re: What is Shift Parameter?

Post by remix919 »

O, ok, is there anyway to simulate the shift in Empty4's indicators on the chart? For example on the AC indicator, in the indi options there's no way to shift?
EA's are the best way to trade. Why? Because they take the emotion out of trading.
garyfritz

Re: What is Shift Parameter?

Post by garyfritz »

The indi has to be written to include the shift in its calculations. If it isn't, you can't shift it.
User avatar
remix919
Trader
Posts: 91
Joined: Wed Jan 23, 2013 2:42 am
Location: Some Road in the USA

Re: What is Shift Parameter?

Post by remix919 »

Is it easy to add or involves a lot of work? Like if I wanted to add it to the default AC indi that Empty4 comes with?
EA's are the best way to trade. Why? Because they take the emotion out of trading.
garyfritz

Re: What is Shift Parameter?

Post by garyfritz »

It's very easy. Just add your shift to the iAC() shift parameter.

So let's say you're calling iAC() on each bar, to display the indi value for each bar:

Code: Select all

for (bar = limit-1; bar >= 0; bar--) {
  ACbuffer[bar] = iAC(null, 0, bar);
}
The "bar" shift in the iAC() call means "give me the iAC value for that bar."

To add your own shift, you literally just add it on: iAC(null, 0, bar+myShift);

So if myShift = 5, then when you're on bar 0 (the current, most recent bar), you'll calculate the value of iAC() on bar 5.

Be careful about specifying values of bar+myShift that fall outside the bounds of the array -- i.e. < 0 or > Bars.
User avatar
remix919
Trader
Posts: 91
Joined: Wed Jan 23, 2013 2:42 am
Location: Some Road in the USA

Re: What is Shift Parameter?

Post by remix919 »

Umm...a little bit confused, is that for adding the shift to an EA's indicator? I was like trying to have say for example, 2 AC's on my chart, 1 with a 0 shift, 1 with a 1 shift so I can see the difference between the two, is that possible?
EA's are the best way to trade. Why? Because they take the emotion out of trading.
garyfritz

Re: What is Shift Parameter?

Post by garyfritz »

See where I assigned the iAC value into ACbuffer[] ? I intended that to be an indicator buffer, so you would display the (unshifted) AC value on the chart.

Now if you want two ACs, just add another display buffer with a shift:

ACbuffer[bar] = iAC(null, 0, bar);
ACbufferShift[bar] = iAC(null, 0, bar+myShift);

If myShift is 1, then on bar 0 you will display the AC values for bars 0 and 1. On bar 1 you'll display the values for bars 1 and 2, etc.
User avatar
remix919
Trader
Posts: 91
Joined: Wed Jan 23, 2013 2:42 am
Location: Some Road in the USA

Re: What is Shift Parameter?

Post by remix919 »

Do I do that for the indicator or EA file? I had tried that in the EA file and while it works, but when I run the EA in visual mode, only 1 AC indi window shows up?
EA's are the best way to trade. Why? Because they take the emotion out of trading.
garyfritz

Re: What is Shift Parameter?

Post by garyfritz »

remix919 wrote:Do I do that for the indicator or EA file?
That depends on if you want an indicator or an EA!! If you want to display lines on a chart, put it in an indicator. If you want to calculate values of AC and make trading decisions with them, put it in an EA. Unfortunately with Empty4, EA code and indicator code is not really compatible. The execution models are different.
Post Reply

Return to “Coders Hangout”