- 注册时间
- 2013-9-23
- 在线时间
- 519 小时
- 最后登录
- 2022-4-4
- 阅读权限
- 200
管理员
MT4软件工程师
- 积分
- 6521
- 帖子
- 2771
- 主题
- 2761
|
MT4智能交易编程示例 Momentum指标- #property copyright "路路发智能交易研发中心"
- #property link "http://www.ea668.com"
- #property description "Momentum"
- #property strict
- #property indicator_separate_window
- #property indicator_buffers 1
- #property indicator_color1 DodgerBlue
- //--- input parameter
- input int InpMomPeriod=14; // Momentum Period
- //--- buffers
- double ExtMomBuffer[];
- //+------------------------------------------------------------------+
- //| Custom indicator initialization function |
- //+------------------------------------------------------------------+
- int OnInit(void)
- {
- string short_name;
- //--- indicator line
- SetIndexStyle(0,DRAW_LINE);
- SetIndexBuffer(0,ExtMomBuffer);
- //--- name for DataWindow and indicator subwindow label
- short_name="Mom("+IntegerToString(InpMomPeriod)+")";
- IndicatorShortName(short_name);
- SetIndexLabel(0,short_name);
- //--- check for input parameter
- if(InpMomPeriod<=0)
- {
- Print("Wrong input parameter Momentum Period=",InpMomPeriod);
- return(INIT_FAILED);
- }
- //---
- SetIndexDrawBegin(0,InpMomPeriod);
- //--- initialization done
- return(INIT_SUCCEEDED);
- }
- //+------------------------------------------------------------------+
- //| Momentum |
- //+------------------------------------------------------------------+
- 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 i,limit;
- //--- check for bars count and input parameter
- if(rates_total<=InpMomPeriod || InpMomPeriod<=0)
- return(0);
- //--- counting from 0 to rates_total
- ArraySetAsSeries(ExtMomBuffer,false);
- ArraySetAsSeries(close,false);
- //--- initial zero
- if(prev_calculated<=0)
- {
- for(i=0; i<InpMomPeriod; i++)
- ExtMomBuffer[i]=0.0;
- limit=InpMomPeriod;
- }
- else
- limit=prev_calculated-1;
- //--- the main loop of calculations
- for(i=limit; i<rates_total; i++)
- ExtMomBuffer[i]=close[i]*100/close[i-InpMomPeriod];
- //--- done
- return(rates_total);
- }
- //+------------------------------------------------------------------+
复制代码
|
|