2025yao 发表于 2025-12-22 15:12:10

03 指标框架多周期显示在一个图表上

//+------------------------------------------------------------------+
//|                                                      多周期均线指标.mq4 |
//|                                  Copyright 2024, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2024, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_plots   3
//--- plot 大周期
#property indicator_label1"大周期"
#property indicator_type1   DRAW_LINE
#property indicator_color1clrRed
#property indicator_style1STYLE_SOLID
#property indicator_width11
//--- plot 中周期
#property indicator_label2"中周期"
#property indicator_type2   DRAW_LINE
#property indicator_color2clrMediumSpringGreen
#property indicator_style2STYLE_SOLID
#property indicator_width21
//--- plot 小周期
#property indicator_label3"小周期"
#property indicator_type3   DRAW_LINE
#property indicator_color3clrYellow
#property indicator_style3STYLE_SOLID
#property indicator_width31
//--- indicator buffers
double         大周期Buffer[];
double         中周期Buffer[];
double         小周期Buffer[];

input ENUM_TIMEFRAMES 大时间周期设置=PERIOD_D1;
input ENUM_TIMEFRAMES 中时间周期设置=PERIOD_H4;
input ENUM_TIMEFRAMES 小时间周期设置=PERIOD_H1;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
   SetIndexBuffer(0,大周期Buffer);
   SetIndexBuffer(1,中周期Buffer);
   SetIndexBuffer(2,小周期Buffer);

//---
   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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[])
{
//---
if(Period()!=小时间周期设置)
{
Print("加载时间周期不对,请重试");
return(rates_total);
}
for(int i=0;i<rates_total;i++)
    {

   小周期Buffer=iMA(Symbol(),小时间周期设置,43,0,MODE_EMA,PRICE_CLOSE,i);
    }
for(int i=0;i<rates_total;i++)
    {
   if(iBarShift(Symbol(),中时间周期设置,iTime(Symbol(),小时间周期设置,i),true)==-1)

       {
      break;
       }
       //1小时图表的K线序号对应的4小时图表上的K线序号
       //iBarShift这个函数时通过时间来找到包含这个时间的K线序号
      中周期Buffer=iMA(Symbol(),中时间周期设置,34,0,
      MODE_EMA,PRICE_CLOSE,iBarShift(Symbol(),中时间周期设置,iTime(Symbol(),小时间周期设置,i),true));   
    }
    //把日线的均线指标值映射到1小时图表上显示
    for(int i=0;i<rates_total;i++)
    {
   if(iBarShift(Symbol(),中时间周期设置,iTime(Symbol(),小时间周期设置,i),true)==-1)


      中周期Buffer=iMA(Symbol(),中时间周期设置,34,0,
      MODE_EMA,PRICE_CLOSE,iBarShift(Symbol(),中时间周期设置,iTime(Symbol(),小时间周期设置,i),true));   
    }

//--- return value of prev_calculated for next call
   return(rates_total);
}
//+------------------------------------------------------------------+

痴墨鼠 发表于 2026-1-31 13:19:13

感谢楼主分享,这个思路不错

xinhua123 发表于 2026-2-13 01:06:09

很好的学习了

Yangyedong 发表于 2026-3-29 15:47:14

,可以的

zhq320 发表于 2026-4-13 19:39:14

思路是很不错的,不知道用的实盘效果怎么样?

zhq320 发表于 2026-4-15 22:43:29

思路可以,实盘应该可以赚

marco699 发表于 2026-4-18 11:26:29

实盘加仓,爆赚翻倍

Hdkndh 发表于 2026-4-24 13:19:38

牛 这个厉害 我可以用用反馈

825541268 发表于 2026-4-27 15:39:41

思路可以,实盘应该可以赚,思路是很不错的,不知道用的实盘效果怎么样?

1183802138 发表于 2026-4-28 19:13:52

这个思路不错

xinhua123 发表于 2026-6-30 00:56:01

多周期显示

dzw199331 发表于 2026-6-30 12:08:55

可以研究下考虑下

fjszph 发表于 2026-7-3 22:44:23

有图片就好了

更胜一期 发表于 2026-7-4 18:50:24

思路不错。接下来怎么应用比较好?
页: [1]
查看完整版本: 03 指标框架多周期显示在一个图表上