0
(0)
姓名:
HVR [ | cn ]
作者: 作家 (2008.02.11 10:02)
已下載: 1206
下載:
HVR 1
HVR.mq4 (2.9 KB) 看法
作者: Albert, (idea and code into MQL2 - podval)

HVR indicator.

HVR 2
1 評論 發表新評論, 請 登錄 或者 登記

The following code displays both 6 & 10 HVR with 100 (all periods as params). Also for more periods on chart.

//+------------------------------------------------------------------+ 
//|                                                          HVR.mq4 | 
//|      版權所有© 2005, Albert,(idea and code into MQL2 - podval) | 
//|      Refactored © 2010, Brewmanz (添加 2 HVR lines)               | 
//|                                                                  | 
//+------------------------------------------------------------------+ 
#property indicator_separate_window
//----
//#property indicator_minimum 0
//#property indicator_maximum 3
#property indicator_buffers 3
//----
#property indicator_color1 Blue
#property indicator_color2 Purple

extern int PeriodLong=100;
extern int PeriodShort=10;
extern int PeriodVeryShort=6;

double
   xVeryShort[],
   xShort[],
   xLong[];

#define kVolfactor 7.211102550927978586238442534941
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
//---- buffers 
double HVRSBuffer[];
double HVRVSBuffer[];
//+------------------------------------------------------------------+ 
//| Custom indicator initialization function                         | 
//+------------------------------------------------------------------+ 
int init()
  {
   ArrayResize(xVeryShort, PeriodVeryShort);
   ArrayResize(xShort, PeriodShort);
   ArrayResize(xLong, PeriodLong);
   SetLevelValue(0, 0.0);
   SetLevelValue(1, 0.5);
   SetLevelValue(2, 1.0);
   SetLevelValue(3, 2.0);
//---- 2 additional buffers are used for counting. 
   IndicatorBuffers(2);
   SetIndexBuffer(0,HVRSBuffer);
   SetIndexBuffer(1,HVRVSBuffer);
//---- indicator line 
   SetIndexStyle(0,DRAW_LINE);
   SetIndexStyle(1,DRAW_LINE);
//---- name for DataWindow and indicator subwindow label 
   IndicatorShortName("HVR( " + PeriodVeryShort +" & " + PeriodShort + " /" + PeriodLong + ")");
   SetIndexLabel(0,"HVR(" + PeriodShort + "/" + PeriodLong + ")");
   SetIndexLabel(1,"HVR(" + PeriodVeryShort + "/" + PeriodLong + ")");
//---- 
//---- 
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
   {
double  hvVeryShort,
   hvShort,
   hvLong,
   meanVeryShort,
   meanShort,
   meanLong;
   int counted_bars=IndicatorCounted();
//---- last counted bar will be recounted
   if(counted_bars>0) 
      counted_bars--;
   int ixLimit=Bars-counted_bars-1;
   為了(int ix=ixLimit; ix>=0; ix--)
   {
      如果(ix+PeriodLong >= Bars)
         continue;
      meanVeryShort=0;
      meanShort=0;
      meanLong=0;
      為了(int i=0; 我<PeriodLong; i++)
      {
         double myLog=MathLog(關閉[ix+i]/關閉[ix+i+1]);
         xLong[我]=myLog;
         meanLong+=myLog;
         如果(我<PeriodShort)
         {
            xShort[我]=myLog;
            meanShort+=myLog;
         }
         如果(我<PeriodVeryShort)
         {
            xVeryShort[我]=myLog;
            meanVeryShort+=myLog;
         }
      }

      meanVeryShort/=PeriodVeryShort;
      meanShort/=PeriodShort;
      meanLong/=PeriodLong;

      hvVeryShort=0;
      為了(i=0; 我<PeriodVeryShort; i++)
         hvVeryShort+=(xVeryShort[我] - meanVeryShort)*(xVeryShort[我] - meanVeryShort);
      hvVeryShort=MathSqrt(hvVeryShort/(PeriodVeryShort-1)) * kVolfactor;

      hvShort=0;
      為了(i=0; 我<PeriodShort; i++)
         hvShort+=(xShort[我] - meanShort)*(xShort[我] - meanShort);
      hvShort=MathSqrt(hvShort/(PeriodShort-1)) * kVolfactor;

      hvLong=0;
      為了(i=0; 我<PeriodLong; i++)
         hvLong+=(xLong[我] - meanLong)*(xLong[我] - meanLong);
      hvLong=MathSqrt(hvLong/(PeriodLong-1)) * kVolfactor;

      HVRVSBuffer[ix]= hvVeryShort/hvLong;
      HVRSBuffer[ix]= hvShort/hvLong;
   }
}
//+------------------------------------------------------------------+

這篇文章有多有用?

點擊一顆星即可對其進行評分!

平均評分 0 / 5. 計票數: 0

目前還沒有投票! 成為第一個評價這篇文章的人.

很抱歉這篇文章對您沒有用!

讓我們改進這篇文章!

告訴我們如何改進這篇文章?



作者: 外匯維基團隊
我們是一支經驗豐富的外匯交易員團隊 [2000-2023] 致力於以我們自己的方式生活的人. 我們的主要目標是實現財務獨立和自由, 我們追求自我教育並在外匯市場上獲得豐富的經驗,以此作為實現自我可持續生活方式的手段.