//+------------------------------------------------------------------+
//| 01-马丁.mq5 |
//| Copyright 2025, MetaQuotes Ltd. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2025, MetaQuotes Ltd."
#property link "https://www.mql5.com"
#property version "1.00"
//显示在主窗口上
#property indicator_chart_window
//绘制缓冲数组的数量2
#property indicator_buffers 2
//绘制的属性为2
#property indicator_plots 2
//缓冲数组的意思:存储某个绘制属性的具体指标的值,而且每根k线都有指标值
//--- plot 线1
#property indicator_label1 "线1"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrRed
#property indicator_style1 STYLE_SOLID
#property indicator_width1 1
//--- plot 线2
#property indicator_label2 "线2"
#property indicator_type2 DRAW_LINE
#property indicator_color2 clrMediumSpringGreen
#property indicator_style2 STYLE_SOLID
#property indicator_width2 1
//--- indicator buffers
//动态数组:元素的个数不确定
//存储的时每根k线对应的指标值
double 线1Buffer[];
double 线2Buffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
//指标开发的事件处理程序
int OnInit()
{
//--- indicator buffers mapping
//给缓冲数组规定元素的个数,然后让缓冲数组的元素个数随着k线的数量的增加而动态变化
SetIndexBuffer(0,线1Buffer,INDICATOR_DATA);
SetIndexBuffer(1,线2Buffer,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[])
{
/*
//---ATR画止损止盈。1.5倍
for(int i=0;i<rates_total;i++)
{
线1Buffer[i]=close[i]+1.5*iATR(Symbol(),PERIOD_CURRENT,21,i);
线2Buffer[i]=close[i]-1.5*iATR(Symbol(),PERIOD_CURRENT,21,i);
}
*/
int jishu=0;
if(prev_calculated==0)
{
jishu=rates_total;
if(prev_calculated>0)
{
jishu=rates_total-prev_calculated+1;
}
}
for(int i=0; i<jishu; i++)
{
线1Buffer[i]=close[i]+1.2*iATR(Symbol(),0,21,i);
线2Buffer[i]=close[i]+1.2*iATR(Symbol(),0,21,i);
}
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
|