Params
Numeric FastLength(5); // 短期指数平均线参数
Numeric SlowLength(20); // 长期指数平均线参数
Vars
Series<Numeric> AvgValue1;
Series<Numeric> AvgValue2;
TimeStamp EndTime = DateTime(2024, 6, 22, 23, 59, 59); // 策略结束时间
Events
OnReady()
{
SetBackBarMaxCount(1 + Max(FastLength, SlowLength));
}
OnBar(ArrayRef<Integer> indexs)
{
// 获取当前时间
TimeStamp currentTime = RealEndDateTime();
// 打印当前时间(用于调试)
Print(DateTimeToString(currentTime));
// 检查当前时间是否超过策略结束时间
If (currentTime > EndTime)
{
// 超过策略结束时间,不再执行交易
return;
}
AvgValue1 = AverageFC(Close, FastLength);
AvgValue2 = AverageFC(Close, SlowLength);
PlotNumeric(\"MA1\", AvgValue1);
PlotNumeric(\"MA2\", AvgValue2);
If(MarketPosition <> 1 && AvgValue1[1] > AvgValue2[1])
{
Buy(0, Open);
}
If(MarketPosition <> -1 && AvgValue1[1] < AvgValue2[1])
{
SellShort(0, Open);
}
}
总是显示13行缺少分号
TimeStamp EndTime = DateTime(2024, 6, 22, 23, 59, 59); // 策略结束时间
你确定变量定义可以这样定义????
小白不太懂,应该怎么写呢 ,
你如果只是要定义一个具体的时间参数,比如2024年6月22日23点59分59秒,那就用数值20240622.235959来表示就行了