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

 
首先感谢各位大大的解答,姐姐的公司是使用 MT4,不是MT5,

首先,我在绘制 MA用,如LINK

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


其中 #property 这一段会照成  'xxxxx' is not expert and cannot be executed 的错误

同事说这是宣告 「区域变量」,拿掉没差,但拿掉后,下面就算我照抄,或是作任何的修改 ,例如,style 的变更 width 设成10 或是颜色,都不会画图。

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




后来,我用研究了,其他方式,用 ObjectCreate 的方式,抓2个时间 ,2个价钱,去画一条线。
但是画出来变成(下图)



程式如下


W1 因为柱数少,所以没有问题 
但 H1 的柱数少3000+根,后面几百个柱,用iMA 抓,都是0,WHY ??

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

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

感谢 各位耐心的看完,
mql4如何自定义画图 - Likwo - 博客园
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
 
我该怎么抓到全部柱数的iMA ??
原因: