设为首页 收藏本站 切换语言 切换语言

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

| 发表于 昨天 15:12 | 显示全部楼层 |复制链接
//+------------------------------------------------------------------+
//|                                                      多周期均线指标.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_color1  clrRed
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- plot 中周期
#property indicator_label2  "中周期"
#property indicator_type2   DRAW_LINE
#property indicator_color2  clrMediumSpringGreen
#property indicator_style2  STYLE_SOLID
#property indicator_width2  1
//--- plot 小周期
#property indicator_label3  "小周期"
#property indicator_type3   DRAW_LINE
#property indicator_color3  clrYellow
#property indicator_style3  STYLE_SOLID
#property indicator_width3  1
//--- 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[i]=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[i]=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[i]=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);
  }
//+------------------------------------------------------------------+


举报

评论 使用道具

发新帖
EA交易
您需要登录后才可以评论 登录 | 立即注册

 简体中文国旗 简体中文
 繁體中文国旗 繁體中文
 English国旗 English(英语)
 日本語国旗 日本語(日语)
 Deutsch国旗 Deutsch(德语)
 Русский язык国旗 Русский язык(俄语)
 بالعربية国旗 بالعربية(阿拉伯语)
 Türkçe国旗 Türkçe(土耳其语)
 Português国旗 Português(葡萄牙语)
 ภาษาไทย国旗 ภาษาไทย(泰国语)
 한어国旗 한어(朝鲜语/韩语)
 Français国旗 Français(法语)
翻译