<function>
 <description>Средняя цена закрытия ВВЕРХ</description>
 <description_en>Average closing UP price</description_en>
 <code>function AverageGain(x, PriceValue, Len)
{
    gain = 0;
    if (CurrentBar == Len)
    {
        for (i = 0; i &lt; Len; i++)
        {
            if (PriceValue.at(i) > PriceValue.at(i+1))
            {
                gain += PriceValue.at(i)-PriceValue.at(i+1);
            }
        }
        x.setAt(0, gain/Len);
    }
    else if (CurrentBar > Len)
    {
        if (PriceValue.at(0) > PriceValue.at(1))
        {
            gain = PriceValue.at(0) - PriceValue.at(1);
        }
        x.setAt(0, (x.at(1)*(Len-1) + gain)/Len);
    }
   return x.at(0);
}</code>
</function>
