- 精华
- 0
- 在线时间
- 41 小时
- UID
- 131362
- 积分
- 32
- 帖子
- 20
- 阅读权限
- 10
- 注册时间
- 2012-7-25
- 最后登录
- 2021-1-22
- 精华
- 0
- UID
- 131362
- 积分
- 32
- 帖子
- 20
- 主题
- 9
- 阅读权限
- 10
- 注册时间
- 2012-7-25
- 最后登录
- 2021-1-22
|
请大侠们帮忙看看这个程序哪里有问题,为什么加载之后很多根K线都出现交易信号?
//------------------------------------------------------------------------
// 简称: A016
// 名称: 结算价
// 类别: 公式应用
// 类型: 用户应用
// 输出:
//------------------------------------------------------------------------
Params//参数
Numeric Lots(1);
Numeric para1(4);
Numeric TStart1(5);
Numeric TStart2(20);
Numeric TStop1(1);
Numeric TStop2(10);
Numeric SL(10);
Vars//变量
NumericSeries dayavg;//量价加权平均价,即结算价。
Numeric MinPoint;//最小波动单位
//出入场变量
Bool Conbuy1;//多开条件
Bool Conbuy2;//多开条件
Bool ConSell;//多平条件
Bool ConSellShort1;//空开条件
Bool ConSellShort2;//空开条件
Bool ConBuyToCover;//空平条件
//跟踪止损变量
Numeric MyEntryPrice; // 开仓价格,本例是开仓均价,也可根据需要设置为某次入场的价格
Numeric TrailingStart1; // 保本启动
Numeric TrailingStart2; // 跟踪止损启动设置
Numeric TrailingStop1; // 保本设置
Numeric TrailingStop2; // 跟踪止损设置
Numeric StopLossSet; // 止损设置
Numeric MyExitPrice; // 平仓价格
NumericSeries HighestAfterEntry; // 开仓后出现的最高价
NumericSeries LowestAfterEntry; // 开仓后出现的最低价
Begin
MinPoint = MinMove*PriceScale;
dayavg = AA001;
Plotnumeric("结算价",dayavg);
//开平仓条件
Conbuy1=(C<dayavg+para1*MinPoint) And C[1]<dayavg[1] And C>dayavg;
Conbuy2=(C[1]>=dayavg[1]) And (C>=dayavg) And (C<dayavg+para1*MinPoint);
ConSell=C[1]>dayavg[1] And C<dayavg;
ConSellShort1=(C>dayavg-para1*MinPoint) And C[1]>dayavg[1] And C<dayavg;
ConSellShort2=(C[1]<=dayavg[1]) And (C<=dayavg) And (C>dayavg-para1*MinPoint);
ConBuyToCover=C[1]<dayavg[1] And C>dayavg;
//交易运行程序
If(Time>0.0905 And Time<0.1455)
{
If(MarketPosition!=1 And (Conbuy1 Or Conbuy2))//多开
{
Buy(Lots,O[-1]);
PlotString("text","多开",(L-3*MinPoint),White);
}
If(ConSell)//多平
{
Sell(Lots,O[-1]);
PlotString("text","多平",(H+2*MinPoint),White);
}
If(MarketPosition!=-1 And (ConSellShort1 Or ConSellShort2))//空开
{
SellShort(Lots,O[-1]);
PlotString("text","空开",(H+3*MinPoint),White);
}
If(ConBuyToCover)//空平
{
BuyToCover(Lots,O[-1]);
PlotString("text","空平",(L-2*MinPoint),White);
}
}
//跟踪止盈止损程序
MyEntryPrice = AvgEntryPrice;
HighestAfterEntry=Highest(H, BarsSinceEntry);
LowestAfterEntry=Lowest(L, BarsSinceEntry);
If(MarketPosition==1) // 有多仓的情况
{
If(HighestAfterEntry>= MyEntryPrice + TrailingStart2*MinPoint) // 第二级跟踪止损的条件表达式
{
MyExitPrice = HighestAfterEntry - TrailingStop2*MinPoint;
If(Low <= MyExitPrice)
{
Sell(Lots,O[-1]);
PlotString("text","跟踪多平",(H+2*MinPoint),White);
}
}else if(HighestAfterEntry >= MyEntryPrice + TrailingStart1*MinPoint)// 第一级跟踪止损的条件表达式
{
MyExitPrice = MyEntryPrice + TrailingStop1*MinPoint;
If(Low <= MyExitPrice)
{
Sell(Lots,O[-1]);
PlotString("text","保本多平",(H+2*MinPoint),White);
}
}else if(Low <= MyEntryPrice - StopLossSet*MinPoint)//可以在这里写上初始的止损处理
{
Sell(Lots,O[-1]);
PlotString("text","多单止损",(H+2*MinPoint),White);
}
}else if(MarketPosition==-1) // 有空仓的情况
{
If(LowestAfterEntry <= MyEntryPrice - TrailingStart2*MinPoint) // 第二级跟踪止损的条件表达式
{
MyExitPrice = LowestAfterEntry + TrailingStop2*MinPoint;
If(High >= MyExitPrice)
{
BuyToCover(Lots,O[-1]);
PlotString("text","跟踪空平",(L-2*MinPoint),White);
}
}else if(LowestAfterEntry <= MyEntryPrice - TrailingStart1*MinPoint)// 第一级跟踪止损的条件表达式
{
MyExitPrice = MyEntryPrice - TrailingStop1*MinPoint;
If(High >= LowestAfterEntry + TrailingStop1*MinPoint)
{
BuyToCover(Lots,O[-1]);
PlotString("text","保本空平",(L-2*MinPoint),White);
}
}else If(High >= MyEntryPrice + StopLossSet*MinPoint)//可以在这里写上初始的止损处理
{
BuyToCover(Lots,O[-1]);
PlotString("text","空单止损",(L-2*MinPoint),White);
}
}
//收盘前平仓程序
If(Time>=0.1458)
{
If(MarketPosition==1)
{
Sell(Lots,O[-1]);
PlotString("text","收盘多平",(H+2*MinPoint),White);
}
if(MarketPosition==-1)
{
BuyToCover(Lots,O[-1]);
PlotString("text","收盘空平",(L-2*MinPoint),White);
}
}
End
//------------------------------------------------------------------------
// 编译版本 GS2010.12.08
// 用户版本 2013/06/18 13:32
// 版权所有 fl1652546
// 更改声明 TradeBlazer Software保留对TradeBlazer平台
// 每一版本的TrabeBlazer公式修改和重写的权利
//------------------------------------------------------------------------ |
|