Metatrader Forum | Forex Expert-Advisor | Broker & Forex Tools

Metatrader Forum | Forex Expert-Advisor | Broker & Forex Tools (http://www.expert-advisor.com/forum/index.php)
-   Programmierung MQL5 (http://www.expert-advisor.com/forum/forumdisplay.php?f=221)
-   -   Relative Stärke nach Levy im MT5 (http://www.expert-advisor.com/forum/showthread.php?t=6917)

Max2018 21.02.21 15:11

Relative Stärke nach Levy im MT5
 
Hallo,

die relative Stärke nach Levy wird berechnet nach

Letzter WochenSchlusskurs/durchschn. Wochenschlusskurs der t wochen....

also
Code:

iClose(NULL,0,i)
dividiert durch
Code:

iMA(NULL,PERIOD_W1,LevyWochen,i,MODE_EMA,PRICE_CLOSE);
und warum geht dann dieser Indicator nicht?

Code:



#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots  1
#property indicator_level1  2
#property indicator_level2 -2
#property indicator_type1  DRAW_LINE
#property indicator_color1  LightSeaGreen
#property indicator_label1  "Levy"

//--- input params
input int LevyWochen=9;
//---- buffers
double DPCBuffer[];
double A,C,X,Levy,iMa1;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                        |
//+------------------------------------------------------------------+
int OnInit()
  {
  IndicatorSetString(INDICATOR_SHORTNAME,"Levy");
//---- index buffer
  SetIndexBuffer(0,DPCBuffer,INDICATOR_DATA);
  ArraySetAsSeries(DPCBuffer,true);
//  PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,100);
  return(INIT_SUCCEEDED);

//---- OnInit done
  }
//+------------------------------------------------------------------+
//| Calculation                                        |
//+------------------------------------------------------------------+
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[])
  {

//--- check for bars count
  if(rates_total<7200/Period())
      return(0); //exit with zero result

//--- prevent total recalculation
  int i=rates_total-1;
  if(prev_calculated>0)
      i=rates_total-prev_calculated -1;

//--- current value should be recalculated
  if(i<0)
      i=0;
//---
  while(i>=0)
    {
      datetime date=iTime(NULL,0,i);
      int Hour=TimeHourMQL4(date);
      int Minute=TimeMinuteMQL4(date);
     
        A=iClose(NULL,0,i);
        iMa1=iMA(NULL,PERIOD_W1,LevyWochen,i,MODE_EMA,PRICE_CLOSE);
        Levy=NormalizeDouble(A/iMa1,1); 
        DPCBuffer[i]=Levy;
      i--;

    }

//----
  return(rates_total);
  }
//+------------------ Functions -----------------------------------------------+

int TimeHourMQL4(datetime date)
  {
  MqlDateTime tm;
  TimeToStruct(date,tm);
  return(tm.hour);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int TimeMinuteMQL4(datetime date)
  {
  MqlDateTime tm;
  TimeToStruct(date,tm);
  return(tm.min);
  }
//+------------------------------------------------------------------+


Indikator-Trading 21.02.21 15:57

Hallo, da gibt es ein paar Faktoren, welche hier das Problem sein könnten.

1)
Code:

  if(rates_total<7200/Period())
      return(0); //exit with zero result

Du musst genug Historie haben, damit dieser Indikator überhaupt mal eine Berechnung durchführt, also min. (7200 / Period())
Period() in MQL5 ist aber leider nicht Period() von MQL4. Lies hierzu am besten mal die Hilfe für MQL5

2)
Code:

//--- current value should be recalculated
  if(i<0)
      i=0;
//---
  while(i>=0)
    {

Mit einer While-Schleife würde ich nach Möglichkeit niemals arbeiten, aber ein eigentliches Problem könnte es auch sein, dass in MT5 die Reihenfolge der Arrays und der historischen Candlebezüge umgedreht ist. Du solltest also besser im Indikator also von 0 bis (rates_total-1) zählen und nicht umgekehrt.

3)
Code:

iMa1=iMA(NULL,PERIOD_W1,LevyWochen,i,MODE_EMA,PRICE_CLOSE);
Hier bekommst du das Handle von den MA, aber nicht den Wert. Das ist alles anders als in MT5. Hierzu bitte ebenfalls einmal die Hilfe bemühen.

Gruß Timo

Max2018 21.02.21 15:59

ok Danke - werde es nochmal versuchen .....


Alle Zeitangaben in WEZ +2. Es ist jetzt 16:44 Uhr.

Powered by vBulletin® Version 3.8.5 (Deutsch)
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.6.1
Powered by vBCMS® 2.7.0 ©2002 - 2024 vbdesigns.de
Copyright ©2009 - 2023 by Expert-Advisor.com - Das Metatrader Forum