Probleme beim Anpassen eines ADX-Indikators

 

Hallo,

ich versuche grade eine Abwandlung vom ADX zu bauen. Dabei interessieren mich nur die Werte von D+ und D-. Um die Sichtbarkeit eines Signales zu verbessern soll, sobald eine der Werte höher ist als der andere und zusätzlich ein Grenzwert überschritten ist, ein Farbwechsel passieren.

Zwei ähnliche Indikatoren habe ich bereits (mit freundlicher Hilfe aus dem Forum) zum laufen gebracht. Hier scheine ich ein Problem mit dem ADXBuffer zu haben, ich verstehe aber noch nicht ganz welches.

//+------------------------------------------------------------------+
//|                                            ADX_Hist.mq5 |
//+------------------------------------------------------------------+

#property indicator_separate_window
#property indicator_buffers 4
#property indicator_plots   1
//+------------------------------------------------------------------+
input int                  InpMAPeriod       =           14;    // MA period
input ENUM_APPLIED_VOLUME  InpAppliedVolume  =  VOLUME_TICK;    // Volumes
input int                  inpHistWidth      =            4;    // Histogramwidth
input color                inpColor          =clrDodgerBlue;    // Color
input color                inpColorUP        =      clrLime;    // Color UP
input color                inpColorDN        =       clrRed;    // Color DN
input color                inpColorOD        =      clrGray;   
input double               Threshold         =           40;
//+------------------------------------------------------------------+
int      inpLineWidth = 1;
int      MAHandle;
double   ADXBuffer[];
double   DI_plusBuffer[];
double   DI_minusBuffer[];
double   ADXColors[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
{
   SetIndexBuffer(0,ADXBuffer,INDICATOR_DATA);                                                                           // indicator buffers mapping
   SetIndexBuffer(1,DI_plusBuffer,INDICATOR_CALCULATIONS);
   SetIndexBuffer(2,DI_minusBuffer,INDICATOR_CALCULATIONS);
   SetIndexBuffer(3,ADXColors,INDICATOR_COLOR_INDEX);

   PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,InpMAPeriod);                        // sets first bar from what index will be drawn
   PlotIndexSetInteger(0,PLOT_LINE_WIDTH,inpLineWidth);
   PlotIndexSetInteger(0,PLOT_DRAW_TYPE,DRAW_COLOR_HISTOGRAM);
   PlotIndexSetInteger(0,PLOT_LINE_WIDTH,inpHistWidth);
   PlotIndexSetInteger(0,PLOT_COLOR_INDEXES,3);
   PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,inpColorUP);
   PlotIndexSetInteger(0,PLOT_LINE_COLOR,1,inpColorDN);
   PlotIndexSetInteger(0,PLOT_LINE_COLOR,2,inpColorOD);


   IndicatorSetString(INDICATOR_SHORTNAME,"ADX Hist("+string(InpMAPeriod)+")");  // name for DataWindow and indicator subwindow label

   MAHandle=iADX(NULL,0,InpMAPeriod);
              // get MA handle
   if(MAHandle==INVALID_HANDLE)                                               // check MA handle
      {
         Alert("*ERROR* creating iMA handle");
         return(INIT_FAILED);
      }
   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Force Index                                                      |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const int begin,
                const double &price[])
{
   int i,start,to_copy;

   if(rates_total<InpMAPeriod)               // check for rates total
      return(0);                             // try again next tick

   if(BarsCalculated(MAHandle)<rates_total)  // check for MA ready
      return(0);                             // try again next tick
                                             // calculate amount of data needed
   to_copy=(prev_calculated==0)?rates_total:rates_total-prev_calculated+1;
   
//   if(CopyBuffer(MAHandle,0,0,to_copy,ADXBuffer)!=to_copy)   // get ma buffer
//      return(0);
   if(CopyBuffer(MAHandle,1,0,to_copy,DI_plusBuffer)!=to_copy)   // get ma buffer
      return(0);
   if(CopyBuffer(MAHandle,2,0,to_copy,DI_minusBuffer)!=to_copy)   // get ma buffer
      return(0);
                                             // preliminary calculations
   start=(prev_calculated<InpMAPeriod)?InpMAPeriod:prev_calculated-1;

   if(InpAppliedVolume==VOLUME_TICK)         // the main loop of calculations
      {
         for(i=start; i<rates_total && !IsStopped(); i++)
            {              
               if(DI_plusBuffer[i] > DI_minusBuffer[i]){
                  if(DI_plusBuffer[i] > Threshold){
                     ADXColors[i]=0;
                  }else{
                     ADXColors[i]=2;
                  }
                  ADXBuffer[i]=DI_plusBuffer[i];
                  Print("DI_plusBuffer["+i+"]*"+DI_plusBuffer[i]+"*");
               }else{
                  if(DI_minusBuffer[i] > Threshold){
                     ADXColors[i]=1;
                  }else{
                     ADXColors[i]=2;
                  }
                  ADXBuffer[i]=DI_minusBuffer[i];
                  Print("DI_minusBuffer["+i+"]*"+DI_minusBuffer[i]+"*");
               }
               Print("ADXBuffer["+i+"]*"+ADXBuffer[i]+"*");
            }
      }
   else
      {
         for(i=start; i<rates_total && !IsStopped(); i++)
            {
               if(DI_plusBuffer[i] > DI_minusBuffer[i]){
                  if(DI_plusBuffer[i] > Threshold){
                     ADXColors[i]=0;
                  }else{
                     ADXColors[i]=2;
                  }
                  ADXBuffer[i]=DI_plusBuffer[i];
                  Print("DI_plusBuffer["+i+"]*"+DI_plusBuffer[i]+"*");
               }else{
                  if(DI_minusBuffer[i] > Threshold){
                     ADXColors[i]=1;
                  }else{
                     ADXColors[i]=2;
                  }
                  ADXBuffer[i]=DI_minusBuffer[i];
                  Print("DI_minusBuffer["+i+"]*"+DI_minusBuffer[i]+"*");
               }
               Print("ADXBuffer["+i+"]*"+ADXBuffer[i]+"*");
            }
      }
   return(rates_total);
}

Im log kann ich sehen, dass der ADXBuffer die korrekten Werte erhält. Allerdings wird überhaupt nichts im Indikator selbst geplottet. 

Danke,
h4rry

 

Inzwischen funktioniert es

//+------------------------------------------------------------------+
//|                                            ADX_Hist.mq5 |
//+------------------------------------------------------------------+

#property indicator_separate_window
#property indicator_buffers 4
#property indicator_plots   2
//+------------------------------------------------------------------+
input int                  InpMAPeriod       =           14;    // MA period
input ENUM_APPLIED_VOLUME  InpAppliedVolume  =  VOLUME_TICK;    // Volumes
input int                  inpHistWidth      =            4;    // Histogramwidth
input color                inpColor          =clrDodgerBlue;    // Color
input color                inpColorUP        =      clrLime;    // Color UP
input color                inpColorDN        =       clrRed;    // Color DN
input color                inpColorOD        =      clrGray;   
input double               Threshold         =           40;
//+------------------------------------------------------------------+
int      inpLineWidth = 1;
int      MAHandle;
double   ADXBuffer[];
double   DI_plusBuffer[];
double   DI_minusBuffer[];
double   ADXColors[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
{
                                                                          // indicator buffers mapping
   SetIndexBuffer(0,ADXBuffer,INDICATOR_DATA); 
   SetIndexBuffer(1,ADXColors,INDICATOR_COLOR_INDEX);
   SetIndexBuffer(2,DI_plusBuffer,INDICATOR_CALCULATIONS);
   SetIndexBuffer(3,DI_minusBuffer,INDICATOR_CALCULATIONS);

   PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,InpMAPeriod);                        // sets first bar from what index will be drawn
   PlotIndexSetInteger(0,PLOT_LINE_WIDTH,inpLineWidth);
   PlotIndexSetInteger(0,PLOT_DRAW_TYPE,DRAW_COLOR_HISTOGRAM);
   PlotIndexSetInteger(0,PLOT_LINE_WIDTH,inpHistWidth);
   PlotIndexSetInteger(0,PLOT_COLOR_INDEXES,3);
   PlotIndexSetInteger(0,PLOT_LINE_COLOR,0,inpColorUP);
   PlotIndexSetInteger(0,PLOT_LINE_COLOR,1,inpColorDN);
   PlotIndexSetInteger(0,PLOT_LINE_COLOR,2,inpColorOD);


   IndicatorSetString(INDICATOR_SHORTNAME,"ADX Hist("+string(InpMAPeriod)+")");  // name for DataWindow and indicator subwindow label

   MAHandle=iADXWilder(NULL,0,InpMAPeriod);
              // get MA handle
   if(MAHandle==INVALID_HANDLE)                                               // check MA handle
      {
         Alert("*ERROR* creating iADXWilder handle");
         return(INIT_FAILED);
      }
   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Force Index                                                      |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const int begin,
                const double &price[])
{
   int i,start,to_copy;

   if(rates_total<InpMAPeriod)               // check for rates total
      return(0);                             // try again next tick

   if(BarsCalculated(MAHandle)<rates_total)  // check for MA ready
      return(0);                             // try again next tick
                                             // calculate amount of data needed
   to_copy=(prev_calculated==0)?rates_total:rates_total-prev_calculated+1;
   
   if(CopyBuffer(MAHandle,1,0,to_copy,DI_plusBuffer)!=to_copy)   // get ma buffer
      return(0);
   if(CopyBuffer(MAHandle,2,0,to_copy,DI_minusBuffer)!=to_copy)   // get ma buffer
      return(0);
                                             // preliminary calculations
   start=(prev_calculated<InpMAPeriod)?InpMAPeriod:prev_calculated-1;

   if(InpAppliedVolume==VOLUME_TICK)         // the main loop of calculations
      {
         for(i=start; i<rates_total && !IsStopped(); i++)
            {
               if(DI_plusBuffer[i] > DI_minusBuffer[i]){
                  ADXBuffer[i]=DI_plusBuffer[i];
                  if(ADXBuffer[i] > Threshold){
                     ADXColors[i]=0;
                  }else{
                     ADXColors[i]=2;
                  }
               }else{
                  ADXBuffer[i]=DI_minusBuffer[i];
                  if(ADXBuffer[i] > Threshold){
                     ADXColors[i]=1;
                  }else{
                     ADXColors[i]=2;
                  }
               }
            }
      }
   else
      {
         for(i=start; i<rates_total && !IsStopped(); i++)
            {
               if(DI_plusBuffer[i] > DI_minusBuffer[i]){
                  ADXBuffer[i]=DI_plusBuffer[i];
                  if(ADXBuffer[i] > Threshold){
                     ADXColors[i]=0;
                  }else{
                     ADXColors[i]=2;
                  }
               }else{
                  ADXBuffer[i]=DI_minusBuffer[i];
                  if(ADXBuffer[i] > Threshold){
                     ADXColors[i]=1;
                  }else{
                     ADXColors[i]=2;
                  }
               }           
            }
      }
   return(rates_total);
}
 
h4rry:

Inzwischen funktioniert es

Wollt ich mir gerade ansehen, bei mir zeigt er nix, keine linie

mir ist ja indicator prgrammierung auch so ein spanisches dorf 😂😂


edit, mann muss es nur auf das richtige chart legen, aber zeigt nur grau an, sollten da nicht farben sein?

Grund der Beschwerde: