曬個程序,扔磚的扔磚啊,不要對我客氣 - TradeBlazer公式 [開拓者 TB]
- 咨詢內容:
交易策略是這樣的:1.先在1min bar上運行,買入的條件是:跳空高開,或則(收盤價上穿600均價 &&( 紅柱同步放大 或 出現金叉));賣空的條件是: 跳空低開, 或則(收盤價下破600均價 && (綠柱同步放大 或則 出現死叉));
2. 平倉的條件是:若為多倉,則當收盤價下穿600均價時,平;若為空倉,則當收盤價上穿600均價時,平;
3. 若在30min內連續平倉3次,則調用5min;然后繼續用五分鐘線做1,2的判斷,判斷條件相同;
4. 若在5分鐘線也出現連續三次平倉時間小于5X30=150min, 則調用15分線;
5. 若在15分。。。。
6. 最后調用30分線,不再調用更長的數據。
小弟編了個策略,還附帶了幾個函數,運行之后沒有語法錯誤,就是沒有信號!
請管理員能不能指點一下?
管理員
各路高手
策略:
Params
numeric buyAmount(1);
numeric sellAmount(1);
Vars
NumericSeries myOpen;
NumericSeries myClose;
NumericSeries myHigh;
NumericSeries myLow;
NumericSeries myCloseAverage;
numeric length;
numeric timeInterval(5);
Begin
// GetGlobalVar(4)表示相鄰3次平倉的時間間隔
// 1min線調用的條件是在前兩次平倉,或則在連續三次平倉的時間間隔>0.0030時
if (GetGlobalVar(4)==InvalidNumeric || GetGlobalVar(4)>0.0030)
{
// 建倉條件
if (BarStatus==2 && MarketPosition>=0 && open>high[1])
{
Buy(buyAmount,Q_AskPrice);
}else if(BarStatus==2 && MarketPosition<=0 && open<low[1])
{
SellShort(sellAmount,Q_BidPrice);
}else if (BarStatus==2 && marketposition>=0 && High>Average(close,600) && ( GreenOrRed(12,26,9)==1 || CrossOver(Average(close,12),Average(close,26))))
{
buy(buyAmount,Q_AskPrice);
}else if (BarStatus==2 && MarketPosition<=0 && low<Average(close,600) && (GreenOrRed(12,26,9)==-1 || Crossunder(Average(close,12),Average(close,26))))
{
SellShort(sellAmount,Q_BidPrice);
}
// 建倉完畢
// 平倉條件
if (MarketPosition==1 && close<Average(close,600))
{
Sell();
if (GetGlobalVar(1)==InvalidNumeric)
{
SetGlobalVar(1,time);
}else
{
if (GetGlobalVar(2)==InvalidNumeric)
{
SetGlobalVar(2,time);
}else
{
if (GetGlobalVar(3)==InvalidNumeric)
{
SetGlobalVar(3,time);
}else
{
SetGlobalVar(1,GetGlobalVar(2));
SetGlobalVar(2,GetGlobalVar(3));
SetGlobalVar(3,time);
}
}
} // 連續三次平倉時間的滾動記錄.
}else if (MarketPosition==-1 && close>Average(close,600))
{
BuyToCover();
if (GetGlobalVar(1)==InvalidNumeric)
{
SetGlobalVar(1,time);
}else
{
if (GetGlobalVar(2)==InvalidNumeric)
{
SetGlobalVar(2,time);
}else
{
if (GetGlobalVar(3)==InvalidNumeric)
{
SetGlobalVar(3,time);
}else
{
SetGlobalVar(1,GetGlobalVar(2));
SetGlobalVar(2,GetGlobalVar(3));
SetGlobalVar(3,time);
}
}
}
}
// 平倉完畢
if (GetGlobalVar(3)!=InvalidNumeric)
{
SetGlobalVar(4,GetGlobalVar(3)-GetGlobalVar(1)); //用全局變量GetGlobalVar(4)來記錄連續三次平
// 倉時間的間隔:若GetGlobalVar(4)>0.0030,前部分程序塊不會運行
}
}else
{
// 若前面if的程序不被執行,說明連續三次平倉的時間間隔小于0,003;避免市場拉鋸,調用更長周期的數據
// 更長周期的數據調用,在下面的代嗎里面類似一個逐步開鎖的過程,鎖便是全局數GetGlobalVar(5) 和 GetGlobalVar(15)
if (GetGlobalVar(5)==InvalidNumeric)
{
timeInterval=5;
}else
{
if (GetGlobalVar(15)==InvalidNumeric)
{
timeInterval=15;
}else
{
timeInterval=30; // 最大調用30min線
}
}
// 開鎖結束
// 調用5min的時間線,數據轉換
myOpen=DataConvert(open,"min",timeInterval,"open");
myClose=DataConvert(close,"min",timeInterval,"close");
myHigh=DataConvert(high,"min",timeInterval,"high");
myLow=DataConvert(low,"min",timeInterval,"low");
// 跨周期計算均值,跨周期判斷穿破,跨周期判斷紅綠放大,見函數Average_transTimeInterval,
// GreenOrRed_transTimeInterval,以及crossOver_transTimeIntrval,CrossUnder_transTimeInterval
// 先計算跨周期收盤價的均值,為后面的判斷準備
myCloseAverage=average_transMinData(myClose,100); //選擇平均周期是100次,對于5min而言,就是5min總共500分鐘的100次收盤價格
// 跨周期調用數據,并判斷是否開倉
if (BarStatus==2 && MarketPosition>=0 && transMinsData(myOpen,timeInterval,0)>transMinsData(myHigh,timeInterval,1))
{
Buy(buyAmount,Q_AskPrice);
}else if (BarStatus==2 && MarketPosition<=0 && transMinsData(myOpen,timeInterval,0)<transMinsData(myLow,timeInterval,1))
{
SellShort(sellAmount,Q_BidPrice);
}else if (BarStatus==2 && MarketPosition>=0 && transMinsData(myHigh)>average_transMinData(myclose,100) && (GreenOrRed_transTimeInterval(myclose,timeInterval,12,26,9)==1 || crossOver_transTimeIntrval(average_transMinData(myclose,12),average_transMinData(myclose,26))==true))
{
Buy(buyAmount,Q_AskPrice);
}else if (BarStatus==2 && MarketPosition<=0 && transMinsData(myHigh)<average_transMinData(myclose,100) && (GreenOrRed_transTimeInterval(myclose,timeInterval,12,26,9)==-1 || CrossUnder_transTimeInterval(average_transMinData(myclose,12),average_transMinData(myclose,26))==true))
{
SellShort(sellAmount,Q_BidPrice);
}
// 跨周期建倉完畢
// 跨周期平倉條件
if (MarketPosition==1 && close<average_transMinData(myClose,100))
{
Sell();
if (GetGlobalVar(timeInterval)==InvalidNumeric)
{
SetGlobalVar(timeInterval+1,time);
}else
{
if (GetGlobalVar(timeInterval+2)==InvalidNumeric)
{
SetGlobalVar(timeInterval+2,time);
}else
{
if (GetGlobalVar(timeInterval+3)==InvalidNumeric)
{
SetGlobalVar(timeInterval+3,time);
}else
{
SetGlobalVar(timeInterval+1,GetGlobalVar(timeInterval+2));
SetGlobalVar(timeInterval+2,GetGlobalVar(timeInterval+3));
SetGlobalVar(timeInterval+3,time);
}
}
} // 連續三次平倉時間的滾動記錄.
}else if (MarketPosition==-1 && close>average_transMinData(myclose,600))
{
BuyToCover();
if (GetGlobalVar(timeInterval)==InvalidNumeric)
{
SetGlobalVar(timeInterval+1,time);
}else
{
if (GetGlobalVar(timeInterval+2)==InvalidNumeric)
{
SetGlobalVar(timeInterval+2,time);
}else
{
if (GetGlobalVar(timeInterval+3)==InvalidNumeric)
{
SetGlobalVar(timeInterval+3,time);
}else
{
SetGlobalVar(timeInterval+1,GetGlobalVar(timeInterval+2));
SetGlobalVar(timeInterval+2,GetGlobalVar(timeInterval+3));
SetGlobalVar(timeInterval+3,time);
}
}
} // 連續三次平倉時間的滾動記錄.
}
// 跨周期平倉結束
// 計算跨周期連續三次平倉的時間,若連續平倉時間大于30*周期長度,則賦予相應全局變量值,達到開鎖的作用
// 總而啟動更長周期的數據調用
if (GetGlobalVar(timeInterval+3)!=InvalidNumeric)
{
if (GetGlobalVar(timeInterval+3)-GetGlobalVar(timeInterval+1)<timeInterval*30)
{
SetGlobalVar(timeInterval,1); // 給開鎖變量賦值
}
}
}
End - TB技術人員:
本帖最后由 Ransoros 于 2011-12-30 10:20 編輯
回復 1# Ransoros
自建函數:
1. GreenOrRed: 判斷是否出現紅柱放大或綠柱放大,紅返回1,綠返回-1;
Params
Numeric FastLength(12);
Numeric SlowLength(26);
Numeric MACDLength(9);
Vars
NumericSeries MACDValue;
Numeric AvgMACD;
NumericSeries MACDDiff;
Begin
MACDValue = XAverage( Close, FastLength ) - XAverage( Close, SlowLength ) ;
AvgMACD = XAverage(MACDValue,MACDLength);
MACDDiff = MACDValue - AvgMACD;
if (MACDDiff>MACDDiff[1] && MACDDiff[1]>0)
{
return 1;
}else if (MACDDiff<MACDDiff[1] && macddiff[1]<0)
{
return -1;
}
End
2. transMinData
這個就不好意思了,非原創,謝謝斑竹的經驗分享!?。。。?!
Params
NumericSeries Price(1);
numeric nMinSet(5);
numeric minsAgo(0);
Vars
NumericSeries barCnt;
NumericSeries minData;
numeric i;
numeric j;
numeric nindex(0);
Begin
if (IntPart(minute%nMinSet)==0)
{
barCnt=1;
}Else
{
barCnt=barCnt+1;
}
minData=price;
if (minsAgo==0)
{
return minData;
}Else
{
for i=1 to minsAgo
{
if (i==1)
{
j=0;
}Else
{
j=j+barCnt[j];
}
if (j>CurrentBar)
{
return InvalidNumeric;
}
nindex=nindex+barCnt[j];
}
return minData[nindex];
}
End
3. average_transMinData 跨周期取均值
params
NumericSeries Price(1);
numeric length(5);
Vars
Numeric sumValue(0);
Numeric meanValue;
numeric index;
Begin
for index=0 to length-1
{
sumValue=sumValue+transMinsData(price,length,index);
}
meanValue=sumValue/length;
return meanValue;
End
4. crossOver_transMinData跨周期判斷是否出現上穿,是就返回true,否就false
Params
NumericSeries Price1(1);
NumericSeries Price2(1);
numeric timeLength(5);
Vars
bool con1(false);
bool con2(false);
numeric counter(0);
Begin
if (transMinsData(price1,timeLength,0)>transMinsData(price2,timeLength,0))
{
counter=1;
con1=(transMinsData(price1,timeLength,1)==transMinsData(price2,timeLength,1));
while (con1 && counter<IntPart(currentbar/timeLength))
{
counter=counter+1;
con1=(transMinsData(price1,timeLength,counter)==transMinsData(price2,timeLength,counter));
}
con2=(transMinsData(price1,timeLength,counter)<transMinsData(price2,timeLength,counter));
return con2;
}Else
{
return false;
}
End
5. crossUnder_transMInData 跨周期判斷是否出現下穿,是就返回true,否就false
Params
NumericSeries Price1(1);
NumericSeries Price2(1);
numeric timeLength(5);
Vars
bool con1(false);
bool con2(false);
numeric counter(0);
Begin
if (transMinsData(price1,timeLength,0)<transMinsData(price2,timeLength,0))
{
counter=1;
con1=(transMinsData(price1,timeLength,1)==transMinsData(price2,timeLength,1));
while (con1 && counter<IntPart(currentbar/timeLength))
{
counter=counter+1;
con1=(transMinsData(price1,timeLength,counter)==transMinsData(price2,timeLength,counter));
}
con2=(transMinsData(price1,timeLength,counter)>transMinsData(price2,timeLength,counter));
return con2;
}Else
{
return false;
}
End
6. GreenOrRed_transMinData 跨周期判斷是否出現紅柱或綠柱放大,紅返回1,綠返回-1
Params
NumericSeries Price(1);
numeric timeLength(5);
numeric fastLength(12);
numeric slowLength(26);
numeric MACDLength(9);
Vars
NumericSeries MACDValue;
NumericSeries AvgMACD;
NumericSeries MACDDiff;
numeric i;
numeric sum1(0);
numeric sum2(0);
numeric sum3(0);
Begin
for i=0 to fastLength-1
{
sum1=sum1+transMinsData(price,fastLength,i); // transMinsData函數起到跨時間取值的作用。
}
for i=0 to slowLength-1
{
sum2=sum2+transMinsData(price,slowLength,i);
}
MACDValue=sum1/fastLength-sum2/slowLength;
for i=0 to timeLength-1
{
sum3=sum3+transMinsData(MACDValue,timeLength,i);
}
avgMACD=sum3/timeLength;
MACDDiff=MACDValue-avgMACD;
if (transMinsData(MACDDiff,timeLength,0)>transMinsData(MACDDiff,timeLength,1) && transMinsData(MACDDiff,timeLength,1)>0)
{
return 1;
}Else if (transMinsData(MACDDiff,timeLength,0)<transMinsData(macddiff,timeLength,1) && transMinsData(macddiff,timeLength,1)<0)
{
return -1;
}
End - TB客服:
不要啊!
- 網友回復:
改了一下,就好多了!哈哈。
Params
numeric buyAmount(1);
numeric sellAmount(1);
Vars
NumericSeries myOpen;
NumericSeries myClose;
NumericSeries myHigh;
NumericSeries myLow;
NumericSeries myCloseAverage;
numeric length;
numeric timeInterval(5);
Begin
// GetGlobalVar(4)表示相鄰3次平倉的時間間隔
// 1min線調用的條件是在前兩次平倉,或則在連續三次平倉的時間間隔>0.0030時
SetGlobalVar(1,999999);
SetGlobalVar(2,999999);
SetGlobalVar(3,999999);
SetGlobalVar(4,999999);
if (GetGlobalVar(4)>0.0030)
{
// 建倉條件
if (BarStatus==2 && MarketPosition>=0 && open>high[1])
{
Buy(buyAmount,Q_AskPrice);
}else if(BarStatus==2 && MarketPosition<=0 && open<low[1])
{
SellShort(sellAmount,Q_BidPrice);
}else if (BarStatus==2 && marketposition>=0 && High>Average(close,600) && ( GreenOrRed(12,26,9)==1 || CrossOver(Average(close,12),Average(close,26))))
{
buy(buyAmount,high);
}else if (BarStatus==2 && MarketPosition<=0 && low<Average(close,600) && (GreenOrRed(12,26,9)==-1 || Crossunder(Average(close,12),Average(close,26))))
{
SellShort(sellAmount,low);
}
// 建倉完畢
// 平倉條件
if (MarketPosition==1 && close<Average(close,600))
{
Sell();
if (GetGlobalVar(1)==999999)
{
SetGlobalVar(1,time);
}else
{
if (GetGlobalVar(2)==999999)
{
SetGlobalVar(2,time);
}else
{
if (GetGlobalVar(3)==999999)
{
SetGlobalVar(3,time);
}else
{
SetGlobalVar(1,GetGlobalVar(2));
SetGlobalVar(2,GetGlobalVar(3));
SetGlobalVar(3,time);
}
}
} // 連續三次平倉時間的滾動記錄.
}else if (MarketPosition==-1 && close>Average(close,600))
{
BuyToCover();
if (GetGlobalVar(1)==999999)
{
SetGlobalVar(1,time);
}else
{
if (GetGlobalVar(2)==999999)
{
SetGlobalVar(2,time);
}else
{
if (GetGlobalVar(3)==999999)
{
SetGlobalVar(3,time);
}else
{
SetGlobalVar(1,GetGlobalVar(2));
SetGlobalVar(2,GetGlobalVar(3));
SetGlobalVar(3,time);
}
}
}
}
// 平倉完畢
if (GetGlobalVar(3)!=999999)
{
SetGlobalVar(4,GetGlobalVar(3)-GetGlobalVar(1)); //用全局變量GetGlobalVar(4)來記錄連續三次平
// 倉時間的間隔:若GetGlobalVar(4)>0.0030,前部分程序塊不會運行
}
}else
{
// 若前面if的程序不被執行,說明連續三次平倉的時間間隔小于0,003;避免市場拉鋸,調用更長周期的數據
// 更長周期的數據調用,在下面的代嗎里面類似一個逐步開鎖的過程,鎖便是全局數GetGlobalVar(5) 和 GetGlobalVar(15)
SetGlobalVar(5,999999);
SetGlobalVar(6,999999);
SetGlobalVar(7,999999);
SetGlobalVar(8,999999);
SetGlobalVar(15,999999);
SetGlobalVar(16,999999);
SetGlobalVar(17,999999);
SetGlobalVar(18,999999);
SetGlobalVar(30,999999);
SetGlobalVar(31,999999);
SetGlobalVar(32,999999);
SetGlobalVar(33,999999);
if (GetGlobalVar(5)==999999)
{
timeInterval=5;
}else
{
if (GetGlobalVar(15)==999999)
{
timeInterval=15;
}else
{
timeInterval=30; // 最大調用30min線
}
}
// 開鎖結束
// 調用5min的時間線,數據轉換
myOpen=DataConvert(open,"min",timeInterval,"open");
myClose=DataConvert(close,"min",timeInterval,"close");
myHigh=DataConvert(high,"min",timeInterval,"high");
myLow=DataConvert(low,"min",timeInterval,"low");
// 跨周期計算均值,跨周期判斷穿破,跨周期判斷紅綠放大,見函數Average_transTimeInterval,
// GreenOrRed_transTimeInterval,以及crossOver_transTimeIntrval,CrossUnder_transTimeInterval
// 先計算跨周期收盤價的均值,為后面的判斷準備
myCloseAverage=average_transMinData(myClose,100); //選擇平均周期是100次,對于5min而言,就是5min總共500分鐘的100次收盤價格
// 跨周期調用數據,并判斷是否開倉
if (BarStatus==2 && MarketPosition>=0 && transMinsData(myOpen,timeInterval,0)>transMinsData(myHigh,timeInterval,1))
{
Buy(buyAmount,Q_AskPrice);
}else if (BarStatus==2 && MarketPosition<=0 && transMinsData(myOpen,timeInterval,0)<transMinsData(myLow,timeInterval,1))
{
SellShort(sellAmount,Q_BidPrice);
}else if (BarStatus==2 && MarketPosition>=0 && transMinsData(myHigh)>average_transMinData(myclose,100) && (GreenOrRed_transTimeInterval(myclose,timeInterval,12,26,9)==1 || crossOver_transTimeIntrval(average_transMinData(myclose,12),average_transMinData(myclose,26))==true))
{
Buy(buyAmount,high);
}else if (BarStatus==2 && MarketPosition<=0 && transMinsData(myHigh)<average_transMinData(myclose,100) && (GreenOrRed_transTimeInterval(myclose,timeInterval,12,26,9)==-1 || CrossUnder_transTimeInterval(average_transMinData(myclose,12),average_transMinData(myclose,26))==true))
{
SellShort(sellAmount,low);
}
// 跨周期建倉完畢
// 跨周期平倉條件
if (MarketPosition==1 && close<average_transMinData(myClose,100))
{
Sell();
if (GetGlobalVar(timeInterval)==999999)
{
SetGlobalVar(timeInterval+1,time);
}else
{
if (GetGlobalVar(timeInterval+2)==999999)
{
SetGlobalVar(timeInterval+2,time);
}else
{
if (GetGlobalVar(timeInterval+3)==999999)
{
SetGlobalVar(timeInterval+3,time);
}else
{
SetGlobalVar(timeInterval+1,GetGlobalVar(timeInterval+2));
SetGlobalVar(timeInterval+2,GetGlobalVar(timeInterval+3));
SetGlobalVar(timeInterval+3,time);
}
}
} // 連續三次平倉時間的滾動記錄.
}else if (MarketPosition==-1 && close>average_transMinData(myclose,600))
{
BuyToCover();
if (GetGlobalVar(timeInterval)==999999)
{
SetGlobalVar(timeInterval+1,time);
}else
{
if (GetGlobalVar(timeInterval+2)==999999)
{
SetGlobalVar(timeInterval+2,time);
}else
{
if (GetGlobalVar(timeInterval+3)==999999)
{
SetGlobalVar(timeInterval+3,time);
}else
{
SetGlobalVar(timeInterval+1,GetGlobalVar(timeInterval+2));
SetGlobalVar(timeInterval+2,GetGlobalVar(timeInterval+3));
SetGlobalVar(timeInterval+3,time);
}
}
} // 連續三次平倉時間的滾動記錄.
}
// 跨周期平倉結束
// 計算跨周期連續三次平倉的時間,若連續平倉時間大于30*周期長度,則賦予相應全局變量值,達到開鎖的作用
// 總而啟動更長周期的數據調用
if (GetGlobalVar(timeInterval+3)!=999999)
{
if (GetGlobalVar(timeInterval+3)-GetGlobalVar(timeInterval+1)<timeInterval*30)
{
SetGlobalVar(timeInterval,1); // 給開鎖變量賦值
}
}
}
End - 網友回復:
果然沒人理。
有思路,想編寫各種指標公式,程序化交易模型,選股公式,預警公式的朋友
可聯系技術人員 QQ: 262069696 進行 有償 編寫!(不貴!點擊查看價格!)
- 上一篇:如何刪除人工的止損單
- 下一篇:過濾集合競價報單
相關文章
-
指定的模型還沒有相關內容!