- 精华
- 0
- 在线时间
- 540 小时
- UID
- 15958
- 积分
- 1290
- 帖子
- 155
- 阅读权限
- 60
- 注册时间
- 2010-9-9
- 最后登录
- 2021-1-25
- 精华
- 0
- UID
- 15958
- 积分
- 1290
- 帖子
- 155
- 主题
- 22
- 阅读权限
- 60
- 注册时间
- 2010-9-9
- 最后登录
- 2021-1-25
|
本帖最后由 穿堂风 于 2011-7-1 13:40 编辑
我改了下,全部贴出来吧- Params
- Numeric Length1(10);
- Numeric Length2(20);
- Numeric Lots(1);
- Numeric InitialStop(20); // 初始止损(千分之N)
- Numeric BreakEvenStop(30); // 保本止损(千分之N)
- Numeric TrailingStop(50); // 追踪止损(千分之N)
-
- Vars
- NumericSeries MA1;
- NumericSeries MA2;
- BoolSeries condBuy(false);
- BoolSeries condSell(false);
- Numeric MinPoint;
- Numeric MyPrice;
- NumericSeries HigherAfterEntry;
- NumericSeries LowerAfterEntry;
- BoolSeries bLongStoped(false);
- BoolSeries bShortStoped(false);
- Numeric StopLine;
- Numeric StopLine1;
- Numeric StopLine2;
- Numeric StopLine3;
- String strDate;
- String strTime;
- String TRADENAME;
- Begin
- if(condBuy==false and condSell==false )
- {
- condBuy=condBuy[1];
- condSell=condSell[1];
- }
- if(BarStatus>0)
- {
- bLongStoped=bLongStoped[1]; //多头止损情况
- bShortStoped=bShortStoped[1]; //空头止损情况
- }
-
- MinPoint=MinMove * PriceScale;
- MA1=AverageFC(Close,Length1);
- MA2=AverageFC(Close,Length2);
- condBuy=CrossOver(MA1,MA2);
- condSell=CrossUnder(MA1,MA2);
-
- If(MarketPosition!=1 and condBuy[1]==true and bLongStoped==False)//初次进场做多
- {
- Buy(Lots,Open);
-
- HigherAfterEntry=Open;
- LowerAfterEntry=Open;
-
- bLongStoped=False;//重置标志
- bShortStoped=False;//重置标志
-
- Commentary("Buy Firsttime at "+text(Open));
- Commentary("HAE="+TEXT(HigherAfterEntry)+" LAE="+Text(LowerAfterEntry));
- Commentary("bLongStoped="+IIFString(bLongStoped,"TRUE","FALSE"));
- Commentary("bShortStoped="+IIFString(bShortStoped,"TRUE","FALSE"));
- }
- If(MarketPosition!=-1 and condSell[1]==true and bShortStoped==False)//初次进场做空
- {
- SellShort(lots,Open);
-
- HigherAfterEntry=Open;
- LowerAfterEntry=Open;
-
- bLongStoped=False;//重置标志
- bShortStoped=False;//重置标志
-
- Commentary("SellShort Firsttime at "+text(Open));
- Commentary("HAE="+TEXT(HigherAfterEntry)+" LAE="+Text(LowerAfterEntry));
- Commentary("bLongStoped="+IIFString(bLongStoped,"TRUE","FALSE"));
- Commentary("bShortStoped="+IIFString(bShortStoped,"TRUE","FALSE"));
- }
- If(BarsSinceEntry>=1)
- {
- HigherAfterEntry=Max(HigherAfterEntry[1],High[1]);
- LowerAfterEntry=Min(LowerAfterEntry[1],Low[1]);
- }
- Else
- {
- HigherAfterEntry=HigherAfterEntry[1];
- LowerAfterEntry=LowerAfterEntry[1];
- }
- If(MarketPosition==1)//多头止损部分的代码
- {
- StopLine=EntryPrice * (1-InitialStop/1000);
- If (HigherAfterEntry>=EntryPrice*(1+BreakEvenStop/1000))
- {
- StopLine=EntryPrice;
- }
- If (StopLine<HigherAfterEntry*(1-TrailingStop/1000))
- {
- StopLine=HigherAfterEntry*(1-TrailingStop/1000);
- }
-
- Commentary("止损价:"+Text(StopLine));
-
- If(Low<=StopLine)// 止损触发
- {
- MyPrice=StopLine;
- If(Open<MyPrice)
- {
- MyPrice=Open;
- }
- Sell(Lots,MyPrice);
-
- bLongStoped=True; // 止损后设置标志
-
- Commentary("Long Position Stoped at "+text(MyPrice));
- }
- }
- If(MarketPosition==-1)//空头止损部分的代码
- {
- StopLine=EntryPrice*(1+InitialStop/1000);
- If(LowerAfterEntry<=EntryPrice*(1+BreakEvenStop/1000)) StopLine=EntryPrice;
- If(StopLine>LowerAfterEntry*(1+TrailingStop/1000)) StopLine=LowerAfterEntry*(1+TrailingStop/1000);
-
- Commentary("止损价:"+Text(StopLine));
-
- If(High>=StopLine)// 止损触发
- {
- MyPrice=StopLine;
- If(Open>MyPrice)
- {
- MyPrice=Open;
- }
- BuyToCover(Lots,MyPrice);
-
- bShortStoped=True; // 止损后设置标志
-
- Commentary("Short Position Stoped at "+text(MyPrice));
- }
- }
- IF(bLongStoped AND MarketPosition==0 AND H>HigherAfterEntry)//二次进场做多
- {
- MyPrice=HigherAfterEntry+MinPoint;
- If(Open>MyPrice)
- {
- MyPrice=Open;
- }
-
- Buy(Lots,MyPrice);
-
- bLongStoped=False;
-
- HigherAfterEntry=AvgEntryPrice;
- LowerAfterEntry=HigherAfterEntry;
-
- Commentary("Buy Secondtime at "+text(Open));
- Commentary("HAE="+TEXT(HigherAfterEntry)+" LAE="+Text(LowerAfterEntry));
- Commentary("bLongStoped="+IIFString(bLongStoped,"TRUE","FALSE"));
- Commentary("bShortStoped="+IIFString(bShortStoped,"TRUE","FALSE"));
-
- Return;
- }
- If(bShortStoped AND MarketPosition==0 AND L<LowerAfterEntry)//二次进场做空
- {
- MyPrice=LowerAfterEntry - MinPoint;
- If(Open<MyPrice)
- {
- MyPrice = Open;
- }
-
- SellShort(Lots,MyPrice);
-
- bShortStoped=False;
-
- HigherAfterEntry=AvgEntryPrice;
- LowerAfterEntry=HigherAfterEntry;
-
- Commentary("SellShort Secondtime at "+text(Open));
- Commentary("HAE="+TEXT(HigherAfterEntry)+" LAE="+Text(LowerAfterEntry));
- Commentary("bLongStoped="+IIFString(bLongStoped,"TRUE","FALSE"));
- Commentary("bShortStoped="+IIFString(bShortStoped,"TRUE","FALSE"));
-
- Return;
- }
- End
复制代码 |
|