诚信为本
量力而为
当前位置:峰汇在线 > MetaTrader 4 > MT4指标 > 正文

特定价格均线指标 corelation.mq4

corelation指标根据特定的算法创建价格均线。

图表:corelation指标

源码:

//+---------------------------------------------------------------------------------+
//|                                                                  corelation.mq4 |
//|                                                Copyright @2008, Borys Chekmasov |
//+---------------------------------------------------------------------------------+
#property copyright "Copyright @2008, Borys Chekmasov"
#property link      "http://www.125808047.com"

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Gold
#property indicator_color2 DodgerBlue

extern string simbol_name = "EURUSD";
extern int bars_for_autoscale = 200;
extern bool inverse = false;
extern bool MA = false;
extern int MAPeriod =14;
extern bool MAOnly = false;

double simbolBuffer[];
double MABuffer[];

int OnInit(void)
{
   SetIndexBuffer(0,simbolBuffer);       
   SetIndexStyle (0,DRAW_LINE);
      SetIndexBuffer(1,MABuffer);       
   SetIndexStyle (1,DRAW_LINE);
   Comment("www.125808047.com");
   return(INIT_SUCCEEDED);
}
     
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[])
{
double simbol_scale = 1;
double simbol_offset = 0;
 int i,k;
int cb=IndicatorCounted();
i = Bars-cb-1;
k = bars_for_autoscale;
if (bars_for_autoscale==0) k=Bars;
double max_scale=iClose(simbol_name,0,1);
double min_scale=iClose(simbol_name,0,1);
double max_scale2=Close[1];
double min_scale2=Close[1];
while(k>=0) 
      {
      
      if (max_scale<iClose(simbol_name,0,k)) max_scale=iClose(simbol_name,0,k);
      if (min_scale>iClose(simbol_name,0,k)) min_scale=iClose(simbol_name,0,k);
      if (max_scale2<Close[k])max_scale2=Close[k];
      if (min_scale2>Close[k])min_scale2=Close[k];
      k--;
      }

simbol_scale = (max_scale2 - min_scale2)/(max_scale-min_scale);
      if(!inverse) {
 simbol_offset = max_scale2 - simbol_scale*max_scale;
 }
 else
 {
 simbol_offset = max_scale2 + simbol_scale*min_scale;
 }

while(i>=0) 
      {
      
        if(!inverse) 
        {
         if (!MAOnly) simbolBuffer[i]=simbol_scale*(iClose(simbol_name,0,i))+simbol_offset;
         if (MA)MABuffer[i]=(iMA(simbol_name,0,MAPeriod,0,0,PRICE_CLOSE,i))*simbol_scale+simbol_offset;
         }
        else 
        {
        if (!MAOnly) simbolBuffer[i]=simbol_offset - simbol_scale*(iClose(simbol_name,0,i));
        if (MA)MABuffer[i]=simbol_offset - simbol_scale*(iMA(simbol_name,0,MAPeriod,0,0,PRICE_CLOSE,i));
        }
          i--;
      }
   return(rates_total);
  }
打赏
版权所有转载请注明标题及链接:峰汇在线 » 特定价格均线指标 corelation.mq4
上一篇:
下一篇:
分享到: 更多 (0)

如您觉得此文不错请扫码打赏!

支付宝扫一扫打赏

微信扫一扫打赏