12下一页
返回列表 发布新帖

谁会修改mt4的RIS线。

3118 13
山野居士 发表于 2005-9-12 13:04 | 查看全部 阅读模式
https://www.y2cn.com
MT的RIS  指标 只有一条线, RIS  (14)。本人已习惯了使用三条线的 RSI 指标,对此将其作了些修改,编译已经通过了,可是不能运行,可能输出格式有问题, 有懂得MT4 编程语言的高手帮个忙。


//+------------------------------------------------------------------+
//|                                     RSI.m4                                    |
//|           Copyright ?2004, MetaQuotes Software Corp. |
//|                                     http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright ?2004, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net/"

#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 100
#property indicator_buffers 3
#property indicator_color1 DodgerBlue
#property indicator_color2 Red
#property indicator_color3 Green
//---- input parameters
extern int RSIPeriod1=7;
extern int RSIPeriod2=14;
extern int RSIPeriod3=50;

//---- buffers
double PERBuffer[];
double RSIBuffer[,];
double PosBuffer[];
double NegBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                       |
//+------------------------------------------------------------------+
int init()
  {
   string short_name;
//---- 2 additional buffers are used for counting.
   IndicatorBuffers(5);
   SetIndexBuffer(1,PosBuffer);
   SetIndexBuffer(2,NegBuffer);
//---- indicator line
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,RSIBuffer[1,]);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,RSIBuffer[2,]);
   SetIndexStyle(2,DRAW_LINE);
   SetIndexBuffer(2,RSIBuffer[3,]);
   
//---- name for DataWindow and indicator subwindow label
   short_name="RSI("+RSIPeriod1+","+RSIPeriod2+","+RSIPeriod3+")";
   IndicatorShortName(short_name);
   SetIndexLabel(0,short_name);
//----
   SetIndexDrawBegin(1,RSIPeriod1);
   SetIndexDrawBegin(1,RSIPeriod2);
   SetIndexDrawBegin(1,RSIPeriod3);
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Relative Strength Index                                          |
//+------------------------------------------------------------------+
int start()
  { int i,j,RSIPeriod,counted_bars=IndicatorCounted();
   double rel,negative,positive;
  
   PERBuffer[1]=RSIPeriod1;
   PERBuffer[3]=RSIPeriod3;
   PERBuffer[2]=RSIPeriod2;
   {
  
   for(j=1;j<=3;j++)
   RSIPeriod= PERBuffer[j];
      
//----
   if(Bars<=RSIPeriod) return(0);
//---- initial zero
   if(counted_bars<1)
      for(i=1;i<=RSIPeriod;i++) RSIBuffer[j,Bars-i]=0.0;
//----
   i=Bars-RSIPeriod-1;
   if(counted_bars>=RSIPeriod) i=Bars-counted_bars-1;
   while(i>=0)
     {
      double sumn=0.0,sump=0.0;
      if(i==Bars-RSIPeriod-1)
        {
         int k=Bars-2;
         //---- initial accumulation
         while(k>=i)
           {
            rel=Close[k]-Close[k+1];
            if(rel>0) sump+=rel;
            else      sumn-=rel;
            k--;
           }
         positive=sump/RSIPeriod;
         negative=sumn/RSIPeriod;
        }
      else
        {
         //---- smoothed moving average
         rel=Close-Close[i+1];
         if(rel>0) sump=rel;
         else      sumn=-rel;
         positive=(PosBuffer[i+1]*(RSIPeriod-1)+sump)/RSIPeriod;
         negative=(NegBuffer[i+1]*(RSIPeriod-1)+sumn)/RSIPeriod;
        }
      PosBuffer=positive;
      NegBuffer=negative;
      if(negative==0.0) RSIBuffer[j,i]=0.0;
      else RSIBuffer[j,i]=100.0-100.0/(1+positive/negative);
      i--;
      }
      j--;
     }
//----
   return(0);
  }
//+------------------------------------------------------------------+

评论13

haoshayuLv.10 发表于 2005-9-12 13:34 | 查看全部
我这里测试
说有三个错误
rel=Close-Close[i+1];
回复 点赞

使用道具 举报

山野居士楼主Lv.3 发表于 2005-9-12 14:11 | 查看全部
复制的错误。应为:  rel=Close[i]-Close[i+1];
回复 点赞

使用道具 举报

啤酒开Lv.3 发表于 2005-9-12 14:18 | 查看全部
这是一个好东东
一根线确实不太好用
无他
但手熟耳
回复 点赞

使用道具 举报

haoshayuLv.10 发表于 2005-9-12 14:32 | 查看全部
现在整好了吗
回复 点赞

使用道具 举报

山野居士楼主Lv.3 发表于 2005-9-12 14:38 | 查看全部
没有呀,等你帮忙那,程序通过了,就是不出来线,气死我了。
回复 点赞

使用道具 举报

zhj0313Lv.10 发表于 2005-9-12 15:16 | 查看全部
不用那么费劲,直接在一个窗口中放置三个RSI指标自行设置参数即可,打开导航器,用鼠标左键将RSI拖入到原来的RSI窗口中,再设置颜色,参数。
回复 点赞

使用道具 举报

haoshayuLv.10 发表于 2005-9-12 15:31 | 查看全部
多谢楼上的
真的可以哦

你还知道怎么把MACD弄成2条线吗
回复 点赞

使用道具 举报

windbell99Lv.2 发表于 2005-9-12 15:54 | 查看全部

PERBuffer 没有初始化

这是第一个错误,PERBuffer根本没有初始化。因此RSIPeriod永远是零,从而引发除零错。
修改:
IndicatorBuffers(6); // add another temporary buffer
...
SetIndexBuffer(3,PERBuffer); // set it as a buffer

第二个错误就是逻辑有错误,呵呵。程序比较乱,我就不仔细看了,呵呵。你仔细研究一下 现在能够划出线,但是画在0这个位置。


原帖由 山野居士 于 2005-9-12 13:04 发表
MT的RIS  指标 只有一条线, RIS  (14)。本人已习惯了使用三条线的 RSI 指标,对此将其作了些修改,编译已经通过了,可是不能运行,可能输出格式有问题, 有懂得MT4 编程语言的高手帮个忙。


//+---------- ...
回复 点赞

使用道具 举报

山野居士楼主Lv.3 发表于 2005-9-12 16:20 | 查看全部
谢谢很好使,真有高人。
回复 点赞

使用道具 举报

回复

本版积分规则

关灯 在本版发帖
扫一扫添加微信客服
QQ客服返回顶部
快速回复 返回顶部 返回列表