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: 4972
Beiträge: 43246
Benutzer: 7.216
Aktive Benutzer: 84
Links: 84
Wir begrüßen unseren neuesten Benutzer: bb1107
Mit 2.475 Benutzern waren die meisten Benutzer gleichzeitig online (16.01.20 um 22:38).
Neue Benutzer:
vor 2 Tagen
- bb1107
vor einer Woche
- rg-trader
vor 2 Wochen
- toshistyle
vor 2 Wochen
- Robin
vor 3 Wochen
- mMmaanu

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

Empfehlungen

Thema geschlossen
 
Themen-Optionen Thema durchsuchen Ansicht
  #1 (permalink)  
Alt 04.03.14
Neues Mitglied
 
Registriert seit: Feb 2014
Beiträge: 21
nikoscher befindet sich auf einem aufstrebenden Ast
Standard Quellcode analysieren

Hey liebe community,

Zur Zeit arbeite ich mit dem MACD-2 Indikator, hier ein kurzer Ausschnitt:
Bildschirmfoto 2014-03-02 um 21.11.34.png
So meine Frage, wie kann ich die momentane Farbe auslesen, sprich sowas wie:
Code:
if ( current_color == "gruen" ) 
{
    Print ( "Zurzeit gruen" );
}
elseif ( current_color == "rot" )
{
    Print ( "Zurzeit rot" );
} 
else 
{
    Print ( "Irgendwas stimmt nicht" );
}
Hier kurz der Quellcode des Indikators (140 Zeilen):
Code:
//+------------------------------------------------------------------+
//|                                                       MACD-2.mq5 |
//|                      Copyright © 2005, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"
//--- indicator version
#property version   "1.00"
//--- indicator description
#property description "MACD-2"
//--- drawing the indicator in a separate window
#property indicator_separate_window
//--- number of indicator buffers 4
#property indicator_buffers 4
//--- two plots are used
#property indicator_plots   2
//+-----------------------------------+
//|  Declaration of constants         |
//+-----------------------------------+
#define RESET  0 // a constant for returning the indicator recalculation command to the terminal
//+-----------------------------------+
//|  Parameters of indicator drawing  |
//+-----------------------------------+
//--- drawing the indicator as a colored cloud
#property indicator_type1   DRAW_FILLING
//--- the following colors are used as the indicator colors
#property indicator_color1  clrLime,clrDeepPink
//--- displaying the indicator label
#property indicator_label1  "MACD_Cloud"
//+----------------------------------------------+
//|  Indicator 2 drawing parameters              |
//+----------------------------------------------+
//--- drawing indicator as a four-color histogram
#property indicator_type2 DRAW_COLOR_HISTOGRAM
//--- colors of the five-color histogram are as follows
#property indicator_color2 clrBrown,clrViolet,clrGray,clrDeepSkyBlue,clrBlue
//--- indicator line is a solid one
#property indicator_style2 STYLE_SOLID
//--- indicator line width is 2
#property indicator_width2 2
//--- displaying the indicator label
#property indicator_label2  "MACD"
//+-----------------------------------+
//|  Indicator input parameters       |
//+-----------------------------------+
input uint FastMACD     = 12;
input uint SlowMACD     = 26;
input uint SignalMACD   = 9;
input ENUM_APPLIED_PRICE   PriceMACD=PRICE_CLOSE;
//+-----------------------------------+
//--- declaration of integer variables for the start of data calculation
int  min_rates_total;
//--- declaration of dynamic arrays that will be used as indicator buffers
double ExtABuffer[],ExtBBuffer[];
double IndBuffer[],ColorIndBuffer[];
//--- declaration of integer variables for the indicators handles
int MACD_Handle;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- initialization of variables of the start of data calculation
   min_rates_total=int(SignalMACD+MathMax(FastMACD,SlowMACD));
//--- getting the handle of iMACD
   MACD_Handle=iMACD(NULL,0,FastMACD,SlowMACD,SignalMACD,PriceMACD);
   if(MACD_Handle==INVALID_HANDLE)
     {
      Print(" Failed to get the handle of iMACD");
      return(INIT_FAILED);
     }
//--- set dynamic array as an indicator buffer
   SetIndexBuffer(0,ExtABuffer,INDICATOR_DATA);
//--- indexing elements in the buffer as in timeseries
   ArraySetAsSeries(ExtABuffer,true);
//--- set dynamic array as an indicator buffer
   SetIndexBuffer(1,ExtBBuffer,INDICATOR_DATA);
//--- indexing elements in the buffer as in timeseries
   ArraySetAsSeries(ExtBBuffer,true);
//--- set IndBuffer dynamic array as an indicator buffer
   SetIndexBuffer(2,IndBuffer,INDICATOR_DATA);
//--- indexing elements in the buffer as in timeseries
   ArraySetAsSeries(IndBuffer,true);
//--- setting a dynamic array as a color index buffer  
   SetIndexBuffer(3,ColorIndBuffer,INDICATOR_COLOR_INDEX);
//--- indexing elements in the buffer as in timeseries
   ArraySetAsSeries(ColorIndBuffer,true);
//--- shifting the start of drawing of the indicator
   PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,min_rates_total);
//--- shifting the start of drawing of the indicator
   PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,min_rates_total);
//--- creation of the name to be displayed in a separate sub-window and in a pop up help
   IndicatorSetString(INDICATOR_SHORTNAME,"MACD-2");
//--- determining the accuracy of the indicator values
   IndicatorSetInteger(INDICATOR_DIGITS,0);
//--- initialization end
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+  
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+  
int OnCalculate(const int rates_total,    // number of bars in history at the current tick
                const int prev_calculated,// amount of history in bars at the previous tick
                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[])
  {
//--- checking if the number of bars is enough for the calculation
   if(BarsCalculated(MACD_Handle)<rates_total || rates_total<min_rates_total) return(RESET);
//--- declarations of local variables
   int to_copy,limit;
//--- calculation of the 'limit' starting index for the bars recalculation loop
   if(prev_calculated>rates_total || prev_calculated<=0)// Checking for the first start of the indicator calculation
      limit=rates_total-min_rates_total-1; // Starting index for calculation of all bars
   else limit=rates_total-prev_calculated;  // starting index for calculation of new bars only  
   to_copy=limit+1;
//--- copy newly appeared data in the arrays
   if(CopyBuffer(MACD_Handle,MAIN_LINE,0,to_copy,ExtABuffer)<=0) return(RESET);
   if(CopyBuffer(MACD_Handle,SIGNAL_LINE,0,to_copy,ExtBBuffer)<=0) return(RESET);
//--- main indicator calculation loop
   for(int bar=limit; bar>=0 && !IsStopped(); bar--)
     {
      ExtABuffer[bar]/=_Point;
      ExtBBuffer[bar]/=_Point;
      IndBuffer[bar]=3*(ExtABuffer[bar]-ExtBBuffer[bar]);
     }
   if(prev_calculated>rates_total || prev_calculated<=0) limit--;
//--- Main loop of the Ind indicator coloring
   for(int bar=limit; bar>=0 && !IsStopped(); bar--)
     {
      int clr=2;
      if(IndBuffer[bar]>0)
        {
         if(IndBuffer[bar]>IndBuffer[bar+1]) clr=4;
         if(IndBuffer[bar]<IndBuffer[bar+1]) clr=3;
        }
      if(IndBuffer[bar]<0)
        {
         if(IndBuffer[bar]<IndBuffer[bar+1]) clr=0;
         if(IndBuffer[bar]>IndBuffer[bar+1]) clr=1;
        }
      ColorIndBuffer[bar]=clr;
     }
//---    
   return(rates_total);
  }
//+------------------------------------------------------------------+
Kann mir da jmd helfen? Ich finde da keinen Ansatz... LG!!
  #2 (permalink)  
Alt 04.03.14
Mitglied
 
Registriert seit: Apr 2011
Ort: Osnabrück
Beiträge: 103
Racki befindet sich auf einem aufstrebenden Ast
Standard

Hier mal n schneller Lösungsansatz

PHP-Code:
//+------------------------------------------------------------------+
//|                                                  MACD2_lesen.mq5 |
//|                        Copyright 2014, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"

int MACD2_Handle;
double MACD2_Buffer1[];
double MACD2_Buffer2[];
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   
MACD2_Handle iCustom(_Symbol,PERIOD_CURRENT,"MACD2");
   
CopyBufferAsSeries(MACD2_Handle,0,0,100,true,MACD2_Buffer1);
   
CopyBufferAsSeries(MACD2_Handle,2,0,100,true,MACD2_Buffer2);
   
//---
   
return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  
}
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   
if(MACD2_Buffer2[0] >= 0) {
   
Comment("Wert der Cloud = " + (string)MACD2_Buffer1[0] + " Farbe = grün"); 
   }
   else 
   {
   
Comment("Wert der Cloud = " + (string)MACD2_Buffer1[0] + " Farbe = pink"); 
   }
   
  }
//+------------------------------------------------------------------+
bool CopyBufferAsSeries(
                        
int handle,      // indicator's handle
                        
int buffer,       // buffer index
                        
int start,       // start index
                        
int number,      // number of elements to copy
                        
bool asSeries,   // if it's true, the elements will be indexed as series
                        
double &M[]      // target array
                        
)
  {
//--- filling the array M with current values of the indicator
   
if(CopyBuffer(handle,buffer,start,number,M)<=0) return(false);
//--- the elements will be indexed as follows:
//--- if asSeries=true, it will be indexed as timeseries
//--- if asSeries=false, it will be indexed as default
   
ArraySetAsSeries(M,asSeries);
//---
   
return(true);
  } 
  #3 (permalink)  
Alt 05.03.14
Neues Mitglied
 
Registriert seit: Feb 2014
Beiträge: 21
nikoscher befindet sich auf einem aufstrebenden Ast
Standard

alles klar, danke, läuft, hab den code kapiert
  #4 (permalink)  
Alt 06.03.14
Neues Mitglied
 
Registriert seit: Feb 2014
Beiträge: 21
nikoscher befindet sich auf einem aufstrebenden Ast
Standard

ok also, der Teil:
Code:
void OnTick()
  {
//---
   if(MACD2_Buffer2[0] >= 0) {
   Print("Wert der Cloud = " + (string)MACD2_Buffer1[0] + " Farbe = grün"); 
   }
   else 
   {
   Print("Wert der Cloud = " + (string)MACD2_Buffer1[0] + " Farbe = pink"); 
   }
   
  }
Egal ob die "Cloud nun grün oder pink ist =>
Das Ergebnis ist immer grün, weiß da jmd wieso?
  #5 (permalink)  
Alt 08.03.14
Mitglied
 
Registriert seit: Apr 2011
Ort: Osnabrück
Beiträge: 103
Racki befindet sich auf einem aufstrebenden Ast
Standard

Du müsstest die Arrays mit den MACD2-Werten neu befüllen.

PHP-Code:
CopyBufferAsSeries(MACD2_Handle,0,0,100,true,MACD2_Buffer1);
CopyBufferAsSeries(MACD2_Handle,2,0,100,true,MACD2_Buffer2); 
Thema geschlossen

Lesezeichen

Stichworte
analysierenmql5, macd, macd-2, quellcode, quellcode analysieren

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 04:45 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.
-----------------------------------------------------------------------------------------------------------------------------