Indicator ADX in another timeframe

 

Good morning,

There is an error that I don't understand. Maybe I'm doing it wrong.

I would like to have an indicator that returns me ADX values in a larger unit of time.

 input int    PeriodADX= 14 ;
input int    ADXTrendLevel= 22 ;
input ENUM_TIMEFRAMES HTF = PERIOD_H1 ;
//---------------------------------------------------------------------
double       TrendBuffer[];
//---------------------------------------------------------------------
int          indicator_handle= 0 ;
int          indicator_Tempo= 0 ;
//---------------------------------------------------------------------
//      Initialization event handler:
//---------------------------------------------------------------------
int OnInit ()
  {
//      Displayed indicator buffer:
   SetIndexBuffer ( 0 ,TrendBuffer, INDICATOR_DATA );
   PlotIndexSetInteger ( 0 , PLOT_DRAW_BEGIN ,PeriodADX* 2 );
   PlotIndexSetString ( 0 , PLOT_LABEL , "ADXTrendDetector( " +( string )PeriodADX+ " )" );

//      Create external indicator handle for future reference to it:
   ResetLastError ();
   indicator_handle= iCustom ( Symbol (), PERIOD_CURRENT , "Examples\\ADX" ,PeriodADX);
   if (indicator_handle== INVALID_HANDLE )
     {
       Print ( "ADX initialization error, Code = " , GetLastError ());
       return (- 1 );   // return nonzero code - initialization was unsuccessful
     }
   indicator_Tempo= iADX ( Symbol (),HTF,PeriodADX);
   if (indicator_Tempo== INVALID_HANDLE )
     {
       Print ( "ADX initialization error, Code = " , GetLastError ());
       return (- 1 );   // return nonzero code - initialization was unsuccessful
     }
   return ( 0 );
  }

when I want to use indicatorTempo, it returns 0...

int TrendDetector(int _shift)
  {
   int      trend_direction=0;
   double   ADXBuffer[1];
   double   PlusDIBuffer[1];
   double   MinusDIBuffer[1];

//	Copy ADX indicator values to buffers:
/*
   CopyBuffer(indicator_handle,0,_shift,1,ADXBuffer);
   CopyBuffer(indicator_handle,1,_shift,1,PlusDIBuffer);
   CopyBuffer(indicator_handle,2,_shift,1,MinusDIBuffer);
*/   
   datetime timeArray[];
   CopyTime(_Symbol,PERIOD_CURRENT,_shift,1,timeArray);
   int maPosition = iBarShift(_Symbol,HTF,timeArray[0],false);
   
   // je récupere la date et heure -> variable maPosition : Ok
   // je veux ensuite récuperer l'état de l'indicateur à la période HTF pour la date donnée ? 
   CopyBuffer(indicator_Tempo,0,maPosition,1,ADXBuffer);
   CopyBuffer(indicator_Tempo,1,maPosition,1,PlusDIBuffer);
   CopyBuffer(indicator_Tempo,2,maPosition,1,MinusDIBuffer);   
   
//	If ADX value is considered (trend strength):
   if(ADXTrendLevel>0)
     {
      if(ADXBuffer[0]<ADXTrendLevel)
        {
         return(trend_direction);
        }
     }

//	Check +DI and -DI positions relative to each other:
   if(PlusDIBuffer[0]>MinusDIBuffer[0])
     {
      trend_direction=1;
     }
   else if(PlusDIBuffer[0]<MinusDIBuffer[0])
     {
      trend_direction=-1;
     }

   return(trend_direction);
  }

Here ADXBuffer[0] = 0 ...

I don't understand my mistake... Can you help me?

Thanks in advance.

Files:
 
William Roeder #:
  1. Please post only in English on this part of the forums. Use the automatic translation tool if needed. Use simple language structure when using mechanical translation. (2013)

    Or use the Français forum.


  2. Where is the rest of your function?
         How To Ask Questions The Smart Way. (2004)
              Be precise and informative about your problem

    Always post all relevant code (using Code button) or attach the source file.

Sorry, 

I update, in the main topic.

Regards.