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

Danke für Deine Anregungen.

An Hand der ArraySetAsSeries - MQL4 Documentation habe ich den gewünschten Code hinbekommen.

Eine Frage hätte ich noch zu double EMAbuffer [45];
Erst ab 45 wird EMAonRSI korrekt berechnet. Der RSI wird spätestens ab 10 korrekt berechnet. Das habe ich jetzt nur durch Testen herausbekommen. Wie wird der Wert für [] normalerweise ermittelt?

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

int start()
{

double RSIbuffer [45];
double EMAbuffer [45];
int    i;
int    limit = ArraySize (RSIbuffer);
ArraySetAsSeries (RSIbuffer, true);
 
for (i = 0; i < limit; i++)
   RSIbuffer[i] = iRSI (NULL, 0, RSI, PRICE_CLOSE, i);

for (i = 0; i < limit; i++)
   EMAbuffer[i] = iMAOnArray (RSIbuffer, limit, EMA, 0, MODE_EMA, i);

for (i = 0; i < 3; i++)
    Print (" RSI ", i, "   ", DoubleToStr (RSIbuffer[i], Digits));

for (i = 0; i < 3; i++)
    Print (" EMAonRSI ", i, "   ", DoubleToStr (EMAbuffer[i], Digits));
}

Hier ist noch der etwas veränderte Indicator. Auch da wäre ich für weitere Verbesserungen im Coding dankbar:
Code:
#property indicator_separate_window
#property indicator_buffers 2

#property indicator_color1 C'44,177,44'
#property indicator_color2 Blue

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

double RSIclose[];
double MaRSIclose[];

int init()
{
    IndicatorDigits (Digits);

    SetIndexBuffer (0, MaRSIclose);
    SetIndexStyle (0, DRAW_LINE);
    SetIndexLabel (0, "EMAonRSI");
    SetIndexDrawBegin (0, EMA);

    SetIndexBuffer (1, RSIclose);
    SetIndexStyle (1, DRAW_LINE);
    SetIndexLabel (1, "RSI");
    SetIndexDrawBegin (0, RSI);

    IndicatorShortName ("EMAonRSI  ["+EMA+",  "+RSI+"] ");
    return (0);
}

int start()
{
    int counted, i;
    counted = IndicatorCounted();

    if (counted < 1)
        for (i = Bars - 2 * EMA; i < Bars; i++)
        {
            RSIclose[i]   = 0.0;
            MaRSIclose[i] = 0.0;
        }

    counted = Bars - counted - 1;

    for (i = counted; i >= 0; i--)
        RSIclose[i]  = iRSI (NULL, 0, RSI, PRICE_CLOSE, i);
    
    for (i = counted; i >= 0; i--)
        MaRSIclose[i] = iMAOnArray (RSIclose, 0, EMA, 0, MODE_EMA, i);
    
    return (0);
}