# 有关绘制MA线的几个问题(新手入门)

https://www.cnblogs.com/likwo/archive/2011/02/22/1961768.html

1、我该怎么用这样的方式画MA线呢。

W1 因为柱数少，所以没有问题

2、我该怎么抓到全部柱数的iMA ??

3、假设 上述的问题 都无法解决，依程式内IMA的参数，我要求60个横数的移动平均价钱，要怎么算？

mql4如何自定义画图 - Likwo - 博客园
• www.cnblogs.com
|                                                  Custom MACD.mq4 | |                      Copyright ?2004, MetaQuotes Software Corp. | |                                        #property  indicator_color1  Silver #property  indicator_color2  Red #property  indicator_width1  | Custom indicator initialization function                         |...

FYI.

```//+------------------------------------------------------------------+
//|                                                           MA.mq4 |
//|                        Copyright 2018, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots   1
//--- plot MA
#property indicator_label1  "MA"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrRed
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1

input int MaPeriods = 60;
input int MaMethod  = MODE_SMA;
input int MaPrice   = PRICE_CLOSE;
//--- indicator buffers
double         MABuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
{
//--- indicator buffers mapping
SetIndexBuffer(0,MABuffer);
SetIndexDrawBegin(0,MaPeriods);
IndicatorDigits(_Digits);

//---
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 i,limit;
if(rates_total<=0)return(0);
if(prev_calculated<=0)limit=rates_total-1;
else limit=rates_total-prev_calculated;
for(i=limit;i>=0;i--)
{
MABuffer[i]=iMA(Symbol(),Period(),MaPeriods,0,MaMethod,MaPrice,i);
}
//--- return value of prev_calculated for next call
return(rates_total);
}
//+------------------------------------------------------------------+
```

Thx