问题描述
我的简单移动平均线指标在添加到图表时可以正确显示,但不显示随后添加的candels。例如,我在10:00将指标添加到M15图表中并显示MA。但在11:00时,它并未显示新添加的4个candels的移动平均值。为什么? 这是代码:
//+------------------------------------------------------------------+
//| ni-ma.mq4 |
//| Copyright 2020,MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020,MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 2 // Number of buffers
#property indicator_color1 Blue // Color of the 1st line
double arrBlue[];
input int period = 20;
input int LineThickness=1;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
SetIndexBuffer(0,arrBlue); // Assigning an array to a buffer
SetIndexStyle(0,DRAW_LINE,EMPTY,LineThickness,clrBlue);
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,Counted_bars;
//--------------------------------------------------------------------
Counted_bars=IndicatorCounted(); // Number of counted bars
i=1; // Index of the first uncounted
while(++i<Bars){
float m1=0;
for(int j=0;j<period ;j++)
m1+=Close[i+j];
m1=m1/period;
Comment( m1/period+"--"+Close[i]);
arrBlue[i]=m1;
}
return(rates_total);
}
//+------------------------------------------------------------------+
有关简单移动平均使用量和计算的其他信息: 简单移动平均线(SMA)是交易员和投资者广泛使用的技术。可以针对不同的价格(例如开盘价,收盘价,最高价和最低价)进行计算。这是一个后向指标,它依赖于一定时期内的过去价格数据。
SMA指标用于向交易员和投资者指示买入和卖出信号。它有助于确定股票的支撑和阻力价格,以指示应在何处买卖该资产。交易者和投资者也使用SMA交叉来表明价格看涨和看跌。但是,要生成指标,必须先使用过去的价格数据进行计算,然后再绘制在图表上。
SMA很容易计算,并且是基于一组参数的特定时间段内的平均股价。移动平均是通过将股票在一定时期内的价格相加,然后将总和除以总时期数得出的。
例如,交易者希望通过查看五个时段的日内高点来计算股票ABC的SMA。在过去的五天中,当日高点分别为25.40美元,25.90美元。 $ 26.50,$ 26.30和$ 27.90。基于高点的SMA为26.40美元((25.40美元+25.90美元+26.50美元+26.30美元+27.90美元)/ 5)。 ABC股票过去五个收盘价分别为$ 25.25,$ 25.50,$ 25.00,$ 24.90和$ 26.80。因此,SMA为$ 25.49。此计算可以扩展到更多时段,例如20、50、100和200个时段。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)