这个是怎么回事??
代码如下:
[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 then
begin
Buy("Buy") Next Bar at Market;
PositionOpen = True;
EntryPrice = Close;
HighestSinceEntry = Close;
end;
// 平仓逻辑
If PositionOpen then
begin
// 更新最高价和最低价
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;
ai写的,不应该问ai吗?
什么叫程序主体,不存在是什么意思?