- 显示:
- 438
- 等级:
- 已发布:
-
需要基于此代码的EA交易或指标吗?请在自由职业者服务中订购 进入自由职业者服务
MetaTrader 5 布林线指标中的标准移动平均线方法只提供 "简单 "方法,我开发这个指标的目的是提供一种替代方法。使用我的指标,用户可以选择其他方法,包括指数法、平滑法和线性加权法。
要使用该指标,需要将其放置在类似以下路径的目录中(在 Windows 下):
C:\Users\lucas\AppData\Roaming\MetaQuotes\Terminal\Indicators\Examples
新增功能:

默认设置为零:

选择线性加权平均值的执行示例:
代码
//+------------------------------------------------------------------+ //|BBPersonalizada.mq5 //|卢卡斯-维达尔 //|https://www.mql5.com | | //+------------------------------------------------------------------+ #property copyright "Lucas Vidal" #property link "https://www.mql5.com/zh/users/lucasmoura00" #property description "Bollinger Bands Personalizada" #include <MovingAverages.mqh> //--- #property indicator_chart_window #property indicator_buffers 4 #property indicator_plots 3 #property indicator_type1 DRAW_LINE #property indicator_color1 LightSeaGreen #property indicator_type2 DRAW_LINE #property indicator_color2 LightSeaGreen #property indicator_type3 DRAW_LINE #property indicator_color3 LightSeaGreen #property indicator_label1 "Bands middle" #property indicator_label2 "Bands upper" #property indicator_label3 "Bands lower" //--- 输入参数 enum MovingAverageMethod { Simple, // 0 Exponential, // 1 Smoothed, // 2 LinearWeighted // 3 }; input MovingAverageMethod InpMaMethod = Simple; // Média Móvel 方法 input int InpBandsPeriod=20; // 期间 input int InpBandsShift=0; // 移位 input double InpBandsDeviations=2.0; // 偏差 //--- 全局变量 int ExtBandsPeriod,ExtBandsShift; double ExtBandsDeviations; int ExtPlotBegin=0; //--- 指示器缓冲区 double ExtMLBuffer[]; double ExtTLBuffer[]; double ExtBLBuffer[]; double ExtStdDevBuffer[]; //+------------------------------------------------------------------+ //| 自定义指示器初始化函数 //+------------------------------------------------------------------+ void OnInit() { //--- 检查输入值 if(InpBandsPeriod<2) { ExtBandsPeriod=20; PrintFormat("Incorrect value for input variable InpBandsPeriod=%d. Indicator will use value=%d for calculations.",InpBandsPeriod,ExtBandsPeriod); } else ExtBandsPeriod=InpBandsPeriod; if(InpBandsShift<0) { ExtBandsShift=0; PrintFormat("Incorrect value for input variable InpBandsShift=%d. Indicator will use value=%d for calculations.",InpBandsShift,ExtBandsShift); } else ExtBandsShift=InpBandsShift; if(InpBandsDeviations==0.0) { ExtBandsDeviations=2.0; PrintFormat("Incorrect value for input variable InpBandsDeviations=%f. Indicator will use value=%f for calculations.",InpBandsDeviations,ExtBandsDeviations); } else ExtBandsDeviations=InpBandsDeviations; //--- 定义缓冲区 SetIndexBuffer(0,ExtMLBuffer); SetIndexBuffer(1,ExtTLBuffer); SetIndexBuffer(2,ExtBLBuffer); SetIndexBuffer(3,ExtStdDevBuffer,INDICATOR_CALCULATIONS); //--- 设置索引标签 PlotIndexSetString(0,PLOT_LABEL,"Bands("+string(ExtBandsPeriod)+") Middle"); PlotIndexSetString(1,PLOT_LABEL,"Bands("+string(ExtBandsPeriod)+") Upper"); PlotIndexSetString(2,PLOT_LABEL,"Bands("+string(ExtBandsPeriod)+") Lower"); //--- 指标名称 IndicatorSetString(INDICATOR_SHORTNAME,"Bollinger Bands"); //--- 索引绘制开始设置 ExtPlotBegin=ExtBandsPeriod-1; PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtBandsPeriod); PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,ExtBandsPeriod); PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,ExtBandsPeriod); //--- 索引移位设置 PlotIndexSetInteger(0,PLOT_SHIFT,ExtBandsShift); PlotIndexSetInteger(1,PLOT_SHIFT,ExtBandsShift); PlotIndexSetInteger(2,PLOT_SHIFT,ExtBandsShift); //--- 指标值的位数 IndicatorSetInteger(INDICATOR_DIGITS,_Digits+1); } //+------------------------------------------------------------------+ //| 计算移动平均值| //+------------------------------------------------------------------+ double CalculateMovingAverage(int position, int period, const double &price[]) { switch(InpMaMethod) { case Simple: return SimpleMA(position, period, price); case Exponential: // Corrigindo a chamada da função iMA com os parâmetros corretos return iMA(NULL, 0, period, 0, MODE_EMA, PRICE_CLOSE); case Smoothed: // 在此处执行您的 SMMA 功能 break; case LinearWeighted: return LinearWeightedMA(position, period, price); } return 0; // Retorno padrão em caso de método indefinido } //+------------------------------------------------------------------+ //| 布林线| //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const int begin, const double &price[]) { if(rates_total<ExtPlotBegin) return(0); //---索引绘制开始设置,当我们收到先前的开始设置时 if(ExtPlotBegin!=ExtBandsPeriod+begin) { ExtPlotBegin=ExtBandsPeriod+begin; PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtPlotBegin); PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,ExtPlotBegin); PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,ExtPlotBegin); } //--- 开始计算 int pos; if(prev_calculated>1) pos=prev_calculated-1; else pos=0; //--- 主循环 for(int i=pos; i<rates_total && !IsStopped(); i++) { //--- 中间线 ExtMLBuffer[i]=CalculateMovingAverage(i, ExtBandsPeriod, price); //--- 计算并写下 StdDev ExtStdDevBuffer[i]=StdDev_Func(i,price,ExtMLBuffer,ExtBandsPeriod); //--- 上一行 ExtTLBuffer[i]=ExtMLBuffer[i]+ExtBandsDeviations*ExtStdDevBuffer[i]; //--- 下一行 ExtBLBuffer[i]=ExtMLBuffer[i]-ExtBandsDeviations*ExtStdDevBuffer[i]; } //--- OnCalculate 完成。返回新的 prev_calculated。 return(rates_total); } //+------------------------------------------------------------------+ //| 计算标准偏差| //+------------------------------------------------------------------+ double StdDev_Func(const int position,const double &price[],const double &ma_price[],const int period) { double std_dev=0.0; //-- 计算标准差 if(position>=period) { for(int i=0; i<period; i++) std_dev+=MathPow(price[position-i]-ma_price[position],2.0); std_dev=MathSqrt(std_dev/period); } //--- 返回计算值 return(std_dev); } //+------------------------------------------------------------------+
由MetaQuotes Ltd译自英文
原代码: https://www.mql5.com/en/code/49464
Geometric Moving Average
几何移动平均法的 MQL5 版本。
Get Nth Active Trade from the end in MT5
该 EA 将扫描所有未结交易,然后打印从末尾开始的第 n 笔交易
OHLC Candles with Ask and Bid
将卖出价和买入价与蜡烛图的最高价和最低价连接起来的蜡烛图
简单的三内图案_EA
当价格形成 "Three From Within "形态时进行交易的简单智能交易系统。

