Metatrader Forum | Forex Expert-Advisor | Broker & Forex Tools
Zurück   Metatrader Forum | Forex Expert-Advisor | Broker & Forex Tools > Metatrader 5 > Programmierung MQL5

Programmierung MQL5 Hier gehts rund ums Programmieren in MQL5.

Login
Benutzername:
Kennwort:


Statistik
Themen: 4973
Beiträge: 43248
Benutzer: 7.219
Aktive Benutzer: 81
Links: 84
Wir begrüßen unseren neuesten Benutzer: Hopfen&Malz
Mit 2.475 Benutzern waren die meisten Benutzer gleichzeitig online (16.01.20 um 22:38).
Neue Benutzer:
vor einem Tag
- Hopfen&Mal...
vor 2 Tagen
- frankmicha...
vor einer Woche
- DFeck
vor einer Woche
- bb1107
vor 2 Wochen
- rg-trader

Onlineuser
'Wer ist online' anzeigen Benutzer: 0
Gäste: 93
Gesamt: 93
Team: 0
Team:  
Benutzer:  
Freunde anzeigen

Empfehlungen

Thema geschlossen
 
Themen-Optionen Thema durchsuchen Ansicht
  #1 (permalink)  
Alt 02.02.21
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);
}
  #2 (permalink)  
Alt 21.02.21
Mitglied
 
Registriert seit: Sep 2018
Beiträge: 238
Max2018 befindet sich auf einem aufstrebenden Ast
Standard

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;
Thema geschlossen

Lesezeichen

Stichworte
macd

Themen-Optionen Thema durchsuchen
Thema durchsuchen:

Erweiterte Suche
Ansicht

Forumregeln
Es ist Ihnen nicht erlaubt, neue Themen zu verfassen.
Es ist Ihnen nicht erlaubt, auf Beiträge zu antworten.
Es ist Ihnen nicht erlaubt, Anhänge hochzuladen.
Es ist Ihnen nicht erlaubt, Ihre Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are aus
Pingbacks are aus
Refbacks are aus




Alle Zeitangaben in WEZ +1. Es ist jetzt 09:15 Uhr.





Suchmaschine - Reisen - Wavesnode - Facebook Forum - Spam Firewall
-----------------------------------------------------------------------------------------------------------------------------
Powered by vBulletin® Version 3.8.5 (Deutsch)
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Powered by vBCMS® 2.7.0 ©2002 - 2024 vbdesigns.de
SEO by vBSEO 3.6.1
Copyright ©2009 - 2023 by Expert-Advisor.com - Das Metatrader Forum
MetaTrader bzw. MetaTrader 4 und MetaTrader 5 sind eingetragene Marken der MetaQuotes Software Corp.
-----------------------------------------------------------------------------------------------------------------------------