- 精华
- 0
- 在线时间
- 65 小时
- UID
- 15265
- 积分
- 174
- 帖子
- 39
- 阅读权限
- 40
- 注册时间
- 2010-8-18
- 最后登录
- 2016-1-30
- 精华
- 0
- UID
- 15265
- 积分
- 174
- 帖子
- 39
- 主题
- 4
- 阅读权限
- 40
- 注册时间
- 2010-8-18
- 最后登录
- 2016-1-30
|
回复 1# nopain
稍微改了一下条件,日线回测还挺好。不过市盘中价格的触发是有未来的。- //------------------------------------------------------------------------
- // 简称: shunshi_B
- // 名称: 顺势_B
- // 类别: 公式应用
- // 类型: 用户应用
- // 输出:
- //------------------------------------------------------------------------
- Params
- Numeric TrailingSet(0.30); // 回撤开仓比例设置,从最高点下跌的比例
- Numeric StopLossSet(0.42); // 止损比例设置
- Numeric lots(1);
- 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
- If(BarStatus==2 && high==low) return; //日线级别的回撤开仓,适合用这种过滤方法。
- highestValue = max(high[2],high[1]);
- lowestValue = min(low[2],low[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 = ((highestValue - Open) / (highestValue - lowestValue) > TrailingSet )&& // 开盘价即满足回撤条件,用开盘价进行交易
- (Open > highestValue -((highestValue - lowestValue)*StopLossSet)) ; // 开盘价不能低于预设的止损价
- If( EntryCondition)
- {
- Buy(lots,Open);
- }Else // 再看其它价格是否满足
- {
- EntryCondition = (highestValue - Low) / (highestValue - lowestValue) > TrailingSet ; // 最低价满足回撤条件,用低于TrailingSet设置的最近价位建仓
- If(EntryCondition)
- {
- myEntryPrice = highestValue - (HighestValue - LowestValue ) * TrailingSet;
- myEntryPrice = IntPart(myEntryPrice / (PriceScale()*MinMove)) *(PriceScale()*MinMove); // 对价格进行处理
- If(myEntryPrice >= low && myEntryPrice <= High)
- {
- Buy(lots,MyEntryPrice);
- }
- }
- }
- }
- }else If(MarketPosition == 1) // 当前多仓
- {
- ExitCondition = ( HighestValue - Low )/(highestValue - lowestValue) > StopLossSet; // 止损条件满足
- If(ExitCondition)
- {
- myExitPrice = highestValue - (HighestValue - LowestValue ) * StopLossSet;
- myExitPrice = IntPart(myExitPrice / (PriceScale()*MinMove)) *(PriceScale()*MinMove); // 对价格进行处理
- Sell(CurrentContracts(),myExitPrice);
- }Else // 获利平仓
- {
- ExitCondition = (high - AvgEntryPrice()) > (highestValue - lowestValue); // 获利平仓条件满足
- If(ExitCondition)
- {
- myExitPrice = AvgEntryPrice() + (HighestValue - LowestValue );
- myExitPrice = IntPart(myExitPrice / (PriceScale()*MinMove)) *(PriceScale()*MinMove); // 对价格进行处理
- If (myExitPrice >= low && myEntryPrice <= high)
- {
- Sell(lots,myExitPrice);
- }Else
- {
- Sell(lots,Close);
- }
- }
- }
- }
- End
- //------------------------------------------------------------------------
- // 编译版本 GS2010.12.08
- // 用户版本 2011/10/22 08:33
- // 版权所有 foodmax
- // 更改声明 TradeBlazer Software保留对TradeBlazer平台
- // 每一版本的TrabeBlazer公式修改和重写的权利
- //------------------------------------------------------------------------
复制代码 |
|