Get Indicator Value from Other TF

 

Hi,

First I apologize if my question was ever asked in this forum and I would be very grateful if you can point me to the answer.

OK, here is the question:

How can I get the indicator value from other timeframe?

What I want is: no matter which TF I'm in (either M15, M30, H1 or other), I want the EA to take the indicator value from (for e.g.) TF M5.

I have tried this:

double TheMain = iADX(NULL, 5, 15, PRICE_CLOSE, 0, 0);

but TheMain Value is always 0 if I'm not in TF5.

Is there any step I should do to get the value?

Thanks in advance for the help. 

 
t4nu:

Hi,

First I apologize if my question was ever asked in this forum and I would be very grateful if you can point me to the answer.

OK, here is the question:

How can I get the indicator value from other timeframe?

What I want is: no matter which TF I'm in (either M15, M30, H1 or other), I want the EA to take the indicator value from (for e.g.) TF M5.

I have tried this:

double TheMain = iADX(NULL, 5, 15, PRICE_CLOSE, 0, 0);

but TheMain Value is always 0 if I'm not in TF5.

Is there any step I should do to get the value?

Thanks in advance for the help. 


double iADX( string symbol, int timeframe, int period, int applied_price, int mode, int shift)
In your code you seem to have forgotten to include the variable for periods. For more help goto MQL4 Reference->Technical Indicators ->iADX
 
Lema_Carl:

double iADX( string symbol, int timeframe, int period, int applied_price, int mode, int shift)
In your code you seem to have forgotten to include the variable for periods. For more help goto MQL4 Reference->Technical Indicators ->iADX

iADX 

 That's not the problem  his period 15
 
deVries:

iADX 

 That's not the problem  his period 15
15 is the correct time frame enumeration value for the chart he wants. The only other problem  I can think of is if his history data is not sufficient for the time frame he wants.
 
t4nu:

Hi,

First I apologize if my question was ever asked in this forum and I would be very grateful if you can point me to the answer.

OK, here is the question:

How can I get the indicator value from other timeframe?

What I want is: no matter which TF I'm in (either M15, M30, H1 or other), I want the EA to take the indicator value from (for e.g.) TF M5.

I have tried this:

double TheMain = iADX(NULL, 5, 15, PRICE_CLOSE, 0, 0);

but TheMain Value is always 0 if I'm not in TF5.

Is there any step I should do to get the value?

Thanks in advance for the help. 


Use Print,  Comment,

//+------------------------------------------------------------------+
//|                                              ADXPeriodTESTER.mq4 |
//|                                          Copyright 2013, deVries |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright 2013, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"


//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   Comment("");
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
//----
   double TheMain5 = iADX(NULL, PERIOD_M5, 15, PRICE_CLOSE, 0, 0);
   double TheMain15 = iADX(NULL, PERIOD_M15, 15, PRICE_CLOSE, 0, 0);
   double TheMain30 = iADX(NULL, PERIOD_M30, 15, PRICE_CLOSE, 0, 0);
   
   Comment("M 5  ",TheMain5,"\n","M 15  ",TheMain15,"\n","M 30  ",TheMain30);
//----
   return(0);
  }
//+------------------------------------------------------------------+

 

 Test out if it is working  

 
deVries:


Use Print,  Comment,

 

 Test out if it is working  

Thanks for the respond. I try it in Strategy Tester, and the result:

if I set the period to 15, TheMain15 gives value the others 0.

If I set the period to 5, TheMain5 gives value, the others 0

If period set to 30, TheMain30 gives value, the others 0

 
t4nu:

Thanks for the respond. I try it in Strategy Tester, and the result:

if I set the period to 15, TheMain15 gives value the others 0.

If I set the period to 5, TheMain5 gives value, the others 0

If period set to 30, TheMain30 gives value, the others 0

 

Show your code please.
 
RaptorUK:
Show your code please.

 

OK, here is my code:

#define _UP        1

#define _DOWN     -1
#define _NO_CROSS  0

//--- input parameters
extern int    TFMonitored=5;
extern int       ADXPeriod=15;

double dx_main;
double dx_plus_now;
double dx_plus_before;
double dx_minus_now;
double dx_minus_before;

int CrossCheck()
{

   string cSymbol = Symbol();
   int nBackVal = _NO_CROSS;
   
   dx_main         = iADX(cSymbol, TFMonitored, ADXPeriod, PRICE_CLOSE, MODE_MAIN, 0);   
   dx_plus_now     = iADX(cSymbol, TFMonitored, ADXPeriod, PRICE_CLOSE, MODE_PLUSDI,  0);
   dx_minus_now    = iADX(cSymbol, TFMonitored, ADXPeriod, PRICE_CLOSE, MODE_MINUSDI, 0);
   dx_plus_before  = iADX(cSymbol, TFMonitored, ADXPeriod, PRICE_CLOSE, MODE_PLUSDI,  1);
   dx_minus_before = iADX(cSymbol, TFMonitored, ADXPeriod, PRICE_CLOSE, MODE_MINUSDI, 1);
   
   if ((dx_plus_before < dx_minus_before) && (dx_plus_now > dx_minus_now))
      nBackVal = _UP;
   else if ((dx_plus_before > dx_minus_before) && (dx_plus_now < dx_minus_now))
      nBackVal = _DOWN;
      
   return (nBackVal);   

}

int init()
{
    
    return(0);

}
  
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
   string cInfo;
   int nCross = CrossCheck();
   
   if (nCross == _UP)
        {
           cInfo = "Cross Up";
        }
      else if (nCross == _DOWN)
        {
           cInfo = "Cross Down";
        }
      else
        {
           if (dx_plus_now > dx_minus_now)
           {
              cInfo = "Trend UP";
           }
           else if (dx_plus_now < dx_minus_now)
           {
              cInfo = "Trend DOWN";
           }

           if (dx_main > 20)
              {
                 if (dx_main > 40)
                   cInfo = cInfo + " - Extrem";
                 else
                   cInfo = cInfo + " - Strong";
              }
              else
                cInfo = cInfo + " - Weak";

        }


//----
    Comment("Symbol: ", Symbol(),
            "\nCurrent Date: ", TimeToStr(TimeCurrent(), TIME_DATE),
            "\nCurrent Time: ", TimeToStr(TimeCurrent(), TIME_MINUTES), 
            "\nTF Monitored: ", TFMonitored,
            "\nMain: ", dx_main,
            "\nPlus DI(0, 1): ", dx_plus_now, ", ", dx_plus_before,
            "\nMinus DI(0, 1): ", dx_minus_now, ", ", dx_minus_before,
            "\nCross Signal: ", cInfo);

//----
   return(0);
  }

 

 

 

And the 3 values change while the test is running 

 
Lema_Carl:
15 is the correct time frame enumeration value for the chart he wants. The only other problem  I can think of is if his history data is not sufficient for the time frame he wants.

I think you're right, after download in the history center, now my code can run as expected. Thanks a lot.
 
deVries:

 

 

And the 3 values change while the test is running 


Yes, it seems the problem is the history data,after download it, now my code can run as expected. 

Thanks for the help.