開拓者夾板交易策略源碼(振蕩交易模型)
作者:開拓者 TB 來源:cxh99.com 發(fā)布時(shí)間:2012年11月19日
- 內(nèi)容: 夾板在實(shí)盤中是一個(gè)很常見的運(yùn)用,用于吃住震蕩行情。它有個(gè)上軌和一個(gè)下軌,行情突破上軌就做空;突破下軌就做多,在上下軌之間來回吃。
OpenCoverFor2Lines函數(shù)代碼
- 源碼:
- // 返回值: 1:有所動(dòng)作,0:沒有動(dòng)作
- // 返回值為非零時(shí),把當(dāng)前要建立的頭寸大小和方向?qū)懭雗eedPosition,把以什么價(jià)格去建立該頭寸寫入needPrice
- // 返回值: 1:有所動(dòng)作,0:沒有動(dòng)作
- // 返回值為非零時(shí),把當(dāng)前要建立的頭寸大小和方向?qū)懭雗eedPosition,把以什么價(jià)格去建立該頭寸寫入needPrice
-
- Params
- Numeric currentPosition(0); // 當(dāng)前頭寸,可正可負(fù)
- Numeric firstLots(0);
-
- Numeric wantShort(120); // 開空倉位置
- Numeric wantLong(8); // 開多倉位置
-
- Numeric wantStopShort(0); // 空頭止損的位置
- Numeric wantStopLong(0); // 多頭止損的位置
-
-
- // 注意:以下兩個(gè)都是引用變量!!!!
- NumericRef needPosition; // 經(jīng)過計(jì)算后的當(dāng)前頭寸,正數(shù):建立多倉,負(fù)數(shù):建立空倉,零:平光所有頭寸
- NumericRef needPrice; // 建立needPosition時(shí)的價(jià)格
-
- Vars
- Numeric tem;
-
- Begin
-
- // 14:55:00平掉當(dāng)日所有頭寸
- if(time >= 0.1455 && currentPosition != 0)
- {
- needPosition = 0;
- needPrice = close ;
- return 1;
- }
- if(currentPosition == 0)
- {
- // 無倉,準(zhǔn)備侍機(jī)開倉
- if(close <= wantLong)
- {
- // 多頭 www.tumamayizhan.com
- needPosition = firstLots;
- needPrice = wantLong;
- return 1;
- }
- if(close >= wantShort)
- {
- // 空頭
- needPosition = -1 * firstLots;
- needPrice = wantShort;
- return 1;
-
- }
- return 0;
- }
-
- if(currentPosition > 0)
- {
- // 持多倉,準(zhǔn)備止損或反轉(zhuǎn)
- if(close >= wantShort)
- {
- // 反轉(zhuǎn)
- needPosition = -1 * firstLots;
- needPrice = wantShort;
- return 1;
- }
-
- if(close <= wantStopLong)
- {
- // 止損
- needPosition = 0;
- needPrice = wantStopLong;
- return 1;
-
- }
- return 0;
- }
- if(currentPosition < 0)
- {
- // 持空倉,準(zhǔn)備止損或反轉(zhuǎn)
- if(close <= wantLong)
- {
- // 反轉(zhuǎn)
- needPosition = firstLots;
- needPrice = wantLong;
- return 1;
- }
-
- if(close >= wantStopShort)
- {
- // 止損
- needPosition = 0;
- needPrice = wantStopShort;
- return 1;
-
- }
- return 0;
- }
- return 0;
- End
- // 來源: www.tumamayizhan.com