雙均線金叉開多平空,死叉開空平多,開倉間隔不小于50個bar
作者:開拓者 TB 來源:cxh99.com 發布時間:2013年06月28日
- 咨詢內容:
本帖最后由 leosu 于 2013-6-18 12:18 編輯
求編寫公式?雙均線交叉,金叉開多平空,死叉開空平多,且兩次多(空)間隔不小于50個bar。先謝謝了!!
- TB技術人員:
最近 版主都忙什么 來幫幫我呀
- TB客服:
請大家幫幫
- 網友回復:
再次頂起來 謝謝大家
- 網友回復:
本帖最后由 rucrui 于 2013-6-25 11:15 編輯
沒人回復的話我來獻丑吧,雙均線交叉,金叉買死叉賣,買賣我都加了滑點,用的次一根開盤價避免信號閃爍。唯一你說的間隔的,描述的有點簡單,我按我的理解寫,就是前一個時間點開多后50根BAR內不再開多,開空同理,如果不一樣自己照著我寫的稍微修改代碼就行。- Params
- Numeric n1(20);
- Numeric n2(60);
- Numeric lots(1);
- Numeric coverTime(50);
- Numeric splitRate(3);
-
- Vars
- Numeric splitDot; //交易滑點
- NumericSeries E1(0);
- NumericSeries E2(0);
- Numeric myprice;
- NumericSeries bCountTime(0);
- NumericSeries sCountTime(0);
-
- Begin
- splitDot=splitRate*MinMove()*PriceScale();
- E1=XAverage(C,n1);
- E2=XAverage(C,n2);
- PlotNumeric("E1",E1,0,Red);
- PlotNumeric("E2",E2,0,Green);
-
- bCountTime=bCountTime[1]+1;
- sCountTime=sCountTime[1]+1;
-
- If(MarketPosition==0)
- {
- If(E1[1]>E2[1] && bCountTime>coverTime)
- {
- myprice=Open+splitDot;
- Buy(lots, myprice);
- bCountTime=0;
- }
- else If(E1[1]<E2[1] && sCountTime>coverTime)
- {
- myprice=Open-splitDot;
- Sellshort(lots, myprice);
- sCountTime=0;
- }
- }
- else If(MarketPosition==1)
- {
- If(E1[1]<E2[1])
- {
- myprice=Open-splitDot;
- Sell(lots,myprice);
- If(sCountTime>coverTime)
- {
- Sellshort(lots, myprice);
- sCountTime=0;
- }
- }
- }
- else If(MarketPosition==-1)
- {
- If(E1[1]>E2[1])
- {
- myprice=Open+splitDot;
- BuyToCover(lots,myprice);
- If(bCountTime>coverTime)
- {
- Buy(lots, myprice);
- bCountTime=0;
- }
- }
- }
-
- Commentary("bCountTime:"+Text(bCountTime));
- Commentary("sCountTime:"+Text(sCountTime));
- End
-
復制代碼