Metatrader Forum | Forex Expert-Advisor | Broker & Forex Tools

Metatrader Forum | Forex Expert-Advisor | Broker & Forex Tools (http://www.expert-advisor.com/forum/index.php)
-   Codeschnipsel (http://www.expert-advisor.com/forum/forumdisplay.php?f=292)
-   -   Stochastik - Differenz %K-%D berechnen und anzeigen (http://www.expert-advisor.com/forum/showthread.php?t=5899)

Kronenchakra 22.10.17 04:05

Stochastik - Differenz %K-%D berechnen und anzeigen
 
Auf mql5.com wurde gefragt wie man die Differenz von %K und %D in der Stochastik berechnet.
Ich habe es in einem MiniEA geproggt und möchte es euch nicht vorenthalten.
Code:

//+------------------------------------------------------------------+
//|                                                    StochDiff.mq5 |
//|                                Copyright © 2017 Ing. Otto Pauser |
//|                                          http://www.spider4x.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2017 Ing. Otto Pauser"
#property link      "http://www.spider4x.com"
#property version  "1.00"

input    int            inp_Kperiod =  5;            // %K Periode
input    int            inp_Dperiod =  3;            // %D Periode
input    int            inp_slowing =  3;            // Verlangsamung
input    ENUM_MA_METHOD inp_method  = MODE_SMA;      // Methode
input    ENUM_STO_PRICE inp_pricef  = STO_LOWHIGH;    // Preisbereich

int      haStoch;    // handle für iStochastik
double  prozD[1],  // statischer buffer für %D
        prozK[1];  // statischer buffer für %K
double  delta;

int OnInit()
{
  haStoch=iStochastic(_Symbol,_Period,inp_Kperiod,inp_Dperiod,inp_slowing,inp_method,inp_pricef);      // handle iStochastik erstellen
  if(haStoch==INVALID_HANDLE)                                                                          // ErrCheck
      {
        MessageBox("*ERROR* creating handle iStochastic",MQLInfoString(MQL_PROGRAM_NAME),MB_ICONERROR); // Info
        return(INIT_FAILED);                                                                            // da ging was schief
      }
  return(INIT_SUCCEEDED);                                                                              // alles OK
}

void OnDeinit(const int reason)
{
  IndicatorRelease(haStoch);      // handle freigeben (nicht unbedingt erforderlich, sind aber gute Sitten)
}

void OnTick()
{
  if(CopyBuffer(haStoch,0,0,1,prozK)!=1) return;    // Werte aus Buffern holen
  if(CopyBuffer(haStoch,1,0,1,prozD)!=1) return;
  delta=prozK[0]-prozD[0];
  Comment("Stochastik Differenz %K-%D: ",DoubleToString(delta,2));
}

Grüße, Otto


Alle Zeitangaben in WEZ +2. Es ist jetzt 17:53 Uhr.

Powered by vBulletin® Version 3.8.5 (Deutsch)
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.6.1
Powered by vBCMS® 2.7.0 ©2002 - 2024 vbdesigns.de
Copyright ©2009 - 2023 by Expert-Advisor.com - Das Metatrader Forum