以文本方式查看主题

-  金字塔客服中心 - 专业程序化交易软件提供商  (http://222.73.7.161/bbs/index.asp)
--  公式模型编写问题提交  (http://222.73.7.161/bbs/list.asp?boardid=4)
----  请高手将一个TB交易系统修改为金字塔交易系统  (http://222.73.7.161/bbs/dispbbs.asp?boardid=4&id=6833)

--  作者:CITSCWB
--  发布时间:2011/6/11 14:34:55
--  请高手将一个TB交易系统修改为金字塔交易系统

Params
 Numeric PercentOfRange(0.4);
 Numeric MinRange(0.2);
 Numeric StopLossSet(0.2);
 Numeric LastTradeMins(14.50);
 Numeric ExitOnCloseMins(14.55);
 Numeric Begintradetime(9.30);
 Numeric Lots(1);
 Numeric TrailingStart(0.1);
 Numeric TrailingStop(0.5);
 Numeric FailureLimit(2);
       Numeric Rangefilter1(0);
       Numeric Rangefilter2(1.5);
    Numeric slip(1);

Vars
    NumericSeries DayOpen;
    Numeric preDayHigh;
    Numeric preDayLow;   
    NumericSeries preDayRange;
 Numeric UpperBand;
 Numeric LowerBand;
 Numeric MyPrice;
 Numeric StopLine;
 NumericSeries HigherAfterEntry;
    NumericSeries LowerAfterEntry;
 BoolSeries  bLongStoped;
    BoolSeries  bShortStoped;
 Numeric MinPoint;
 Bool bInBoardRange;
 NumericSeries FailureCnts;
       NumericSeries range;


Begin
   

    MinPoint = MinMove*PriceScale;
    preDayHigh = HighD(1);
    preDayLow = LowD(1);
   
    range=((preDayHigh-preDayLow)/preDayLow)*100;
    If(range>Rangefilter2)
    {
    Return;
    }
 If(range<Rangefilter1)
 {
 Return;
 }
    If(Date!=Date[1])
    {
        DayOpen = Open;
        preDayRange = preDayHigh - preDayLow;
        If(preDayRange < Open*MinRange*0.01)
  preDayRange = Open*MinRange*0.01;
  bLongStoped = False;
     bShortStoped = False;
     HigherAfterEntry = High;
     LowerAfterEntry = Low;
  FailureCnts = 0;
    }Else
    {
        DayOpen = DayOpen[1];
        preDayRange = preDayRange[1];
     bLongStoped = bLongStoped[1];
     bShortStoped = bShortStoped[1];
  HigherAfterEntry = max(HigherAfterEntry[1],High[1]);
        LowerAfterEntry = min(LowerAfterEntry[1],Low[1]);
        If(BarsSinceEntry == 1)
        {
         //If (MarketPosition==1)
   HigherAfterEntry = AvgEntryPrice;
         //If (MarketPosition==-1)
   LowerAfterEntry = AvgEntryPrice;
        }
  FailureCnts = FailureCnts[1];
    }
    Commentary("FailureCnts="+Text(FailureCnts));
 Commentary("bLTrue","False"));
    Commentary("bShortStoped="+IIFString(bShortStoped,"True","False"));
 

 Commentary("HigherAfterEntry="+Text(HigherAfterEntry));
    Commentary("LowerAfterEntry="+Text(LowerAfterEntry));
 
 UpperBand = DayOpen + preDayRange*PercentOfRange;
 LowerBand = DayOpen - preDayRange*PercentOfRange;
 
 bInBoardRange = (Open < Q_LowerLimit + DayOpen*StopLossSet*0.02) Or ( Open > Q_UpperLimit - DayOpen*StopLossSet*0.02);
 
 If(Open == Q_UpperLimit) Sell(1,Open);
 If(Open == Q_LowerLimit) BuyToCover(Lots,Open);
 
 If(MarketPosition!=1 && High>=UpperBand && Time < LastTradeMins/100 && bLongStoped==False && FailureCnts < FailureLimit&&Time>(Begintradetime/100))
 {
  MyPrice = UpperBand;
  If(Open > MyPrice) MyPrice = Open+slip;
  Buy(Lots,MyPrice);
  bLongStoped = True;
  Return;
 }
 If(MarketPosition!=-1 && Low<=LowerBand && Time < LastTradeMins/100 && bShortStoped==False && FailureCnts < FailureLimit&&Time>(Begintradetime/100))
 {
  MyPrice = LowerBand;
  If(Open < MyPrice) MyPrice = Open-slip;
  SellShort(Lots,MyPrice);
  bShortStoped = True;
  Return;
 }
    If(MarketPosition==1)
    {
     If(HigherAfterEntry>=AvgEntryPrice+DayOpen*TrailingStart*0.01)
     {
      StopLine = HigherAfterEntry - DayOpen*TrailingStop*0.01;
     }Else // 止损
     {
      StopLine = AvgEntryPrice-DayOpen*StopLossSet*0.01;
     }
     If(Low <= StopLine)
     {
   If(PositionProfit < 0 ) FailureCnts = FailureCnts + 1;
      MyPrice = StopLine;
      If(Open < MyPrice) MyPrice = Open-slip;
      Sell(Lots,MyPrice);
   bLongStoped = True;
            Return;
     }
    }
 Else If(MarketPosition==-1)
    {
     If(LowerAfterEntry<=AvgEntryPrice-DayOpen*TrailingStart*0.01)
     {
      StopLine = LowerAfterEntry + DayOpen*TrailingStop*0.01;
     }Else // 止损
     {
         StopLine = AvgEntryPrice+DayOpen*StopLossSet*0.01;
  }
     If(High >= StopLine)
     {
   If(PositionProfit < 0 ) FailureCnts = FailureCnts + 1;
      MyPrice = StopLine;
      If(Open > MyPrice) MyPrice = Open+slip;
      BuyToCover(Lots,MyPrice);
   bShortStoped= True;
            Return;
     }
    }
 
 //突破前期高低点再次入场
 If(bLongStoped && MarketPosition==0 && High > HigherAfterEntry && Time < LastTradeMins/100  && FailureCnts < FailureLimit)
 {
  MyPrice = HigherAfterEntry + MinPoint;
  If(Open > MyPrice) MyPrice = Open+slip;
  Buy(Lots,MyPrice);
  bLongStoped = False;
  Return;
 }
 If(bShortStoped && MarketPosition==0 && Low < LowerAfterEntry && Time < LastTradeMins/100  && FailureCnts < FailureLimit)
 {
  MyPrice = LowerAfterEntry - MinPoint;
  If(Open < MyPrice) MyPrice = Open-slip;
  SellShort(Lots,MyPrice);
  bShortStoped= False;
  Return;
 }

 // 收盘平仓
 If(Time >=ExitOnCloseMins/100)
 {
  Sell(Lots,Open+slip);
  BuyToCover(Lots,Open-slip);
 }
 SetExitOnClose;
End

[此贴子已经被作者于2011-6-11 14:37:10编辑过]

--  作者:26327756l
--  发布时间:2011/6/13 10:16:49
--  

看不懂,不如你把策略用语言文字描写出来,看看能不能写.