均线策略
这个是怎么回事??代码如下:[Description("5日均线向上突破10日均线做多")][Version(1)]// 输入参数Inputs: ShortTermMA(5), LongTermMA(10), StopLossPercent(2), TakeProfitPercent(5);// 变量声明Vars: PositionOpen(False), EntryPrice(0), HighestSinceEntry(0), LowestSinceEntry(0);// 计算移动平均线Plot1(MA(Close, ShortTermMA), "5日均线");Plot2(MA(Close, LongTermMA), "10日均线");// 开仓条件:5日均线上穿10日均线If (MA(Close, ShortTermMA) Crosses Above MA(Close, LongTermMA)) and not PositionOpen thenbegin Buy("Buy") Next Bar at Market; PositionOpen = True; EntryPrice = Close; HighestSinceEntry = Close;end;// 平仓逻辑If PositionOpen thenbegin // 更新最高价和最低价 If Close > HighestSinceEntry then HighestSinceEntry = Close; If Close < LowestSinceEntry or LowestSinceEntry = 0 then LowestSinceEntry = Close; // 止损:亏损2% If Close <= EntryPrice * (1 - StopLossPercent / 100) then begin Sell("StopLoss") Next Bar at Market; PositionOpen = False; end; // 止盈:从最高位回撤5% If HighestSinceEntry > 0 and Close <= HighestSinceEntry * (1 - TakeProfitPercent / 100) then begin Sell("TakeProfit") Next Bar at Market; PositionOpen = False;