Need help to understand one line in the highest rated EA

 
   for(int i = 0 ; i < MACDLevel ; i ++)
     {
       if(iMACD(Symbol(), MathPow( 2, i) , 2, 4, 1, PRICE_CLOSE, MODE_MAIN, 0) < 
          iMACD(Symbol(), MathPow( 2, i), 2, 4, 1, PRICE_CLOSE, MODE_MAIN, 1) )
         {
           SellIndex += iMACD(Symbol(), MathPow( 2, i), 2, 4, 1, PRICE_CLOSE, MODE_MAIN, 0);
         }
       if(iMACD(Symbol(), MathPow( 2, i), 2, 4, 1, PRICE_CLOSE, MODE_MAIN, 0) > 
          iMACD(Symbol(), MathPow( 2, i), 2, 4, 1, PRICE_CLOSE, MODE_MAIN, 1) )
         {
           BuyIndex += iMACD(Symbol(), MathPow( 2, i), 2, 4, 1, PRICE_CLOSE, MODE_MAIN, 0);
         }
 
     }

I am reading the code from the highest rated EA https://www.mql5.com/en/code/8553.

I need help for the above lines that is in the block of AskMACD()
My question is here:

How can MathPow(2,i) be used to choose a timeframe? I am having a hard time to understand it. Need your help. Thanks

 

Before posting please read some of the other threads . . . then you would have seen numerous requests like this one:

Please use this to post code . . . it makes it easier to read.

 

asking your question you know this

Timeframe of the chart (chart period). It can be any of the following values:

Constant Value Description
PERIOD_M1 1 1 minute.
PERIOD_M5 5 5 minutes.
PERIOD_M15 15 15 minutes.
PERIOD_M30 30 30 minutes.
PERIOD_H1 60 1 hour.
PERIOD_H4 240 4 hour.
PERIOD_D1 1440 Daily.
PERIOD_W1 10080 Weekly.
PERIOD_MN1 43200 Monthly.
0 (zero) 0 Timeframe used on the chart.


We also know MathPow( 2, 0) =1,
MathPow( 2, 1) =2
MathPow( 2, 2) =4
So values like 1,2,4,8,16,32,.....


Maybe you found an error .....
Trie out what it does in iMACD

So make a program and print out the values iMACD with mathpow(2,i) as timeframe, and look to the outcome

Do it also with the normally timeframeperiods and compare them

 
deVries:

asking your question you know this

Timeframe of the chart (chart period). It can be any of the following values:

Constant Value Description
PERIOD_M1 1 1 minute.
PERIOD_M5 5 5 minutes.
PERIOD_M15 15 15 minutes.
PERIOD_M30 30 30 minutes.
PERIOD_H1 60 1 hour.
PERIOD_H4 240 4 hour.
PERIOD_D1 1440 Daily.
PERIOD_W1 10080 Weekly.
PERIOD_MN1 43200 Monthly.
0 (zero) 0 Timeframe used on the chart.


We also know MathPow( 2, 0) =1,
MathPow( 2, 1) =2
MathPow( 2, 2) =4
So values like 1,2,4,8,16,32,.....


Maybe you found an error .....
Trie out what it does in iMACD

So make a program and print out the values iMACD with mathpow(2,i) as timeframe, and look to the outcome

Do it also with the normally timeframeperiods and compare them


I got 0 using the Mathpow(2,i) when i!=0, which means iMACD does not work.
 
lostbridge:

I got 0 using the Mathpow(2,i) when i!=0, which means iMACD does not work.


I really think the author of the code did that on purpose.
 

Hi lostbridge,

You're really lost this time ;D.

It's called code obfuscation. The purpose for code obfuscation is to confuse, even to mislead it's reader so that the code is hard to understand. That MACD will only return value when MathPow(2,0) value is 1 which is period M1.

Click here - https://en.wikipedia.org/wiki/Obfuscated_code

:D

 
onewithzachy:

Hi lostbridge,

You're really lost this time ;D.

It's called code obfuscation. The purpose for code obfuscation is to confuse, even to mislead it's reader so that the code is hard to understand. That MACD will only return value when MathPow(2,0) value is 1 which is period M1.

Click here - https://en.wikipedia.org/wiki/Obfuscated_code

:D


That is the point. Thanks
Reason: