import {
IndicatorImplementation,
TIndexBuffer,
TDrawStyle,
TPenStyle,
TimeZoneMode,
TOptionType
} from 'forex-tester-custom-indicator-api';
export class IntradayVWAP extends IndicatorImplementation {
// 缓冲区用于存储VWAP值
private vwapBuffer: TIndexBuffer = this.api.CreateIndexBuffer();
// 每日累计值
private sumPV: number = 0; // 价格*成交量的总和
private sumVol: number = 0; // 成交量总和
private currentDate: string = '';
// 参数:自定义开始时间
private startHour = this.api.createTOptValue_number(9); // 默认9点开始
private startMinute = this.api.createTOptValue_number(0); // 默认0分
Init(): void {
// 设置指标名称
this.api.IndicatorShortName("Intraday VWAP");
// 设置缓冲区
this.api.IndicatorBuffers(1);
this.api.SetIndexBuffer(0, this.vwapBuffer);
// 设置线条样式
this.api.SetIndexStyle(0, TDrawStyle.LINE, TPenStyle.SOLID, 2, "#0066FF");
this.api.SetIndexLabel(0, "VWAP");
// 注册参数
this.api.RegOption("Start Hour", TOptionType.INTEGER, this.startHour);
this.api.RegOption("Start Minute", TOptionType.INTEGER, this.startMinute);
// 设置参数范围
this.api.SetOptionRange("Start Hour", 0, 23);
this.api.SetOptionRange("Start Minute", 0, 59);
}
Calculate(index: number): void {
// 只在日线以下的时间周期显示
if (this.api.Timeframe() >= 1440) {
this.vwapBuffer.setValue(index, NaN);
return;
}
const time = this.api.Time(index);
const currentDate = `${time.yearOf()}-${time.monthOf()}-${time.dayOfMonth()}`;
// 检查是否是新的一天或会话开始
const isSessionStart =
time.hour() === this.startHour.value &&
time.minute() === this.startMinute.value;
// 如果是新的一天或会话开始,重置累计值
if (currentDate !== this.currentDate || isSessionStart) {
this.sumPV = 0;
this.sumVol = 0;
this.currentDate = currentDate;
}
// 计算当前bar的典型价格和成交量
const typicalPrice = (this.api.High(index) + this.api.Low(index) + this.api.Close(index)) / 3;
const volume = this.api.Volume(index);
// 累加价格成交量
this.sumPV += typicalPrice * volume;
this.sumVol += volume;
// 计算并设置VWAP值
if (this.sumVol > 0) {
const vwap = this.sumPV / this.sumVol;
this.vwapBuffer.setValue(index, vwap);
} else {
this.vwapBuffer.setValue(index, NaN);
}
}
}
export const indicator = new IntradayVWAP();Hi, I created it using AI in cursor. And built the
`my-indicator-project.js`. However, after I uploaded it, nothing had happend….. no response at all. Is there anything wrong with the codes?
Share update with 0 linked conversations as well
Completed
💡 Feature Request
About 1 year ago

Liwei Gao
Get notified by email when there are changes.
Completed
💡 Feature Request
About 1 year ago

Liwei Gao
Get notified by email when there are changes.