// 策略参数设置
Params
Numeric FastMA(3); // 快速均线周期
Numeric SlowMA(10); // 慢速均线周期
Numeric MACD_Fast(6); // MACD快速线周期
Numeric MACD_Slow(13); // MACD慢速线周期
Numeric MACD_Signal(5);// MACD信号线周期
Numeric RSI_Length(7); // RSI周期
Numeric RiskRatio(1); // 风险比例(1%本金)
Numeric ATR_Stop(14); // ATR止损周期
// 指标计算
Vars
Series<Numeric> MA_Fast; // 快速均线
Series<Numeric> MA_Slow; // 慢速均线
Series<Numeric> MACD_Dif; // MACD差值
Series<Numeric> MACD_Dea; // MACD信号线
Series<Numeric> MACD_Hist;// MACD柱状图
Series<Numeric> RSI_Value;// RSI值
Series<Numeric> ATR_StopVal;// 动态止损值
// 指标计算模块
MA_Fast = AverageFC(Close, FastMA);
MA_Slow = AverageFC(Close, SlowMA);
MACD_Dif = EMA(Close, MACD_Fast) - EMA(Close, MACD_Slow);
MACD_Dea = EMA(MACD_Dif, MACD_Signal);
MACD_Hist = MACD_Dif - MACD_Dea;
RSI_Value = 50 * (RateOfChange(Close, RSI_Length) + 100);
ATR_StopVal = AvgTrueRange(ATR_Stop) * BigPointValue;
// 交易条件判断
// 多头信号条件
Condition1 = CrossOver(MA_Fast, MA_Slow); // 均线金叉
Condition2 = MACD_Dif > MACD_Dea && MACD_Dif[1] <= MACD_Dea[1]; // MACD金叉确认
Condition3 = RSI_Value > 50 && RSI_Value < 70; // RSI中性偏强
Condition4 = Close > MA_Slow; // 价格在慢线之上
// 空头信号条件
Condition5 = CrossUnder(MA_Fast, MA_Slow); // 均线死叉
Condition6 = MACD_Dif < MACD_Dea && MACD_Dif[1] >= MACD_Dea[1];// MACD死叉确认
Condition7 = RSI_Value < 50 && RSI_Value > 30; // RSI中性偏弱
Condition8 = Close < MA_Slow; // 价格在慢线之下
// 交易执行模块
If(MarketPosition = 0) Begin
If(Condition1 And Condition2 And Condition3 And Condition4) Then
Buy("LE", 1, Ask, StopPrice:Close - ATR_StopVal, LimitPrice:Close + ATR_StopVal * 2);
If(Condition5 And Condition6 And Condition7 And Condition8) Then
SellShort("SE", 1, Bid, StopPrice:Close + ATR_StopVal, LimitPrice:Close - ATR_StopVal * 2);
End
// 动态止盈止损模块
If(MarketPosition = 1) Begin
// 移动止盈:最高价回撤1.5倍ATR
SetStopLoss(Close - ATR_StopVal * 2);
SetProfitTarget(High + ATR_StopVal * 3);
// 突破止损:价格跌破EMA10
If(Close < MA_Slow) Then
Sell("TP-MA", 0, Close);
End
If(MarketPosition = -1) Begin
// 移动止盈:最低价反弹1.5倍ATR
SetStopLoss(Close + ATR_StopVal * 2);
SetProfitTarget(Low - ATR_StopVal * 3);
// 突破止损:价格突破EMA10
If(Close > MA_Slow) Then
BuyToCover("TP-MA", 0, Close);
End
语法错误已修改,编译成功
ai写的东西出问题还是问ai吧