Einzelnen Beitrag anzeigen
  #1 (permalink)  
Alt 21.02.21
Max2018 Max2018 ist offline
Mitglied
 
Registriert seit: Sep 2018
Beiträge: 238
Max2018 befindet sich auf einem aufstrebenden Ast
Standard 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);
  }
//+------------------------------------------------------------------+