如何把Lab3Buffer[i]画出来一条直线 新评论 lly221 2022.09.28 11:06 //+------------------------------------------------------------------+//| 第二指标.mq4 |//| Copyright 2022, MetaQuotes Software Corp. |//| https://www.mql5.com |//+------------------------------------------------------------------+#property copyright "Copyright 2022, MetaQuotes Software Corp."#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 Lab1#property indicator_label1 "Lab1"#property indicator_type1 DRAW_LINE#property indicator_color1 clrPaleGreen#property indicator_style1 STYLE_SOLID#property indicator_width1 1//--- plot Lab2#property indicator_label2 "Lab2"#property indicator_type2 DRAW_LINE#property indicator_color2 clrRed#property indicator_style2 STYLE_SOLID#property indicator_width2 1//--- plot Lab3#property indicator_label3 "Lab3"#property indicator_type3 DRAW_LINE#property indicator_color3 clrRed#property indicator_style3 STYLE_SOLID#property indicator_width3 1//--- indicator buffersdouble Lab1Buffer[];double Lab2Buffer[];double Lab3Buffer[];//+------------------------------------------------------------------+//| Custom indicator initialization function |//+------------------------------------------------------------------+int OnInit() {//--- indicator buffers mapping SetIndexBuffer(0,Lab1Buffer); SetIndexBuffer(1,Lab2Buffer); SetIndexBuffer(2,Lab3Buffer); //--- 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[]) { int limit = rates_total - prev_calculated; if(limit == 0) limit++; for(int i = 0; i < limit; i++) { Lab1Buffer[i] = iMA(Symbol(), PERIOD_CURRENT, 10, 0, MODE_SMA, PRICE_CLOSE, i); Lab2Buffer[i] = iMA(Symbol(), PERIOD_CURRENT, 20, 0, MODE_SMA, PRICE_CLOSE, i); } for(int i = 0; i < limit; i++) { if(Lab1Buffer[i] > Lab2Buffer[i] && Lab1Buffer[i+1]<Lab2Buffer[i+1]) { Lab3Buffer[i] =Lab2Buffer[i]; } else if(Lab1Buffer[i]<Lab2Buffer[i] && Lab1Buffer[i+1]>Lab2Buffer[i+1]) { Lab3Buffer[i] = Lab2Buffer[i]; } } return(rates_total); } Discover new MetaTrader 5 opportunities with MQL5 community and services 2022.09.28www.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个数组有数据? 指标永远比图表慢几个bar 新评论 您错过了交易机会: 免费交易应用程序 8,000+信号可供复制 探索金融市场的经济新闻 注册 登录 拉丁字符(不带空格) 密码将被发送至该邮箱 发生错误 使用 Google 登录 您同意网站政策和使用条款 如果您没有帐号,请注册 可以使用cookies登录MQL5.com网站。 请在您的浏览器中启用必要的设置,否则您将无法登录。 忘记您的登录名/密码? 使用 Google 登录
//| 第二指标.mq4 |
//| Copyright 2022, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2022, MetaQuotes Software Corp."
#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 Lab1
#property indicator_label1 "Lab1"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrPaleGreen
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
//--- plot Lab2
#property indicator_label2 "Lab2"
#property indicator_type2 DRAW_LINE
#property indicator_color2 clrRed
#property indicator_style2 STYLE_SOLID
#property indicator_width2 1
//--- plot Lab3
#property indicator_label3 "Lab3"
#property indicator_type3 DRAW_LINE
#property indicator_color3 clrRed
#property indicator_style3 STYLE_SOLID
#property indicator_width3 1
//--- indicator buffers
double Lab1Buffer[];
double Lab2Buffer[];
double Lab3Buffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,Lab1Buffer);
SetIndexBuffer(1,Lab2Buffer);
SetIndexBuffer(2,Lab3Buffer);
//---
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[])
{
int limit = rates_total - prev_calculated;
if(limit == 0) limit++;
for(int i = 0; i < limit; i++) {
Lab1Buffer[i] = iMA(Symbol(), PERIOD_CURRENT, 10, 0, MODE_SMA, PRICE_CLOSE, i);
Lab2Buffer[i] = iMA(Symbol(), PERIOD_CURRENT, 20, 0, MODE_SMA, PRICE_CLOSE, i);
}
for(int i = 0; i < limit; i++) {
if(Lab1Buffer[i] > Lab2Buffer[i] && Lab1Buffer[i+1]<Lab2Buffer[i+1]) {
Lab3Buffer[i] =Lab2Buffer[i];
}
else if(Lab1Buffer[i]<Lab2Buffer[i] && Lab1Buffer[i+1]>Lab2Buffer[i+1]) {
Lab3Buffer[i] = Lab2Buffer[i];
}
}
return(rates_total);
}