Download MetaTrader 5

Quick but curious

To add comments, please log in or register
xanderhinds
108
xanderhinds  

Hi I'm going through an old EA I found on a post from some years back, I've come to this and don't understand what logic is behind it.


extern string entrylogics="Entry Logics";

extern int timeframe=0;
extern int period=5;
extern int shift=2;                      // bar in the past to take in consideration for the signal

 

   if(iHighest(NULL,timeframe,MODE_HIGH,period,0)==shift)
   {
   if(reversesignals)sell=true;else buy=true;
   }
   if(iLowest(NULL,timeframe,MODE_LOW,period,0)==shift)
   {
   if(reversesignals)buy=true;else sell=true;
   }

  I don't understand why == shift is used.. as shift is 2 how can iLowest/Highest be 2 when the data for highest and lowest is always a double of considerably less value than 2..

 

It's probably me missing something but anyone who can explain this to me will be appreciated! 

Alain Verleyen
Moderator
35129
Alain Verleyen  
Check the documentation of iLowest/iHighest and what value is returned.
xanderhinds
108
xanderhinds  
Alain Verleyen:
Check the documentation of iLowest/iHighest and what value is returned.

ah so it is an integer, why then would it be set to 2?

Alain Verleyen
Moderator
35129
Alain Verleyen  
xanderhinds:

ah so it is an integer, why then would it be set to 2?

Why not ? :-)
xanderhinds
108
xanderhinds  
Alain Verleyen:
Why not ? :-)
Hahaha.. I feel that its the simplest gaps of knowledge that cause most bewilderment.
honest_knave
Moderator
2342
honest_knave  
xanderhinds:

how can iLowest/Highest be 2 when the data for highest and lowest is always a double of considerably less value than 2..

xanderhinds:

ah so it is an integer

It is indeed an integer. A very common misconception is that iHighest and iLowest return the highest and lowest values respectively. They don't. They return the bar index that contains the highest/lowest values.

If the highest value is 1.10045 and it occurred on the previous bar, iHighest returns 1 (not 1.10045)

whroeder1
17092
whroeder1  
xanderhinds: ah so it is an integer, why then would it be set to 2?
  1. Do you know what a fractal is? Two lower highs on the left (bars 3 and 4,) two lower highs on the right (bars 0 and 1,) highest high in the middle (bar 2.)
  2. Can't use iFractals because it won't ever indicate a fractal on bar 2, only bar 3 (fully formed bars.)
JC
1581
JC  
whroeder1:
  1. Do you know what a fractal is? Two lower highs on the left (bars 3 and 4,) two lower highs on the right (bars 0 and 1,) highest high in the middle (bar 2.)

Being very, very pedantic... the built-in MT4 definition is very slightly different. It allows one or more equal highs with two lower highs before and after. A valid fractal is therefore not necessarily a 5-bar sequence.

For example, there is a six-bar fractal sequence at 13:31/13:32 today on EURUSD M1 in the MetaQuotes demo server price feed; equal highs at 1.06689. Screenshot attached.

Files:
Alain Verleyen
Moderator
35129
Alain Verleyen  
JC:

Being very, very pedantic... the built-in MT4 definition is very slightly different. It allows one or more equal highs with two lower highs before and after. A valid fractal is therefore not necessarily a 5-bar sequence.

For example, there is a six-bar fractal sequence at 13:31/13:32 today on EURUSD M1 in the MetaQuotes demo server price feed; equal highs at 1.06689. Screenshot attached.

Anyway this topic is not about fractals.
xanderhinds
108
xanderhinds  
Thanks for all the responses. It helps a lot to understand that iHighest/lowest returns the bar index as opposed to the bar value, I'll do some reading into fractals to uncover more! Thanks again!
To add comments, please log in or register