Код: Выделить всё
function Initialize() {
IndicatorName = "VWAPfast";
PriceStudy = true;
AddInput("Input", Inputs.Candle);
AddParameter("D", 2.1);
AddSeries("VWAP", DrawAs.Line, Color.Red);
AddSeries("UPPER", DrawAs.Line, Color.Gray);
AddSeries("LOWER", DrawAs.Line, Color.Gray);
AddGlobalVariable("Period", Types.Int, 0);
AddGlobalVariable("cv", Types.Double, 0);
AddGlobalVariable("v", Types.Double, 0);
AddGlobalVariable("delta2", Types.Double, 0);
}
function Evaluate() {
// AlfaDirect. 2019. OX // 2020 mod by max
// VWAP – VOLUME WEIGHTED AVERAGE PRICE
double p = (Input.High[0] + Input.Low[0] + Input.Close[0])/3.0;
if (CurrentIndex < 500 || BarDate() != BarDate(1)) {
Period = 1;
cv = p * Input.Volume[0];
v = Input.Volume[0];
VWAP = p;
delta2 = 0;
UPPER = p;
LOWER = p;
} else {
Period++;
cv += p * Input.Volume[0];
v += Input.Volume[0];
VWAP = cv / v;
// std - расчета разниц цены и VWAP в каждый момент времени
delta2 += (p - VWAP) * (p - VWAP);
double std = Math.Sqrt(delta2/Period);
UPPER = VWAP + D * std;
LOWER = VWAP - D * std;
}
}