欢迎使用金字塔普通技术服务论坛,您可以在相关区域发表技术支持贴。
我司技术服务人员将优先处理 VIP客服论坛 服务贴,普通区问题处理速度慢,请耐心等待。谢谢您对我们的支持与理解。


金字塔客服中心 - 专业程序化交易软件提供商金字塔软件公式模型编写问题提交 → 改编MT5中rates_total等怎么处理

   

欢迎使用金字塔普通技术服务论坛,您可以在相关区域发表技术支持贴。
我司技术服务人员将优先处理 VIP客服论坛 服务贴,普通区问题处理速度慢,请耐心等待。谢谢您对我们的支持与理解。    


  共有5096人关注过本帖树形打印复制链接

主题:改编MT5中rates_total等怎么处理

帅哥哟,离线,有人找我吗?
qwer9873
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:新手上路 帖子:4 积分:0 威望:0 精华:0 注册:2016/2/4 10:59:43
改编MT5中rates_total等怎么处理  发帖心情 Post By:2016/2/4 11:05:20    Post IP:101.81.132.229[只看该作者]

请问MT5当中的rates_total, prev_calculated,copied
改过来应该怎么处理?O(∩_∩)O谢谢

完整代码如下
//+------------------------------------------------------------------+
//|                                             TrendStrength_v2.mq5 |
//|                                Copyright ?2013, TrendLaboratory |
//|            http://finance.groups.yahoo.com/group/TrendLaboratory |
//|                                   E-mail: igorad2003@yahoo.co.uk |
//+------------------------------------------------------------------+
#property copyright "Copyright ?2013, TrendLaboratory"
#property link      "http://finance.groups.yahoo.com/group/TrendLaboratory"

//--- indicator settings
#property indicator_separate_window
#property indicator_buffers 5
#property indicator_plots   3


#property indicator_label1  "Smoothed RSI"
#property indicator_type1   DRAW_LINE
#property indicator_color1  DarkGray
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1

#property indicator_label2  "UpTrend"
#property indicator_type2   DRAW_LINE
#property indicator_color2  DeepSkyBlue
#property indicator_style2  STYLE_SOLID
#property indicator_width2  2

#property indicator_label3  "DnTrend"
#property indicator_type3   DRAW_LINE
#property indicator_color3  OrangeRed
#property indicator_style3  STYLE_SOLID
#property indicator_width3  2

//---- indicator parameters

input ENUM_APPLIED_PRICE   Price          = PRICE_CLOSE;    // Applied Price
input int                  RSILength      =          14;    // RSI Period
input int                  Smooth         =           5;    // Smoothing Period
input double               K              =       4.236;    // Multiplier


//---- indicator buffers
double smRSI[];
double upTrend[];
double dnTrend[];

double rsi[];
double trend[];

double delta1[2],delta2[2],upband[2],loband[2],alpha;
int    rsi_handle;
datetime prevTime;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,smRSI,INDICATOR_DATA);
   SetIndexBuffer(1,upTrend,INDICATOR_DATA);
   SetIndexBuffer(2,dnTrend,INDICATOR_DATA);

   SetIndexBuffer(3,rsi,INDICATOR_CALCULATIONS);
   SetIndexBuffer(4,trend,INDICATOR_CALCULATIONS);
//---
   IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1);
//--- 
   string short_name="TrendStrength_v2("+priceToString(Price)+","+(string)RSILength+","+(string)Smooth+","+DoubleToString(K,3)+")";
   IndicatorSetString(INDICATOR_SHORTNAME,short_name);
//--- sets first bar from what index will be drawn
   int begin=(int)MathMax(2,RSILength+Smooth);
   PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,begin);
   PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,begin);
   PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,begin);
//--- 
   rsi_handle=iRSI(NULL,0,RSILength,Price);
   alpha=1.0/RSILength;
//--- initialization done
  }
//+------------------------------------------------------------------+
//| TrendStrength_v2                                                 |
//+------------------------------------------------------------------+
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     &TickVolume[],
                const long     &Volume[],
                const int      &Spread[])
  {
   int shift,limit,copied=0;
   double hiRSI,loRSI,rangeRSI;
//--- preliminary calculations
   if(prev_calculated==0)
     {
      limit=RSILength+Smooth;
      ArrayInitialize(smRSI,0);
      ArrayInitialize(upTrend,0);
      ArrayInitialize(dnTrend,0);
     }
   else limit=prev_calculated-1;

   copied=CopyBuffer(rsi_handle,0,0,rates_total-1,rsi);
   if(copied<0)
     {
      Print("not all RSI copied. Will try on next tick Error =",GetLastError(),", copied =",copied);
      return(0);
     }

//--- the main loop of calculations
   for(shift=limit;shift<rates_total;shift++)
     {
      if(prevTime<Time[shift])
        {
         delta1[1] = delta1[0];
         delta2[1] = delta2[0];
         upband[1] = upband[0];
         loband[1] = loband[0];

         prevTime=Time[shift];
        }

      smRSI[shift]=smRSI[shift-1]+2./(Smooth+1)*(rsi[shift]-smRSI[shift-1]);

      if(smRSI[shift]>smRSI[shift-1]) {hiRSI=smRSI[shift]; loRSI=smRSI[shift-1];}
      else
      if(smRSI[shift]<smRSI[shift-1]) {hiRSI=smRSI[shift-1]; loRSI=smRSI[shift];}
      else
        {hiRSI=smRSI[shift]; loRSI=smRSI[shift];}

      rangeRSI=hiRSI-loRSI;

      delta1[0] = delta1[1] + alpha*(rangeRSI  - delta1[1]);
      delta2[0] = delta2[1] + alpha*(delta1[0] - delta2[1]);

      upband[0] = smRSI[shift] + K*delta2[0];
      loband[0] = smRSI[shift] - K*delta2[0];

      trend[shift]=trend[shift-1];

      if(smRSI[shift] > upband[1]) trend[shift] = 1;
      if(smRSI[shift] < loband[1]) trend[shift] =-1;

      upTrend[shift] = EMPTY_VALUE;
      dnTrend[shift] = EMPTY_VALUE;

      if(trend[shift]>0)
        {
         if(loband[0]<loband[1]) loband[0]=loband[1];
         upTrend[shift]=loband[0];
        }
      else
      if(trend[shift]<0)
        {
         if(upband[0]>upband[1]) upband[0]=upband[1];
         dnTrend[shift]=upband[0];
        }

     }
//--- done
   return(rates_total);
  }
//+------------------------------------------------------------------+
string priceToString(ENUM_APPLIED_PRICE app_price)
  {
   switch(app_price)
     {
      case PRICE_CLOSE   :    return("Close");
      case PRICE_HIGH    :    return("High");
      case PRICE_LOW     :    return("Low");
      case PRICE_MEDIAN  :    return("Median");
      case PRICE_OPEN    :    return("Open");
      case PRICE_TYPICAL :    return("Typical");
      case PRICE_WEIGHTED:    return("Weighted");
      default            :    return("");
     }
  }
//+------------------------------------------------------------------+


 回到顶部
帅哥哟,离线,有人找我吗?
jinzhe
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:罗宾汉 帖子:46311 积分:50819 威望:0 精华:2 注册:2011/3/23 8:50:25
  发帖心情 Post By:2016/2/4 11:16:07    Post IP:58.246.57.26[只看该作者]

注释一下


金字塔—专业程序化交易量化投资平台

客户服务部

----------------------------------------------------------- 欢迎您参加我公司的技术培训,具体培训需求请发邮件到service@weistock.com

您的宝贵建议或者投诉,请发往邮箱:weiwei@weistock.com

 回到顶部
帅哥哟,离线,有人找我吗?
qwer9873
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:新手上路 帖子:4 积分:0 威望:0 精华:0 注册:2016/2/4 10:59:43
  发帖心情 Post By:2016/2/4 12:38:24    Post IP:101.81.132.229[只看该作者]

首先rates_total 参数包括栏的数量,可用来计算指标,与图表中现存的栏数一致。

需要注意OnCalculate() 返回值和第二输入参数prev_calculated的连接。调用函数时,prev_calculated 参数包括上次调用时OnCalculate() 返回值。这就允许用经济算法计算自定义指标,避免重复计算。

返回rates_total参数值足够了,包括当前调用函数的栏数。如果自从上次调用函数OnCalculate(),价格数据更改了(下载深度历史记录或者填满历史空白期),输入参数prev_calculated 值由终端机设置为零。

注:如果OnCalculate返回零,那么指标值不能显示在客户端的数据窗口。

为更好的理解,启动附加以下代码的指标很有用。

指标示例:

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots   1
//---- 图的线
#property indicator_label1  "Line"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrDarkBlue
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- 指标缓冲区
double         LineBuffer[];
//+------------------------------------------------------------------+
//| 自定义指标初始化函数                                                |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- 指标缓冲区绘图
   SetIndexBuffer(0,LineBuffer,INDICATOR_DATA);
//---
   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[])
  {
//--- 获得当前交易品种和图表周期的有效柱数
   int bars=Bars(Symbol(),0);
   Print("Bars = ",bars,", rates_total = ",rates_total,",  prev_calculated = ",prev_calculated);
   Print("time[0] = ",time[0]," time[rates_total-1] = ",time[rates_total-1]);
//--- 为下次调用返回prev_calculated值
   return(rates_total);
  }
//+------------------------------------------------------------------+


 回到顶部
帅哥哟,离线,有人找我吗?
qwer9873
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:新手上路 帖子:4 积分:0 威望:0 精华:0 注册:2016/2/4 10:59:43
  发帖心情 Post By:2016/2/4 12:39:15    Post IP:101.81.132.229[只看该作者]

上面是一个例子,里面也有rates_total, prev_calculated

 回到顶部
帅哥哟,离线,有人找我吗?
jinzhe
  5楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:罗宾汉 帖子:46311 积分:50819 威望:0 精华:2 注册:2011/3/23 8:50:25
  发帖心情 Post By:2016/2/4 13:20:53    Post IP:58.246.57.26[只看该作者]

别举一个认为能说明上面代码的例子

直接注释下上面的代码



金字塔—专业程序化交易量化投资平台

客户服务部

----------------------------------------------------------- 欢迎您参加我公司的技术培训,具体培训需求请发邮件到service@weistock.com

您的宝贵建议或者投诉,请发往邮箱:weiwei@weistock.com

 回到顶部
帅哥哟,离线,有人找我吗?
qwer9873
  6楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:新手上路 帖子:4 积分:0 威望:0 精华:0 注册:2016/2/4 10:59:43
  发帖心情 Post By:2016/2/4 13:47:56    Post IP:101.81.132.229[只看该作者]

我不懂啊,注释不来啊,帮忙耐心看看,O(∩_∩)O谢谢

 回到顶部
帅哥哟,离线,有人找我吗?
jinzhe
  7楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:罗宾汉 帖子:46311 积分:50819 威望:0 精华:2 注册:2011/3/23 8:50:25
  发帖心情 Post By:2016/2/4 14:07:19    Post IP:58.246.57.26[只看该作者]

那这个我们也没办法,我们不是MT5,你需要找MT5的人解释下上面的代码


金字塔—专业程序化交易量化投资平台

客户服务部

----------------------------------------------------------- 欢迎您参加我公司的技术培训,具体培训需求请发邮件到service@weistock.com

您的宝贵建议或者投诉,请发往邮箱:weiwei@weistock.com

 回到顶部