PrevAvgValue1 = Ref(AvgValue1, -1); // 获取前一根K线的均线值
PrevAvgValue2 = Ref(AvgValue2, -1);
Numeric Account_Equity = Account_Equity();
这三项代码在编译时都提示函数未声明,请问怎么解决?
截图贴全,编译器报的内容截图
//------------------------------------------------------------------------
// 简称: newma
// 名称: 双均线增强策略
// 类别: 公式应用
// 类型: 用户应用
// 输出: Void
//------------------------------------------------------------------------
// 文件类型:交易策略
Params
Numeric FastLength(5); // 短期均线周期
Numeric SlowLength(20); // 长期均线周期
Numeric VolumeMAPeriod(20); // 成交量均线周期
Numeric MaxDrawdown(10); // 最大回撤百分比
Vars
// 修正1:声明为序列变量以支持Ref函数
Series<Numeric> AvgValue1; // 短期EMA
Series<Numeric> AvgValue2; // 长期EMA
Series<Numeric> HighestAfterEntry; // 入场后最高价
Series<Numeric> LowestAfterEntry; // 入场后最低价
Bool CrossUp;
Bool CrossDown;
Numeric PrevAvgValue1; // 前一日快线值
Numeric PrevAvgValue2; // 前一日慢线值
Numeric AvgVolume; // 成交量均线
Bool VolumeFilter;
Series<Numeric> EntryPrice; // 入场价格(序列变量)
Numeric ATRValue;
Numeric TrailingStop;
Numeric PeakEquity;
Events
OnReady()
{
SetBackBarMaxCount(Max(FastLength, SlowLength) + 50);
}
// 修正:移除错误的事件参数
OnBar(ArrayRef<Integer> indexs)
{
//--- 数据准备 ---
// 使用TB内置Volume变量(修正2)
AvgVolume = Average(Vol, VolumeMAPeriod);
VolumeFilter = Vol > AvgVolume * 1.2;
// 计算EMA(使用序列变量)
AvgValue1 = XAverage(Close, FastLength);
AvgValue2 = XAverage(Close, SlowLength);
// 获取前值(修正1)
PrevAvgValue1 = Ref(AvgValue1, -1); // 获取前一根K线的均线值
PrevAvgValue2 = Ref(AvgValue2, -1);
//--- 信号生成 ---
CrossUp = PrevAvgValue1 < PrevAvgValue2
&& AvgValue1 > AvgValue2
&& Close > AvgValue2
&& VolumeFilter
&& Time >= 0.1430;
CrossDown = PrevAvgValue1 > PrevAvgValue2
&& AvgValue1 < AvgValue2
&& Close < AvgValue2
&& VolumeFilter
&& Time >= 0.1430;
//--- 风险管理(修正3)---
// 使用TB内置账户权益函数
Numeric Account_Equity = Account_Equity();
If(MarketPosition == 0) {
PeakEquity = Account_Equity;
} Else {
PeakEquity = Max(PeakEquity, Account_Equity);
}
If((PeakEquity - Account_Equity)/PeakEquity*100 >= MaxDrawdown) {
Sell(0, Close);
BuyToCover(0, Close);
Return;
}
//--- 交易逻辑 ---
If(CrossUp) {
If(MarketPosition == -1) BuyToCover(0, Open);
Buy(1, Open);
EntryPrice = Open;
// 初始化最高价跟踪(修正4/5)
HighestAfterEntry = High;
} Else If(CrossDown) {
If(MarketPosition == 1) Sell(0, Open);
SellShort(1, Open);
EntryPrice = Open;
// 初始化最低价跟踪
LowestAfterEntry = Low;
}
//--- 动态止损(修正4/5)---
// 手动实现最高/低价跟踪
If(MarketPosition == 1) {
HighestAfterEntry = Max(HighestAfterEntry, High);
TrailingStop = HighestAfterEntry - 2*ATRValue;
If(Low <= TrailingStop) Sell(0, TrailingStop);
}
Else If(MarketPosition == -1) {
LowestAfterEntry = Min(LowestAfterEntry, Low);
TrailingStop = LowestAfterEntry + 2*ATRValue;
If(High >= TrailingStop) BuyToCover(0, TrailingStop);
}
//--- 可视化 ---
PlotNumeric("FastMA", AvgValue1, 0);
PlotNumeric("SlowMA", AvgValue2, 0);
PlotBool("BuySignal", CrossUp, High+10, Green);
PlotBool("SellSignal", CrossDown, Low-10, Red);
}
//------------------------------------------------------------------------
// 编译版本 2025/02/16 235608
// 版权所有 coolben
//------------------------------------------------------------------------
在线等
这是谁写的?tbquant没有三个系统函数,自己定义的?自己定义的那就要自己补充函数内容。
前面参数哪里加Numeric AvgValue1.。。。这三个添加进去就行了,如果这些是变量就加在Vars那呀
Params
Numeric FastLength(5); // 短期均线周期
Numeric SlowLength(20); // 长期均线周期
Numeric VolumeMAPeriod(20); // 成交量均线周期
Numeric MaxDrawdown(10); // 最大回撤百分比
Vars
// 修正1:声明为序列变量以支持Ref函数
Series<Numeric> AvgValue1; // 短期EMA
Series<Numeric> AvgValue2; // 长期EMA
Series<Numeric> HighestAfterEntry; // 入场后最高价
Series<Numeric> LowestAfterEntry; // 入场后最低价
Bool CrossUp;
Bool CrossDown;
Numeric PrevAvgValue1; // 前一日快线值
Numeric PrevAvgValue2; // 前一日慢线值
Numeric AvgVolume; // 成交量均线
Bool VolumeFilter;
Series<Numeric> EntryPrice; // 入场价格(序列变量)
Numeric ATRValue;
Numeric TrailingStop;
Numeric PeakEquity;
原文是这样的,但我加了好像也不行