- 精华
- 3
- 在线时间
- 196 小时
- UID
- 2459
- 积分
- 14133
- 帖子
- 179
- 阅读权限
- 150
- 注册时间
- 2008-9-26
- 最后登录
- 2015-12-3
- 精华
- 3
- UID
- 2459
- 积分
- 14133
- 帖子
- 179
- 主题
- 19
- 阅读权限
- 150
- 注册时间
- 2008-9-26
- 最后登录
- 2015-12-3
|
本帖最后由 hyjok 于 2015-11-16 11:44 编辑
双均线策略测试公式- //------------------------------------------------------------------------
- // 简称: AutoChangeExitToday
- // 名称: 自动转换平今仓发单案例
- // 类别: 公式应用
- // 类型: 用户应用
- // 输出:
- //------------------------------------------------------------------------
- Params
- Numeric FastLength(5);
- Numeric SlowLength(20);
-
- Numeric DataN(0); //发单合约序列,不叠加合约时Data0为0、叠加合约Data1为1,以此类推DataN
- Numeric Lots(1);
- Numeric AOrder(1);//A函数发单开关,1为A函数发单,其他为不允许A函数发单
- Numeric iLastPrice(1);//1为用最新价报单,其他为对手价报单
- Numeric OffSet(10);//委托偏移跳数
- Numeric MaxLots(4);//对锁持仓最大手数,用户根据账户资金大小预设最大持仓手数,
- //应用时设置忽略所有自动交易,用A函数发单,适用于TBV5.2.3.16之前的版本(V5.2.3.16版本开始忽略自动交易也会忽略A函数发单)
- Vars
- NumericSeries AvgValue1;
- NumericSeries AvgValue2;
-
- Numeric myBuyPosition;
- Numeric myTodayBuyPosition;
- Numeric mySellPosition;
- Numeric myTodaySellPosition;
- Numeric myLots;
- Numeric MinPoint;
- Begin
- MinPoint = MinMove*PriceScale;
- If (A_AccountID<>"" && BarStatus==2)
- {
- myBuyPosition=Data[DataN].A_BuyPosition;
- myTodayBuyPosition=Data[DataN].A_TodayBuyPosition;
- mySellPosition=Data[DataN].A_SellPosition;
- myTodaySellPosition=Data[DataN].A_TodaySellPosition;
- }
- Commentary("myBuyPosition="+Text(myBuyPosition));
- Commentary("myTodayBuyPosition="+Text(myTodayBuyPosition));
- Commentary("mySellPosition="+Text(mySellPosition));
- Commentary("myTodaySellPosition="+Text(myTodaySellPosition));
-
- AvgValue1 = AverageFC(Close,FastLength);
- AvgValue2 = AverageFC(Close,SlowLength);
- If(MarketPosition <>1 && AvgValue1[1] > AvgValue2[1])
- {
- If (AOrder==1 && GetGlobalVar(0)<>1)//全局变量的作用是控制重复发单
- {
- If (AorderDataNBuy(DataN,IIF(MarketPosition==-1,2,1)*Lots,iLastPrice,OffSet,MaxLots)) SetGlobalVar(0,1);
- }
- Buy(Lots,Open);
- }
-
- If(MarketPosition <>-1 && AvgValue1[1] < AvgValue2[1])
- {
- If (AOrder==1 && GetGlobalVar(0)<>-1)
- {
- If (AOrderDataNSellShort(DataN,IIF(MarketPosition==1,2,1)*Lots,iLastPrice,OffSet,MaxLots)) SetGlobalVar(0,-1);
- }
- SellShort(Lots,Open);
- }
-
- If (MarketPosition==1 && C[1]<=EntryPrice*0.99)
- {
- If (AOrder==1 && GetGlobalVar(0)<>2)
- {
- If (AOrderDataNSellShort(DataN,Abs(CurrentContracts),iLastPrice,OffSet,MaxLots)) SetGlobalVar(0,2);
- }
- Sell(0,Open);
- }
- If (MarketPosition==-1 && C[1]>=EntryPrice*1.01)
- {
- If (AOrder==1 && GetGlobalVar(0)<>-2)
- {
- If (AorderDataNBuy(DataN,Abs(CurrentContracts),iLastPrice,OffSet,MaxLots)) SetGlobalVar(0,-2);
- }
- BuyToCover(0,Open);
- }
-
- PlotNumeric("MA1",AvgValue1);
- PlotNumeric("MA2",AvgValue2);
- End
复制代码 |
|