//+------------------------------------------------------------------+
//| TestCopyBuffer3.mq5 |
//| Copyright 2009, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
//#property indicator_separate_window
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots 1
//---- 图 MA
#property indicator_label1 "MA"
#property indicator_type1 DRAW_SECTION
#property indicator_color1 clrRed
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
//--- 输入参量
input bool AsSeries=true;
input int period=15;
input ENUM_MA_METHOD smootMode=MODE_EMA;
input ENUM_APPLIED_PRICE price=PRICE_CLOSE;
input int shift=0;
//--- 指标缓冲区
double MABuffer[];
int ma_handle;
//+------------------------------------------------------------------+
//| 自定义指标初始化函数 |
//+------------------------------------------------------------------+
int OnInit()
{
//--- 指标缓冲区绘图
SetIndexBuffer(0,MABuffer,INDICATOR_DATA);
Print("Parameter AsSeries = ",AsSeries);
Print("Indicator buffer after SetIndexBuffer() is a timeseries = ",
ArrayGetAsSeries(MABuffer));
//--- 设置短小的指标名称
IndicatorSetString(INDICATOR_SHORTNAME,"MA("+period+")"+AsSeries);
//--- 设置 AsSeries(依据输入参量)
ArraySetAsSeries(MABuffer,AsSeries);
Print("Indicator buffer after ArraySetAsSeries(MABuffer,true); is a timeseries = ",
ArrayGetAsSeries(MABuffer));
//---
PlotIndexSetDouble(0,PLOT_EMPTY_VALUE,0.0);
ma_handle = iCustom(NULL, 0, "Examples\\ZigZag", 12, 5, 3);
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| 自定义指标重复函数 |
//+------------------------------------------------------------------+
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(BarsCalculated(ma_handle)<rates_total) return(0);
//--- 不复制所有数据
if(CopyBuffer(ma_handle,0,0,rates_total,MABuffer)<=0) return(0);
//--- 为下次调用返回prev_calculated值
return(rates_total);
}
//+------------------------------------------------------------------+
调用ZigZag显示
最新推荐文章于 2025-10-26 21:35:32 发布
1065

被折叠的 条评论
为什么被折叠?



