# 在外汇中显示不同周期级别的加权平均价与结算价-MT5指标 - MetaTrader 5脚本

924

2020.04.03 09:06

2020.04.03 09:51

```   int count = -1;
long bars = 0;

if((bars = Bars(symbol,timeframe,start - PeriodSeconds(timeframe),(datetime)UINT_MAX))> 0)
if((count = CopyTime(symbol,timeframe,0,(int)bars,times))== bars)
return count;

if((count = CopyTime(symbol,timeframe,start - PeriodSeconds(timeframe),(datetime)UINT_MAX,times))> 0)
return count;```

```   for(int i = 0; i <= copied; i++)
{
int shift = pos;
for(; pos < rates_total && (pos - shift) <= ExtPeriodLimit && !_StopFlag; pos++)
{
double price=EMPTY_VALUE;
_setPrice(Applied,price,pos);
if(i < copied)
{
if(time[pos] >= _times[i])
break;
}
else
shift = pos - Bars(_Symbol,_Period,_times[i - 1],time[pos]) + 1; //i==count

ExtBarBuffer[pos] = pos - shift; //ExtBarBuffer[pos-1]+1
if(ExtBarBuffer[pos] > 0)
{
double amount = ExtPvolBuffer[pos - 1] * ExtVolumeSumBuffer[pos - 1] + price * tick_volume[pos];
ExtVolumeSumBuffer[pos] = ExtVolumeSumBuffer[pos - 1] + tick_volume[pos];
ExtPvolBuffer[pos] = (ExtVolumeSumBuffer[pos] > 0) ? amount / ExtVolumeSumBuffer[pos] : ExtPvolBuffer[pos - 1];
ExtPvolColors[pos] = (price < ExtPvolBuffer[pos] && ExtPvolBuffer[pos] <= ExtPvolBuffer[pos - 1]) ? 1 :
(price > ExtPvolBuffer[pos] && ExtPvolBuffer[pos] >= ExtPvolBuffer[pos - 1]) ? 2 : 0;
}
else
{
ExtVolumeSumBuffer[pos] = (double)tick_volume[pos];
ExtPvolBuffer[pos] = price;
ExtPvolColors[pos] = 0;
}
ExtSettleBuffer[pos] = (ExtBarBuffer[pos]>1) ? ExtSettleBuffer[pos-1]:(shift > 0)? ExtPvolBuffer[shift - 1] : price;
}
}```