Einzelnen Beitrag anzeigen
  #7 (permalink)  
Alt 21.02.12
Dennis Dennis ist offline
Neues Mitglied
 
Registriert seit: Feb 2012
Beiträge: 4
Dennis befindet sich auf einem aufstrebenden Ast
Standard

Versuchen? Du wußtest doch bestimmt genau, daß Dein Code wunschgemäß funktionieren wird Danke Dir dafür! Dein Code sieht natürlich schon rein optisch straffer aus und er bringt sicher auch einen Speed-Vorteil.

MAonRSI[k] liefert erst ab RSIBuffer [76] korrekte Werte bis in die 5. Nachkommastelle. Hier muß man also probieren oder den Wert gleich ziemlich hoch ansetzen (Speed-Nachteil).

Wie ist "//Zugriff auf Array für iMAOnArray umkehren" gemeint? Denn ArraySetAsSeries (RSIBuffer, true); hatte ich ja bereits genauso gecodet in meinem 2. Versuch.

Die Comment-Funktion ist natürlich ganz praktisch. Beim Stöbern nach einer Erklärung des void-Befehls bin ich auf Information Storage and View - MQL4 Articles gestoßen. Mit den dort downloadbaren Dateien sind die Comments komfortabel gestaltbar. info.mq4 habe ich allerdings angepaßt, damit alles wunschgemäß angezeigt werden kann.

Wie ist das eigentlich mit dem void-Befehl? Ich meine schon gelesen zu haben, daß theoretisch auch komplexe EAs statt mit int start() genauso mit einzelnen void-Befehlen gecodet werden können.

Zum Indikator: Naja, Du meintest in #2, der Indikator enthält ein paar grobe Schnitzer. Daraufhin hatte ich ihn nach meinen bescheidenen Möglichkeiten versucht zu verbessern. Ist er jetzt ok so, wie er zuletzt gepostet ist?

Code:
#include <info3.mq4>

extern int EMA = 10;
extern int RSI =  5;

double RSIBuffer[76]; //Buffer für RSI Werte, erst ab [76] korrekte Werte bis in 5. Stelle
double MAonRSI[3];    //Ergebnis für 3 Kerzen

void init()
{
   ArraySetAsSeries (RSIBuffer, true); //Zugriff auf Array für iMAOnArray umkehren
   info_init();
}

void deinit()
{
   info_deinit();
}

void start()
{
   for (int k = 0; k <= 2; k++) //k = die 3 letzten Kerzen
   {
      for (int i = 0; i <= 75; i++) // Index für RSI Array
         {
            RSIBuffer[i] = iRSI (NULL, 0, RSI, PRICE_CLOSE, i); //Array beschreiben
         }  
      MAonRSI[k] = iMAOnArray (RSIBuffer, 0, EMA, 0, MODE_EMA, k);
   }
/*     
   // für normale Ausgabe im Chart:
   Comment ("MAonRSI  0:  ", DoubleToStr (MAonRSI[0], Digits),
      "\n", "MAonRSI  1:  ", DoubleToStr (MAonRSI[1], Digits),     
      "\n", "MAonRSI  2:  ", DoubleToStr (MAonRSI[2], Digits),
      "\n", "RSI  0:  ", DoubleToStr (RSIBuffer[0], Digits),
      "\n", "RSI  1:  ", DoubleToStr (RSIBuffer[1], Digits),     
      "\n", "RSI  2:  ", DoubleToStr (RSIBuffer[2], Digits));

   // für Ausgabe im Journal:
   for (int j = 2; j >= 0; j--)
   {
      Print (" MAonRSI ", j, "   ", DoubleToStr (MAonRSI[j], Digits));
      Print (" RSI ", j, "   ", DoubleToStr (RSIBuffer[j], Digits));
   }
*/
   // für komfortablere Ausgabe im Chart:
   info (0, "Account #" + AccountNumber() + " (" + AccountName() + "):", Blue, 10);
   info (1, "AccountBalance = " + DoubleToStr (AccountBalance(), 2), Blue);
   info (2, "AccountEquity   = " + DoubleToStr (AccountEquity(), 2), Blue);
   info (3, "MAonRSI 0   " + DoubleToStr (MAonRSI[0], Digits), Blue);
   info (4, "MAonRSI 1   " + DoubleToStr (MAonRSI[1], Digits), Blue);
   info (5, "MAonRSI 2   " + DoubleToStr (MAonRSI[2], Digits), Blue);
   info (6, "RSI 0   " + DoubleToStr (RSIBuffer[0], Digits), Blue);
   info (7, "RSI 1   " + DoubleToStr (RSIBuffer[1], Digits), Blue);
   info (8, "RSI 2   " + DoubleToStr (RSIBuffer[2], Digits), Blue);
}
info3.mq4:
Code:
color  lastusedColor    = Blue;
double lastusedFontSize = 10;
string lastusedFont     = "Verdana";

void info_init()
{
	for (int row = 0; row <= 10; row ++)
	{
		_LabelCreate (StringConcatenate ("InfoLabel_0", row),  10, 20 + 20 * row); // Zeilenabstand x * row
		_LabelCreate (StringConcatenate ("InfoLabel_1", row), 270, 15 + 15 * row);
	}
}

void _LabelCreate (string _Name, int _XDistance, int _YDistance, int _Corner = 0)
{
	int _GetLastError;

	if (!ObjectCreate (_Name, OBJ_LABEL, 0, 0, 0))
	{
		_GetLastError = GetLastError();
		if (_GetLastError != 4200)
		{
			Print ("ObjectCreate (\"", _Name, "\", OBJ_LABEL, 0, 0, 0) - Error #", _GetLastError);
			return(-1);
		}
	}
	if (!ObjectSet (_Name, OBJPROP_CORNER, _Corner))
	{
		_GetLastError = GetLastError();
		Print ("ObjectSet( \"", _Name, "\", OBJPROP_CORNER, ", _Corner, 
													") - Error #", _GetLastError);
	}
	if (!ObjectSet( _Name, OBJPROP_XDISTANCE, _XDistance ) )
	{
		_GetLastError = GetLastError();
		Print ("ObjectSet (\"", _Name, "\", OBJPROP_XDISTANCE, ", _XDistance, 
															") - Error #", _GetLastError);
	}
	if (!ObjectSet (_Name, OBJPROP_YDISTANCE, _YDistance))
	{
		_GetLastError = GetLastError();
		Print ("ObjectSet (\"", _Name, "\", OBJPROP_YDISTANCE, ", _YDistance, 
															") - Error #", _GetLastError);
	}
	if (!ObjectSetText (_Name, "", 10))
	{
		_GetLastError = GetLastError();
		Print ("ObjectSetText (\"", _Name, "\", \"\", 10) - Error #", _GetLastError);
	}
}

void info_deinit()
{
	int _GetLastError;
	for (int row = 0; row <= 10; row ++)
	{
		if (!ObjectDelete (StringConcatenate ("InfoLabel_0", row)))
		{
			_GetLastError = GetLastError();
			Print ("ObjectDelete (\"", StringConcatenate ("InfoLabel_0", row), 
															"\") - Error #", _GetLastError);
		}
		if (!ObjectDelete (StringConcatenate ("InfoLabel_1", row)))
		{
			_GetLastError = GetLastError();
			Print ("ObjectDelete (\"", StringConcatenate ("InfoLabel_1", row), 
															"\") - Error #", _GetLastError);
		}
	}
}

void info (int LabelNumber, string Text, color Color = -1, 
			  double FontSize = -1.0, string Font = "-1")
{
	string LabelName;
	if (LabelNumber < 10 )  // hier 10 im Original
		LabelName = StringConcatenate ("InfoLabel_0", LabelNumber);
	else
		LabelName = StringConcatenate ("InfoLabel_" , LabelNumber);

	if (Color < 0) Color = lastusedColor;
	if (FontSize < 0) FontSize = lastusedFontSize;
	if (Font == "-1") Font = lastusedFont;

	lastusedColor = Color;
	lastusedFontSize = FontSize;
	lastusedFont = Font;

	if (!ObjectSetText (LabelName, Text, FontSize, Font, Color))
	{
		int _GetLastError = GetLastError();
		Print ("ObjectSetText (\"", LabelName, "\", \"", Text, "\", ", FontSize, ", ", Font, 
															", ", Color, ") - Error #", _GetLastError);
	}
	ObjectsRedraw();
}

void info_clear()
{
	for (int n =  0;  n < 5; n ++) info (n, ""); // hier zwecks Erhöhung der Info-Lines nichts geändert
	for (    n = 10; n < 15; n ++) info (n, ""); // hier zwecks Erhöhung der Info-Lines nichts geändert
}