关于使用MT5进行跨周期时,ima无法获取跨周期信息的问题 新评论 FreshBird 2022.04.17 12:52 使用以下代码,当TimeFrame不为当前周期时,例如当前周期为30M,但是TimeFrame取值不为30M的时候,后面调试起来slow2的值全部为0,这是为什么呢? //+------------------------------------------------------------------+ //| cross cycle.mq5 | //| Copyright 2022, MetaQuotes Ltd. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2022, MetaQuotes Ltd." #property link "https://www.mql5.com" #property version "1.00" #property indicator_chart_window #property indicator_buffers 2 #property indicator_plots 2 //--- plot slow #property indicator_label1 "slow" #property indicator_type1 DRAW_LINE #property indicator_color1 clrRed #property indicator_style1 STYLE_SOLID #property indicator_width1 1 //--- plot fast #property indicator_label2 "fast" #property indicator_type2 DRAW_LINE #property indicator_color2 clrYellow #property indicator_style2 STYLE_SOLID #property indicator_width2 1 //--- input parameters input ENUM_TIMEFRAMES TimeFrame = PERIOD_H1; input int slow=5; input int fast=15; input int K线根数=3000; //--- indicator buffers double slowBuffer[]; double fastBuffer[]; int slow_h; int fast_h; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping slow_h = iMA(NULL,TimeFrame,slow,0,0,PRICE_CLOSE); //将大周期的MA存入 fast_h = iMA(NULL,TimeFrame,fast,0,0,PRICE_CLOSE); //存在Bug,跨周期数据无法获取 ArraySetAsSeries(slowBuffer,true); ArraySetAsSeries(fastBuffer,true); SetIndexBuffer(0,slowBuffer,INDICATOR_DATA); SetIndexBuffer(1,fastBuffer,INDICATOR_DATA); //--- 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[]) { //--- //--- return value of prev_calculated for next call double slow2[]; ArraySetAsSeries(slow2,true); CopyBuffer(slow_h,0,0,rates_total,slow2); double fast2[]; ArraySetAsSeries(fast2,true); CopyBuffer(fast_h,0,0,rates_total,fast2); datetime timeda[]; ArraySetAsSeries(timeda,true); CopyTime(NULL,TimeFrame,0,rates_total,timeda); ArraySetAsSeries(time,true); int y = 0; for(int i=0; i < K线根数; i++) { if(time[i]<timeda[y]) y++; //根据大小周期的时间来对K线进行对应 slowBuffer[i] = slow2[y]; fastBuffer[i] = fast2[y]; } int bbb = 1; return(rates_total); } //+------------------------------------------------------------------+ Discover new MetaTrader 5 opportunities with MQL5 community and services 2022.04.17www.mql5.com MQL5: language of trade strategies built-in the MetaTrader 5 Trading Platform, allows writing your own trading robots, technical indicators, scripts and libraries of functions 初学者的问题 MQL5 MT5 MetaTrader 5 求助,用MT5编程。分配4个数组,为什么只有3个数组有数据? 我将免费编写指标 新评论 您错过了交易机会: 免费交易应用程序 8,000+信号可供复制 探索金融市场的经济新闻 注册 登录 拉丁字符(不带空格) 密码将被发送至该邮箱 发生错误 使用 Google 登录 您同意网站政策和使用条款 如果您没有帐号,请注册 可以使用cookies登录MQL5.com网站。 请在您的浏览器中启用必要的设置,否则您将无法登录。 忘记您的登录名/密码? 使用 Google 登录
使用以下代码,当TimeFrame不为当前周期时,例如当前周期为30M,但是TimeFrame取值不为30M的时候,后面调试起来slow2的值全部为0,这是为什么呢?
//+------------------------------------------------------------------+
//| cross cycle.mq5 |
//| Copyright 2022, MetaQuotes Ltd. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2022, MetaQuotes Ltd."
#property link "https://www.mql5.com"
#property version "1.00"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots 2
//--- plot slow
#property indicator_label1 "slow"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrRed
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
//--- plot fast
#property indicator_label2 "fast"
#property indicator_type2 DRAW_LINE
#property indicator_color2 clrYellow
#property indicator_style2 STYLE_SOLID
#property indicator_width2 1
//--- input parameters
input ENUM_TIMEFRAMES TimeFrame = PERIOD_H1;
input int slow=5;
input int fast=15;
input int K线根数=3000;
//--- indicator buffers
double slowBuffer[];
double fastBuffer[];
int slow_h;
int fast_h;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
slow_h = iMA(NULL,TimeFrame,slow,0,0,PRICE_CLOSE); //将大周期的MA存入
fast_h = iMA(NULL,TimeFrame,fast,0,0,PRICE_CLOSE); //存在Bug,跨周期数据无法获取
ArraySetAsSeries(slowBuffer,true);
ArraySetAsSeries(fastBuffer,true);
SetIndexBuffer(0,slowBuffer,INDICATOR_DATA);
SetIndexBuffer(1,fastBuffer,INDICATOR_DATA);
//---
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[])
{
//---
//--- return value of prev_calculated for next call
double slow2[];
ArraySetAsSeries(slow2,true);
CopyBuffer(slow_h,0,0,rates_total,slow2);
double fast2[];
ArraySetAsSeries(fast2,true);
CopyBuffer(fast_h,0,0,rates_total,fast2);
datetime timeda[];
ArraySetAsSeries(timeda,true);
CopyTime(NULL,TimeFrame,0,rates_total,timeda);
ArraySetAsSeries(time,true);
int y = 0;
for(int i=0; i < K线根数; i++)
{
if(time[i]<timeda[y]) y++; //根据大小周期的时间来对K线进行对应
slowBuffer[i] = slow2[y];
fastBuffer[i] = fast2[y];
}
int bbb = 1;
return(rates_total);
}
//+------------------------------------------------------------------+