Thema: VIX Indikator
Einzelnen Beitrag anzeigen
  #1 (permalink)  
Alt 28.07.20
Anja Anja ist offline
Neues Mitglied
 
Registriert seit: Jul 2020
Beiträge: 27
Anja befindet sich auf einem aufstrebenden Ast
Standard VIX Indikator

Ich habe einen interessanten Indikator gefunden und versucht den auf MQL4 umzuschreiben: https://www.mql5.com/de/code/20906

Erstens würde mich interessieren, ob ich das richtig gemacht habe und zweitens, weshalb ich beim iCustom() Aufruf fast nur EMPTY_VALUE zurück bekomme.

Leider verstehe ich den Anfang der OnCalculate() bisher nicht: wie hängt die Berechnung mit dem was man sieht zusammen? Denn die Anzeige ist wunderbar in Ordnung und ich finde es nicht tragisch, statt einer Farbe eine zweite Linie zu haben, da ich ja sowieso die Richtung auswerten möchte.

Code:
double vix = iCustom(NULL,0,"VIX",20,0,1);
double vixDirection = iCustom(NULL,0,"VIX",20,1,1);
Code:
//+------------------------------------------------------------------
#property copyright   "mladen"
#property link        "mladenfx@gmail.com"
#property description "Synthetic VIX"
#property strict
//+------------------------------------------------------------------
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_label1  "Synthetic VIX"
#property indicator_type1   DRAW_LINE
#property indicator_color1 clrYellow 
#property indicator_width1  2
#property indicator_label2  "Color VIX"
#property indicator_type2   DRAW_LINE
#property indicator_color2  clrDarkGray
#property indicator_width2  1
//--- input parameters
input int inpVixPeriod = 20; // Synthetic VIX period
//--- buffers and global variables declarations
double val[],valc[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   IndicatorBuffers(2);
//--- indicator buffers mapping
   SetIndexBuffer(0,val); 
   SetIndexBuffer(1,valc); 
//--- indicator short name assignement
   IndicatorSetString(INDICATOR_SHORTNAME,"Synthetic VIX ("+(string)inpVixPeriod+")");
   
   return (INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator de-initialization function                      |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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[])
  {
   if(Bars(_Symbol,_Period)<rates_total) return(prev_calculated);
   int i=(int)MathMax(prev_calculated-1,0); for(; i<rates_total && !_StopFlag; i++)
     {
      int    _start   = MathMax(i-inpVixPeriod+1,0);
      double _highest = high[ArrayMaximum(high,_start,inpVixPeriod)];
      val[i]  = 100.0*(_highest-low[i])/_highest;
      valc[i] = (i>0) ?(val[i]>val[i-1]) ? 1 :(val[i]<val[i-1]) ? 2 : valc[i-1]: 0;
     }
   return (i);
  }