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

Metatrader Forum | Forex Expert-Advisor | Broker & Forex Tools (http://www.expert-advisor.com/forum/index.php)
-   Programmierung MQL5 (http://www.expert-advisor.com/forum/forumdisplay.php?f=221)
-   -   Indikator Umschreiben MACDSignal (http://www.expert-advisor.com/forum/showthread.php?t=6905)

Max2018 02.02.21 07:46

Indikator Umschreiben MACDSignal
 
Hallo,

ich habe einen eigenen MACD Signal Indikator, der im MT4 läuft, aber nicht im MT5.... wo liegt der Fehler :confused:

Hier die MT4 Version:
Code:

//--------------------------------------------------------------------
#property strict
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 clrYellow
//--------------------------------------------------------------------
input string              Indicator                  = "MACD";      /*--/ MACD*/
input int                  MACD_fast_ema_period      = 12;          /*. fast_ema_period*/ //12
input int                  MACD_slow_ema_period      = 26;          /*. slow_ema_period*/ //26
input int                  MACD_signal_period        = 9;          /*. signal_period*/
input ENUM_APPLIED_PRICE  MACD_applied_price        = 0;          /*. applied_price*/ // PRICE_CLOSE,PRICE_OPEN,PRICE_HIGH,PRICE_LOW,PRICE_MEDIAN,PRICE_TYPICAL(HLC/3),PRICE_WEIGHTED(HLCC/4)
//--------------------------------------------------------------------
double buf[];
//====================================================================
//• OnInit -----------------------------------------------------------
void OnInit()
  {
  SetIndexBuffer(0,buf);
  SetIndexStyle(0,DRAW_LINE);
  IndicatorDigits(0);
  }
//====================================================================
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 limit=rates_total-prev_calculated;
  for(int i=0;i<limit;i++)
      {
      double iMACDmain_0=iMACD(NULL,PERIOD_CURRENT,MACD_fast_ema_period,MACD_slow_ema_period,MACD_signal_period,MACD_applied_price,MODE_MAIN,i),
            iMACDmain_1=iMACD(NULL,PERIOD_CURRENT,MACD_fast_ema_period,MACD_slow_ema_period,MACD_signal_period,MACD_applied_price,MODE_MAIN,i+1),
            iMACDmain_2=iMACD(NULL,PERIOD_CURRENT,MACD_fast_ema_period,MACD_slow_ema_period,MACD_signal_period,MACD_applied_price,MODE_MAIN,i+2),
            iMACDmain_3=iMACD(NULL,PERIOD_CURRENT,MACD_fast_ema_period,MACD_slow_ema_period,MACD_signal_period,MACD_applied_price,MODE_MAIN,i+3),
            iMACDmain_4=iMACD(NULL,PERIOD_CURRENT,MACD_fast_ema_period,MACD_slow_ema_period,MACD_signal_period,MACD_applied_price,MODE_MAIN,i+4),
            XB=(iMACDmain_1+iMACDmain_3+iMACDmain_2),
            XA=(iMACDmain_1+iMACDmain_0+iMACDmain_2),
            XC,XD;
            if(XA>XC)XC=XA;
            if(XA<XD)XD=XA;
      //buf[i]=(XB<XA?1:0);
      buf[i]=(XC?1:0);
      }
  //---
  return(rates_total);
  }

und hier die MT5 Version

Code:

//+------------------------------------------------------------------+
//|                                                      MACD3er.mq5 |
//|                        Copyright 2019, MetaQuotes Software Corp. |
//|                                            https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2019, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version  "1.00"
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots  1
#property indicator_color1 clrYellow

input string              Indicator                  = "MACD";      /*--/ MACD*/
input int                  MACD_fast_ema_period      = 12;          /*. fast_ema_period*/ //12
input int                  MACD_slow_ema_period      = 26;          /*. slow_ema_period*/ //26
input int                  MACD_signal_period        = 9;          /*. signal_period*/
input ENUM_APPLIED_PRICE  MACD_applied_price        = PRICE_CLOSE;          /*. applied_price*/ // PRICE_CLOSE,PRICE_OPEN,PRICE_HIGH,PRICE_LOW,PRICE_MEDIAN,PRICE_TYPICAL(HLC/3),PRICE_WEIGHTED(HLCC/4)


double buf[];
int macd_handle;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                        |
//+------------------------------------------------------------------+
int OnInit()
  {

  SetIndexBuffer(0,buf,INDICATOR_DATA);
  PlotIndexSetInteger(0,PLOT_DRAW_TYPE,DRAW_LINE);
  IndicatorSetInteger(INDICATOR_DIGITS,0);
  ArraySetAsSeries(buf,true);
 
  macd_handle = iMACD(NULL,PERIOD_CURRENT,MACD_fast_ema_period,MACD_slow_ema_period,MACD_signal_period,MACD_applied_price);
           
     
  return(INIT_SUCCEEDED);
  }
 
void OnDeinit(const int reason){
 IndicatorRelease(macd_handle);

//+------------------------------------------------------------------+
//| 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[])
  {
  double iMACDmain_0;
  double iMACDmain_1;
  double iMACDmain_2;
  double iMACDmain_3;
  double iMACDmain_4;
  double XA;
  double XB;
  double XC=0;
  double XD=0;
  int limit=rates_total-prev_calculated;
 
 
    for(int i=0;i<limit;i++)
 
 
      {
        iMACDmain_0= macd(i);
        iMACDmain_1= macd(i+1);
        iMACDmain_2= macd(i+2);
        iMACDmain_3= macd(i+3);
        iMACDmain_4= macd(i+4);
       
        XB=(iMACDmain_1+iMACDmain_3+iMACDmain_2);
        XA=(iMACDmain_1+iMACDmain_0+iMACDmain_2);
        if(XA>XC)XC=XA;
        if(XA<XD)XD=XA;
        //buf[i]=(XB<XA?1:0);
        //xxbuf[i]=(XC!=0?1:0);
            buf[i]=(XC?1:0);
    } 

  return(rates_total);
  }
//+------------------------------------------------------------------+


double macd( int shift) {
  double value[];
  if( macd_handle!=INVALID_HANDLE ) {
      if( CopyBuffer(macd_handle,0,shift,1,value)>0 )
        return(value[0]);
  }
  return(WRONG_VALUE);
}


Max2018 21.02.21 15:16

Schade dass in diesem Forum keine Antwort kam ;)
Der Fehler lag in diesem Abschnitt, der richtig heißen muss:
Code:

{
  for(int i=MathMin(rates_total-prev_calculated+1,rates_total-1); i>=0; i--) {
      double iMACDmain_0;
      double iMACDmain_1;
      double iMACDmain_2;
      double iMACDmain_3;
      double iMACDmain_4;
     
      double XA;
      double XB;
      double XC=0;
      double XD=0;

      buf[i]=EMPTY_VALUE;



Alle Zeitangaben in WEZ +2. Es ist jetzt 11:04 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