開拓者 TB KD2號交易策略模型源碼
作者:開拓者 TB 來源:cxh99.com 發布時間:2013年03月14日
- 咨詢內容: 本帖最后由 woomin1985 于 2013-2-19 23:52 編輯
//------------------------------------------------------------------------
// 簡稱: kd2
// 名稱:
// 類別: 公式應用
// 類型: 用戶應用
// 輸出://程序化交易 www.tumamayizhan.com
//------------------------------------------------------------------------
Params
Numeric Length1(16);
Numeric Length2(35);
Numeric Length3(9);
Numeric Lots(1);
Vars
NumericSeries Value1;
NumericSeries Value2;
NumericSeries LowestValue;
NumericSeries Value5;
NumericSeries RSV;
NumericSeries KValue;
NumericSeries DValue;
NumericSeries AvgVol5;
NumericSeries CloseTmp1;
NumericSeries CloseTmp2;
NumericSeries RSIValue;
NumericSeries PreLow;
NumericSeries PreKValue;
NumericSeries Lowest33Value;
NumericSeries VarTmp1;
NumericSeries VarTmp2;
NumericSeries ZL;
NumericSeries SH;
Begin
Value1 =XAverage(Close,Length1);
Value2 =XAverage(Close,Length2);
//取兩條均線的值
LowestValue = Lowest(Low,Length3);
//取最低值
Value5= (CLOSE-LowestValue)/(Highest(High,Length3)-LowestValue)*100;
RSV =XAverage(Value5,3);
KValue = XAverage(RSV,3);
DValue =Average(KValue,3);
PreKValue =KValue[1];
PreLow =Low[1];
AvgVol5 =Average(Vol,5);
Lowest33Value= Lowest(Low,33);
VarTmp1=((2*CLOSE+HIGH+LOW)/4 - Lowest33Value )/(Highest(High,33) - Lowest33Value) *100;
ZL =XAverage(VarTmp1,17);
VarTmp2 =0.667*ZL[1] + 0.333*ZL;
SH =XAverage(VarTmp2,2);
CloseTmp1 =Max(Close - Close[1], 0);
CloseTmp2 =Abs(Close - Close[1]);
RSIValue =WAverage(CloseTmp1,6)/WAverage(CloseTmp2,6) *100;
//以上為KD部分只要如何換書寫方式就可了,,higest ==hhv lowest==llv xAverager=ma
// Buy什么時做買入動作,條件
If((Close[1]>Value1[1] and Close[2]<Value1[2] && KValue[1] > DValue[1] && ZL[1]>SH[1]) or
(Value1[1]>Value2[1] and Value1[2]<Value2[2] && ZL[1]>SH[1] && Vol[1]> 1.25 * AvgVol5[1] && KValue[1] > DValue[1]) Or
(KValue[1]>DValue[1] and KValue[2]<DValue[2] && Close[1] > Value1[1] && ZL[1]>SH[1]) Or
(RSIValue[1]>70 and RSIValue[2]<70))//條件
{
Buy(Lots,open+MinMove*PriceScale);
}
//SellShort 什么作賣出動作
If((PreLow[1]>Close[1] and PreLow[2]<Close[2] && KValue[1] > DValue[1] && SH>ZL) Or
(DValue[1]>KValue[1] and DValue[2]<KValue[2] && Close[1] < Value1[1] && Value1[1] < Value2[1]) Or
(PreKValue[1]>KValue[1] and PreKValue[2]<KValue[2] && SH[1]>ZL[1]))//條件
{
SellShort(Lots,open-MinMove*PriceScale);
}
// Sell 什么做多平倉動作
If((DValue[1]>KValue[1] and DValue[2]<KValue[2]) or Close[1] < Value1 [1]* 1.001)//條件
{
Sell(Lots,open-MinMove*PriceScale);;
}
//BuyToCover什么做空平倉動作
If((KValue[1]>DValue[1] and KValue[2]<DValue[2]) or Close[1] > Value1[1] * 1.001)//條件
{
BuyToCover(Lots,open+MinMove*PriceScale);
}
End