初学者问一个关于MQL4与MQL5如何选择的问题 - 页 3 123 新评论 Yit Fatt Choo 2022.09.21 05:04 #21 各位大大 我(新人)最近写着一个指标,问题不难, 但是,当我要把里面的两个指标分开两个“窗口” 如: 主窗口 要两个MA线 副窗口 要两个RSI线 要怎样写,才能把一个指标, “分出两个窗口?” 这个是可能的吗? 我是在mql4写作业的 #property strict #property indicator_separate_window #property indicator_buffers 6 #property indicator_plots 6 //--- plot ma1line #property indicator_label1 "ma1line" #property indicator_type1 DRAW_LINE #property indicator_color1 clrRed #property indicator_style1 STYLE_SOLID #property indicator_width1 1 //--- plot ma2line #property indicator_label2 "ma2line" #property indicator_type2 DRAW_LINE #property indicator_color2 clrPeachPuff #property indicator_style2 STYLE_SOLID #property indicator_width2 1 //--- plot rsi1line #property indicator_label3 "rsi1line" #property indicator_type3 DRAW_LINE #property indicator_color3 clrRed #property indicator_style3 STYLE_SOLID #property indicator_width3 1 //--- plot rsi2line #property indicator_label4 "rsi2line" #property indicator_type4 DRAW_LINE #property indicator_color4 clrPeachPuff #property indicator_style4 STYLE_SOLID #property indicator_width4 1 //--- plot upArrow #property indicator_label5 "upArrow" #property indicator_type5 DRAW_ARROW #property indicator_color5 clrRed #property indicator_style5 STYLE_SOLID #property indicator_width5 1 //--- plot downArrow #property indicator_label6 "downArrow" #property indicator_type6 DRAW_ARROW #property indicator_color6 clrPeachPuff #property indicator_style6 STYLE_SOLID #property indicator_width6 1 //--- input parameters input double rsi1line=25.0; input double rsi2line=100.0; input double ma1line=25.0; input double ma2line=200.0; //--- indicator buffers double ma1lineBuffer[]; double ma2lineBuffer[]; double rsi1lineBuffer[]; double rsi2lineBuffer[]; double upArrowBuffer[]; double downArrowBuffer[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping SetIndexBuffer(0,ma1lineBuffer); SetIndexBuffer(1,ma2lineBuffer); SetIndexBuffer(2,rsi1lineBuffer); SetIndexBuffer(3,rsi2lineBuffer); SetIndexBuffer(4,upArrowBuffer); SetIndexBuffer(5,downArrowBuffer); //--- setting a code from the Wingdings charset as the property of PLOT_ARROW PlotIndexSetInteger(4,PLOT_ARROW,159); PlotIndexSetInteger(5,PLOT_ARROW,159); //--- 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(rates_total<rsi1line||rates_total<rsi2line||rates_total<ma1line || rates_total<ma2line) { return(0); } { int i,limit; limit=rates_total-prev_calculated; if(prev_calculated>0) limit++; for(i=0; i<limit; i++) { ma1lineBuffer[i]=iMA(NULL,0,ma1line,0,MODE_SMA,PRICE_CLOSE,i); ma2lineBuffer[i]=iMA(NULL,0,ma2line,0,MODE_SMA,PRICE_CLOSE,i); } for(i=0; i<limit; i++) { rsi1lineBuffer[i]=iRSI(NULL,0,rsi1line,PRICE_CLOSE,i); rsi2lineBuffer[i]=iRSI(NULL,0,rsi2line,PRICE_CLOSE,i); } } //--- return value of prev_calculated for next call return(rates_total); } 附加的文件: RSI2lineMA2line.mq4 5 kb 新人对MQL4和MQL5的任何问题,对算法和代码的帮助和讨论 求助,用MT5编程。分配4个数组,为什么只有3个数组有数据? 初学者的问题 MQL5 MT5 MetaTrader 123 新评论 您错过了交易机会: 免费交易应用程序 8,000+信号可供复制 探索金融市场的经济新闻 注册 登录 拉丁字符(不带空格) 密码将被发送至该邮箱 发生错误 使用 Google 登录 您同意网站政策和使用条款 如果您没有帐号,请注册 可以使用cookies登录MQL5.com网站。 请在您的浏览器中启用必要的设置,否则您将无法登录。 忘记您的登录名/密码? 使用 Google 登录
我是在mql4写作业的
#property strict
#property indicator_separate_window
#property indicator_buffers 6
#property indicator_plots 6
//--- plot ma1line
#property indicator_label1 "ma1line"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrRed
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
//--- plot ma2line
#property indicator_label2 "ma2line"
#property indicator_type2 DRAW_LINE
#property indicator_color2 clrPeachPuff
#property indicator_style2 STYLE_SOLID
#property indicator_width2 1
//--- plot rsi1line
#property indicator_label3 "rsi1line"
#property indicator_type3 DRAW_LINE
#property indicator_color3 clrRed
#property indicator_style3 STYLE_SOLID
#property indicator_width3 1
//--- plot rsi2line
#property indicator_label4 "rsi2line"
#property indicator_type4 DRAW_LINE
#property indicator_color4 clrPeachPuff
#property indicator_style4 STYLE_SOLID
#property indicator_width4 1
//--- plot upArrow
#property indicator_label5 "upArrow"
#property indicator_type5 DRAW_ARROW
#property indicator_color5 clrRed
#property indicator_style5 STYLE_SOLID
#property indicator_width5 1
//--- plot downArrow
#property indicator_label6 "downArrow"
#property indicator_type6 DRAW_ARROW
#property indicator_color6 clrPeachPuff
#property indicator_style6 STYLE_SOLID
#property indicator_width6 1
//--- input parameters
input double rsi1line=25.0;
input double rsi2line=100.0;
input double ma1line=25.0;
input double ma2line=200.0;
//--- indicator buffers
double ma1lineBuffer[];
double ma2lineBuffer[];
double rsi1lineBuffer[];
double rsi2lineBuffer[];
double upArrowBuffer[];
double downArrowBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,ma1lineBuffer);
SetIndexBuffer(1,ma2lineBuffer);
SetIndexBuffer(2,rsi1lineBuffer);
SetIndexBuffer(3,rsi2lineBuffer);
SetIndexBuffer(4,upArrowBuffer);
SetIndexBuffer(5,downArrowBuffer);
//--- setting a code from the Wingdings charset as the property of PLOT_ARROW
PlotIndexSetInteger(4,PLOT_ARROW,159);
PlotIndexSetInteger(5,PLOT_ARROW,159);
//---
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(rates_total<rsi1line||rates_total<rsi2line||rates_total<ma1line || rates_total<ma2line)
{
return(0);
}
{
int i,limit;
limit=rates_total-prev_calculated;
if(prev_calculated>0)
limit++;
for(i=0; i<limit; i++)
{
ma1lineBuffer[i]=iMA(NULL,0,ma1line,0,MODE_SMA,PRICE_CLOSE,i);
ma2lineBuffer[i]=iMA(NULL,0,ma2line,0,MODE_SMA,PRICE_CLOSE,i);
}
for(i=0; i<limit; i++)
{
rsi1lineBuffer[i]=iRSI(NULL,0,rsi1line,PRICE_CLOSE,i);
rsi2lineBuffer[i]=iRSI(NULL,0,rsi2line,PRICE_CLOSE,i);
}
}
//--- return value of prev_calculated for next call
return(rates_total);
}