Re: Очень нужен индикатор VWAP
Добавлено: 16 янв 2021, 09:42
Поддерживаю коллегу, если можно прикрутить динамичное изменение точки 0, то это будет просто огонь
Неофициальный форум клиентского терминала Альфа-Инвестиции (Альфа-Директ 4). Обсуждение терминала, обмен опытом, разработка скриптов индикаторов и стратегий.
https://alfadirect4.ru/
Код: Выделить всё
function Initialize()
{
IndicatorName = "VWAP4";
PriceStudy = true;
AddInput("Input", Inputs.Candle);
AddParameter("Start", DateTime.Now.ToString());
AddSeries("VWAP4", DrawAs.Line, Color.Orange);
AddGlobalVariable("pq", Types.Double, 0.0);
AddGlobalVariable("q", Types.Double, 0.0);
}
function Evaluate()
{
string s=Start.stringValue;
DateTime start=Convert.ToDateTime(s);
// if(CurrentIndex==0)
// ShowMessage(String.Format("VWAP4 Start: {0}", start));
if(CurrentTime<start)
{
return;
// pq=0.0;
// q=0.0;
}
double p0=(Input.High[0]+Input.Low[0]+Input.Close[0])/3.0;
double q0=Input.Volume[0];
pq+=p0*q0;
q+=q0;
if(q!=0) VWAP4[0]=pq/q;
else VWAP4[0]=(CurrentIndex>0 ? VWAP4[-1] : 0.0);
}
Код: Выделить всё
function Initialize()
{
IndicatorName = "VWAP3";
PriceStudy = true;
AddInput("Input", Inputs.Candle);
AddParameter("Period", 10, "Период");
AddSeries("VWAP3", DrawAs.Line, Color.Orange);
AddGlobalVariable("cv", Types.Double, 0.0);
AddGlobalVariable("v", Types.Double, 0.0);
}
function Evaluate()
{
int period=(int)Period;
if(period<=0 && BarDate()!=BarDate(1)) // period=0 - считать внутри дня
{
cv=0.0; v=0.0;
}
double p0=(Input.High[0]+Input.Low[0]+Input.Close[0])/3.0;
double q0=Input.Volume[0];
cv+=p0*q0;
v+=q0;
if(period<=0 || CurrentIndex<period)
{
if(v!=0) VWAP3[0]=cv/v; else
if(CurrentIndex>0) VWAP3[0]=VWAP3[-1];
else VWAP3[0]=0.0;
}
else
{
double p1=(Input.High[-period]+Input.Low[-period]+Input.Close[-period])/3.0;
double q1=Input.Volume[-period];
cv-=p1*q1;
v-=q1;
if(v!=0) VWAP3[0]=cv/v;
else VWAP3[0]=VWAP3[-1];
}
}