Einzelnen Beitrag anzeigen
  #1 (permalink)  
Alt 02.02.21
Max2018 Max2018 ist offline
Mitglied
 
Registriert seit: Sep 2018
Beiträge: 238
Max2018 befindet sich auf einem aufstrebenden Ast
Standard Indikator Umschreiben MACDSignal

Hallo,

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

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);
}