Indikator Grundlagen - Seite 4

 
amando:

Das maximum und minimum kann ich aber nur über die #property einstellen oder?

in der OnInit kann ich diese soviel ich gesehen habe nicht indizieren

Drück doch Callis Zaubertaste dann wird dir geholfen.

A bisserl mehr Selbständigkeit wär gefragt!

Es geht.

   IndicatorSetInteger(INDICATOR_HEIGHT,100);

'Custom Indicators Properties' in der Reference

 

So einfach geht Indikator:

//+------------------------------------------------------------------+
//|                                                   CandleSize.mq5 |
//|                               Copyright © 2019, Ing. Otto Pauser |
//|                       https://www.mql5.com/de/users/kronenchakra |
//+------------------------------------------------------------------+
#property copyright   "Copyright © 2019, Ing. Otto Pauser"
#property link        "https://www.mql5.com/de/users/kronenchakra"
#property version     "1.00"
#property description "Candlesize in separate window"

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots   1

#include <Indis.mqh>

enum INDITYPE
  {
      LINE, // DRAW_LINE
      HIST, // DRAW_HISTO
      ARRO  // DRAW_ARROW
  };

input INDITYPE inp_IndiType = HIST;          // Select type of indicator
input color    inp_Color    = clrLimeGreen;  // Select color

double buffer[];

int OnInit()
{
   switch(inp_IndiType)
     {
      case LINE: Indi.InitLine (buffer,inp_Color); break;
      case HIST: Indi.InitHist (buffer,inp_Color); break;
      case ARRO: Indi.InitArrow(buffer,inp_Color); break;
     }

   return(INIT_SUCCEEDED);
}

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
{
   int      i,
            idxStart=(prev_calculated==0)?0:prev_calculated-1;
   double   size,
            f=1/_Point;

   for(i=idxStart; i<rates_total; i++)
      {
         size=(high[i]-low[i])*f;
         buffer[i]=size;
      }

   return(rates_total);
}


Drei verschiedene Darstellungsarten mit nur 65 Zeilen Code.

Die Indis.mqh wird benötigt.

Dateien:
Indis.mqh  11 kb
 

Noch ein Beispiel, das auch zeigen soll, daß es sinnvoll ist Bibliotheken wie 'Indis.mqh' auszulagern.

Gleiche Aufgabenstellungen wie gehabt, Kerzengrößen darzustellen, nur diesmal färbig und für EAs leicht auszulesen.

DRAW_COLOR_LINE und DRAW_COLOR_HISTOGRAM etc. sind zwar nett anzusehen, aber für EAs eher unbrauchbar (AO zB).

Viel geeigneter sind da 2 Buffer, auch nett anzusehen, obendrein leicht im EA zu interpretieren. Und der Code ist wirklich kompakt.

//+------------------------------------------------------------------+
//|                                                CandleSize_V2.mq5 |
//|                               Copyright © 2019, Ing. Otto Pauser |
//|                       https://www.mql5.com/de/users/kronenchakra |
//+------------------------------------------------------------------+
#property copyright   "Copyright © 2019, Ing. Otto Pauser"
#property link        "https://www.mql5.com/de/users/kronenchakra"
#property version     "2.00"
#property description "Candlesize with colors in separate window"

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_plots   2

#include <Indis.mqh>

input bool inp_Down = true; // Bearische Kerzen nach unten

double buUP[],buDN[];

int OnInit()
{
   Indi.InitHist(buUP,clrGreen);
   Indi.InitHist(buDN,clrRed);
   
   return(INIT_SUCCEEDED);
}

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
{
   int      i,
            idxStart=(prev_calculated==0)?0:prev_calculated-1;
   double   size,
            f=1/_Point;

   for(i=idxStart; i<rates_total; i++)
      {
         size=(high[i]-low[i])*f;
         if(open[i]<close[i])
            {
               buUP[i]=size;
               buDN[i]=NULL;
            }
         else
            {
               buUP[i]=NULL;
               if(inp_Down)
                     buDN[i]=-size;
               else
                     buDN[i]= size;
            }
      }

   return(rates_total);
}

Und so sieht es aus:


oder


Viel Erfolg beim Indi proggen.

Dateien:
Indis.mqh  11 kb
Grund der Beschwerde: