- 精华
- 0
- 在线时间
- 74 小时
- UID
- 273669
- 积分
- 16
- 帖子
- 8
- 阅读权限
- 10
- 注册时间
- 2018-12-15
- 最后登录
- 2024-1-3
- 精华
- 0
- UID
- 273669
- 积分
- 16
- 帖子
- 8
- 主题
- 1
- 阅读权限
- 10
- 注册时间
- 2018-12-15
- 最后登录
- 2024-1-3
|
Params
//此处添加参
Numeric StartPer1(5); //1级跟踪止盈,盈利10%启动
Numeric StopPer1(20); //1级跟踪止盈,盈利回撤100%触发
Numeric StartPer2(10); //2级跟踪止盈,盈利20%启动
Numeric StopPer2(30); //2级跟踪止盈,盈利回撤50%触发
Numeric StartPer3(30); //3级跟踪止盈,盈利30%启动
Numeric StopPer3(30); //3级跟踪止盈,盈利回撤30%触发
Numeric StartPer4(50); //3级跟踪止盈,盈利50%启动
Numeric StopPer4(15); //3级跟踪止盈,盈利回撤15%触发
Numeric StopLoss(1); // 止损2%
Vars
//此处添加变量
NumericSeries HighestAfterEntry; // 开仓后出现的最高价
NumericSeries LowestAfterEntry; // 开仓后出现的最低价
//记录开仓后高低点
if (BarsSinceEntry == 1)
{
HighestAfterEntry = High;
LowestAfterEntry = Low;
} Else If(BarsSinceEntry > 1)
{
HighestAfterEntry = Max(HighestAfterEntry[1],High[1]);
LowestAfterEntry = Min(LowestAfterEntry[1],Low[1]);
}
Else
{
HighestAfterEntry = HighestAfterEntry[1];
LowestAfterEntry = LowestAfterEntry[1];
}
Commentary("HighestAfterEntry="+Text(HighestAfterEntry));
Commentary("LowestAfterEntry="+Text(LowestAfterEntry));
//1级跟踪止盈,盈利10%启动,盈利回撤100%触发
If(MarketPosition==-1 && BarsSinceLastEntry>0 && LowestAfterEntry[1]<=LastEntryPrice*(1-0.01*StartPer1) && High>=LowestAfterEntry[1]+(LastEntryPrice-LowestAfterEntry[1])*0.01*StopPer1)
{
BuyToCover(0,Max(Open,LowestAfterEntry[1]+(LastEntryPrice-LowestAfterEntry[1])*0.01*StopPer1));
}
If(MarketPosition==1 && BarsSinceLastEntry>0 && HighestAfterEntry[1]>=LastEntryPrice*(1+0.01*StartPer1) && Low<=HighestAfterEntry[1]-(HighestAfterEntry[1]-LastEntryPrice)*0.01*StopPer1)
{
Sell(0,Min(Open,HighestAfterEntry[1]-(HighestAfterEntry[1]-LastEntryPrice)*0.01*StopPer1));
}
//2级跟踪止盈,盈利20%启动,盈利回撤50%触发
If(MarketPosition==-1 && BarsSinceLastEntry>0 && LowestAfterEntry[1]<=LastEntryPrice*(1-0.01*StartPer2) && High>=LowestAfterEntry[1]+(LastEntryPrice-LowestAfterEntry[1])*0.01*StopPer2)
{
BuyToCover(0,Max(Open,LowestAfterEntry[1]+(LastEntryPrice-LowestAfterEntry[1])*0.01*StopPer2));
}
If(MarketPosition==1 && BarsSinceLastEntry>0 && HighestAfterEntry[1]>=LastEntryPrice*(1+0.01*StartPer2) && Low<=HighestAfterEntry[1]-(HighestAfterEntry[1]-LastEntryPrice)*0.01*StopPer2)
{
Sell(0,Min(Open,HighestAfterEntry[1]-(HighestAfterEntry[1]-LastEntryPrice)*0.01*StopPer2));
}
//3级跟踪止盈,盈利30%启动,盈利回撤30%触发
If(MarketPosition==-1 && BarsSinceLastEntry>0 && LowestAfterEntry[1]<=LastEntryPrice*(1-0.01*StartPer3) && High>=LowestAfterEntry[1]+(LastEntryPrice-LowestAfterEntry[1])*0.01*StopPer3)
{
BuyToCover(0,Max(Open,LowestAfterEntry[1]+(LastEntryPrice-LowestAfterEntry[1])*0.01*StopPer3));
}
If(MarketPosition==1 && BarsSinceLastEntry>0 && HighestAfterEntry[1]>=LastEntryPrice*(1+0.01*StartPer3) && Low<=HighestAfterEntry[1]-(HighestAfterEntry[1]-LastEntryPrice)*0.01*StopPer3)
{
Sell(0,Min(Open,HighestAfterEntry[1]-(HighestAfterEntry[1]-LastEntryPrice)*0.01*StopPer3));
}
//4级跟踪止盈,盈利50%启动,盈利回撤15%触发
If(MarketPosition==-1 && BarsSinceLastEntry>0 && LowestAfterEntry[1]<=LastEntryPrice*(1-0.01*StartPer4) && High>=LowestAfterEntry[1]+(LastEntryPrice-LowestAfterEntry[1])*0.01*StopPer4)
{
BuyToCover(0,Max(Open,LowestAfterEntry[1]+(LastEntryPrice-LowestAfterEntry[1])*0.01*StopPer4));
}
If(MarketPosition==1 && BarsSinceLastEntry>0 && HighestAfterEntry[1]>=LastEntryPrice*(1+0.01*StartPer4) && Low<=HighestAfterEntry[1]-(HighestAfterEntry[1]-LastEntryPrice)*0.01*StopPer4)
{
Sell(0,Min(Open,HighestAfterEntry[1]-(HighestAfterEntry[1]-LastEntryPrice)*0.01*StopPer4));
}
// 启动止损
If(MarketPosition==-1 && BarsSinceLastEntry>0 && High>=LastEntryPrice*(1+StopLoss*0.01))
{
BuyToCover(0,Max(LastEntryPrice*(1+StopLoss*0.01),Open));
Commentary(Text(StopLoss)+"%止损");
}
If(MarketPosition==1 && BarsSinceLastEntry>0 && Low<=LastEntryPrice*(1-StopLoss*0.01))
{
Sell(0,Min(LastEntryPrice*(1-StopLoss*0.01),Open));
Commentary(Text(StopLoss)+"%止损");
}
End |
|