- 精华
- 0
- 在线时间
- 91 小时
- UID
- 6686
- 积分
- 420
- 帖子
- 111
- 阅读权限
- 50
- 注册时间
- 2010-1-16
- 最后登录
- 2019-3-24
- 精华
- 0
- UID
- 6686
- 积分
- 420
- 帖子
- 111
- 主题
- 25
- 阅读权限
- 50
- 注册时间
- 2010-1-16
- 最后登录
- 2019-3-24
|
做空是这样吗,但是我运行了,运行不了。。还是这个系统只适合做多啊
//------------------------------------------------------------------------
// 简称: huangji
// 名称: 顺势2
// 类别: 公式应用
// 类型: 用户应用
// 输出:
//------------------------------------------------------------------------
Params
Numeric TrailingSet(0.382); // 回撤开仓比例设置,从最高点下跌的比例
Numeric StopLossSet(0.5); // 止损比例设置
Vars
Bool startCondition(False); // 启动条件
Bool EntryCondition(False); // 开仓条件
Bool ExitCondition(False); // 平仓条件
NumericSeries highestValue(0); // 前2个周期的最高价
NumericSeries lowestValue(0); // 前2个周期的最低价
Numeric myEntryPrice(0); // 开仓价格
Numeric myExitPrice(0); // 平仓价格
Begin
highestValue = highestValue[1];
lowestValue = lowestValue[1];
If(MarketPosition ==0 ) // 当前空仓
{
If(Close[2]<Open[2] && Close[1] <Open[1] && Close[1] < Close[2])
{
startCondition = True;
highestValue = max(high[2],high[1]);
lowestValue = min(low[2],low[1]);
}
If(startCondition)
{
EntryCondition = ((open-LowestValue) / (highestValue - lowestValue) > TrailingSet )&& // 开盘价即满足回撤条件,用开盘价进行交易
(Open < LowestValue +((highestValue - lowestValue)*StopLossSet)) ; // 开盘价不能低于预设的止损价
If( EntryCondition)
{
SellShort(1,Open);
}Else // 再看其它价格是否满足
{
EntryCondition = (High - LowestValue) / (highestValue - lowestValue) > TrailingSet ; // 最低价满足回撤条件,用低于TrailingSet设置的最近价位建仓
If(EntryCondition)
{
myEntryPrice = lowestValue + (HighestValue - LowestValue ) * TrailingSet;
myEntryPrice = IntPart(myEntryPrice / (PriceScale()*MinMove)) *(PriceScale()*MinMove); // 对价格进行处理
If(myEntryPrice >= low && myEntryPrice <= High)
{
SellShort(1,MyEntryPrice);
}
}
}
}
}
else If(MarketPosition == -1) // 当前持空仓
{
ExitCondition = ( High - lowestValue )/(highestValue - lowestValue) > StopLossSet; // 止损条件满足
If(ExitCondition)
{
myExitPrice = lowestValue +(HighestValue - LowestValue ) * StopLossSet;
myExitPrice = IntPart(myExitPrice / (PriceScale()*MinMove)) *(PriceScale()*MinMove); // 对价格进行处理
BuyToCover(CurrentContracts(),myExitPrice);
}Else // 获利平仓
{
ExitCondition = (AvgEntryPrice() - low) > (highestValue - lowestValue); // 获利平仓条件满足
If(ExitCondition)
{
myExitPrice = AvgEntryPrice() - (HighestValue - LowestValue );
myExitPrice = IntPart(myExitPrice / (PriceScale()*MinMove)) *(PriceScale()*MinMove); // 对价格进行处理
If (myExitPrice >= low && myEntryPrice <= high)
{
BuyToCover(CurrentContracts(),myExitPrice);
}Else
{
BuyToCover(CurrentContracts(),Close);
}
}
}
}
end
//------------------------------------------------------------------------
// 编译版本 GS2010.12.08
// 用户版本 2011/08/10 11:23
// 版权所有 lzl563
// 更改声明 TradeBlazer Software保留对TradeBlazer平台
// 每一版本的TrabeBlazer公式修改和重写的权利
//------------------------------------------------------------------------ |
|