曬個(gè)程序,扔磚的扔磚啊,不要對(duì)我客氣 - TradeBlazer公式 [開(kāi)拓者 TB]
- 咨詢內(nèi)容:
交易策略是這樣的:1.先在1min bar上運(yùn)行,買入的條件是:跳空高開(kāi),或則(收盤(pán)價(jià)上穿600均價(jià) &&( 紅柱同步放大 或 出現(xiàn)金叉));賣空的條件是: 跳空低開(kāi), 或則(收盤(pán)價(jià)下破600均價(jià) && (綠柱同步放大 或則 出現(xiàn)死叉));
2. 平倉(cāng)的條件是:若為多倉(cāng),則當(dāng)收盤(pán)價(jià)下穿600均價(jià)時(shí),平;若為空倉(cāng),則當(dāng)收盤(pán)價(jià)上穿600均價(jià)時(shí),平;
3. 若在30min內(nèi)連續(xù)平倉(cāng)3次,則調(diào)用5min;然后繼續(xù)用五分鐘線做1,2的判斷,判斷條件相同;
4. 若在5分鐘線也出現(xiàn)連續(xù)三次平倉(cāng)時(shí)間小于5X30=150min, 則調(diào)用15分線;
5. 若在15分。。。。
6. 最后調(diào)用30分線,不再調(diào)用更長(zhǎng)的數(shù)據(jù)。
小弟編了個(gè)策略,還附帶了幾個(gè)函數(shù),運(yùn)行之后沒(méi)有語(yǔ)法錯(cuò)誤,就是沒(méi)有信號(hào)!
請(qǐng)管理員能不能指點(diǎn)一下?
管理員
各路高手
策略:
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次平倉(cāng)的時(shí)間間隔
// 1min線調(diào)用的條件是在前兩次平倉(cāng),或則在連續(xù)三次平倉(cāng)的時(shí)間間隔>0.0030時(shí)
if (GetGlobalVar(4)==InvalidNumeric || GetGlobalVar(4)>0.0030)
{
// 建倉(cāng)條件
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);
}
// 建倉(cāng)完畢
// 平倉(cāng)條件
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);
}
}
} // 連續(xù)三次平倉(cāng)時(shí)間的滾動(dòng)記錄.
}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);
}
}
}
}
// 平倉(cāng)完畢
if (GetGlobalVar(3)!=InvalidNumeric)
{
SetGlobalVar(4,GetGlobalVar(3)-GetGlobalVar(1)); //用全局變量GetGlobalVar(4)來(lái)記錄連續(xù)三次平
// 倉(cāng)時(shí)間的間隔:若GetGlobalVar(4)>0.0030,前部分程序塊不會(huì)運(yùn)行
}
}else
{
// 若前面if的程序不被執(zhí)行,說(shuō)明連續(xù)三次平倉(cāng)的時(shí)間間隔小于0,003;避免市場(chǎng)拉鋸,調(diào)用更長(zhǎng)周期的數(shù)據(jù)
// 更長(zhǎng)周期的數(shù)據(jù)調(diào)用,在下面的代嗎里面類似一個(gè)逐步開(kāi)鎖的過(guò)程,鎖便是全局?jǐn)?shù)GetGlobalVar(5) 和 GetGlobalVar(15)
if (GetGlobalVar(5)==InvalidNumeric)
{
timeInterval=5;
}else
{
if (GetGlobalVar(15)==InvalidNumeric)
{
timeInterval=15;
}else
{
timeInterval=30; // 最大調(diào)用30min線
}
}
// 開(kāi)鎖結(jié)束
// 調(diào)用5min的時(shí)間線,數(shù)據(jù)轉(zhuǎn)換
myOpen=DataConvert(open,"min",timeInterval,"open");
myClose=DataConvert(close,"min",timeInterval,"close");
myHigh=DataConvert(high,"min",timeInterval,"high");
myLow=DataConvert(low,"min",timeInterval,"low");
// 跨周期計(jì)算均值,跨周期判斷穿破,跨周期判斷紅綠放大,見(jiàn)函數(shù)Average_transTimeInterval,
// GreenOrRed_transTimeInterval,以及crossOver_transTimeIntrval,CrossUnder_transTimeInterval
// 先計(jì)算跨周期收盤(pán)價(jià)的均值,為后面的判斷準(zhǔn)備
myCloseAverage=average_transMinData(myClose,100); //選擇平均周期是100次,對(duì)于5min而言,就是5min總共500分鐘的100次收盤(pán)價(jià)格
// 跨周期調(diào)用數(shù)據(jù),并判斷是否開(kāi)倉(cāng)
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);
}
// 跨周期建倉(cāng)完畢
// 跨周期平倉(cāng)條件
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);
}
}
} // 連續(xù)三次平倉(cāng)時(shí)間的滾動(dòng)記錄.
}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);
}
}
} // 連續(xù)三次平倉(cāng)時(shí)間的滾動(dòng)記錄.
}
// 跨周期平倉(cāng)結(jié)束
// 計(jì)算跨周期連續(xù)三次平倉(cāng)的時(shí)間,若連續(xù)平倉(cāng)時(shí)間大于30*周期長(zhǎng)度,則賦予相應(yīng)全局變量值,達(dá)到開(kāi)鎖的作用
// 總而啟動(dòng)更長(zhǎng)周期的數(shù)據(jù)調(diào)用
if (GetGlobalVar(timeInterval+3)!=InvalidNumeric)
{
if (GetGlobalVar(timeInterval+3)-GetGlobalVar(timeInterval+1)<timeInterval*30)
{
SetGlobalVar(timeInterval,1); // 給開(kāi)鎖變量賦值
}
}
}
End - TB技術(shù)人員:
本帖最后由 Ransoros 于 2011-12-30 10:20 編輯
回復(fù) 1# Ransoros
自建函數(shù):
1. GreenOrRed: 判斷是否出現(xiàn)紅柱放大或綠柱放大,紅返回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
這個(gè)就不好意思了,非原創(chuàng),謝謝斑竹的經(jīng)驗(yàn)分享?。。。。?!
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跨周期判斷是否出現(xiàn)上穿,是就返回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 跨周期判斷是否出現(xiàn)下穿,是就返回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 跨周期判斷是否出現(xiàn)紅柱或綠柱放大,紅返回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函數(shù)起到跨時(shí)間取值的作用。
}
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客服:
不要?。?
- 網(wǎng)友回復(fù):
改了一下,就好多了!哈哈。
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次平倉(cāng)的時(shí)間間隔
// 1min線調(diào)用的條件是在前兩次平倉(cāng),或則在連續(xù)三次平倉(cāng)的時(shí)間間隔>0.0030時(shí)
SetGlobalVar(1,999999);
SetGlobalVar(2,999999);
SetGlobalVar(3,999999);
SetGlobalVar(4,999999);
if (GetGlobalVar(4)>0.0030)
{
// 建倉(cāng)條件
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);
}
// 建倉(cāng)完畢
// 平倉(cāng)條件
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);
}
}
} // 連續(xù)三次平倉(cāng)時(shí)間的滾動(dòng)記錄.
}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);
}
}
}
}
// 平倉(cāng)完畢
if (GetGlobalVar(3)!=999999)
{
SetGlobalVar(4,GetGlobalVar(3)-GetGlobalVar(1)); //用全局變量GetGlobalVar(4)來(lái)記錄連續(xù)三次平
// 倉(cāng)時(shí)間的間隔:若GetGlobalVar(4)>0.0030,前部分程序塊不會(huì)運(yùn)行
}
}else
{
// 若前面if的程序不被執(zhí)行,說(shuō)明連續(xù)三次平倉(cāng)的時(shí)間間隔小于0,003;避免市場(chǎng)拉鋸,調(diào)用更長(zhǎng)周期的數(shù)據(jù)
// 更長(zhǎng)周期的數(shù)據(jù)調(diào)用,在下面的代嗎里面類似一個(gè)逐步開(kāi)鎖的過(guò)程,鎖便是全局?jǐn)?shù)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; // 最大調(diào)用30min線
}
}
// 開(kāi)鎖結(jié)束
// 調(diào)用5min的時(shí)間線,數(shù)據(jù)轉(zhuǎn)換
myOpen=DataConvert(open,"min",timeInterval,"open");
myClose=DataConvert(close,"min",timeInterval,"close");
myHigh=DataConvert(high,"min",timeInterval,"high");
myLow=DataConvert(low,"min",timeInterval,"low");
// 跨周期計(jì)算均值,跨周期判斷穿破,跨周期判斷紅綠放大,見(jiàn)函數(shù)Average_transTimeInterval,
// GreenOrRed_transTimeInterval,以及crossOver_transTimeIntrval,CrossUnder_transTimeInterval
// 先計(jì)算跨周期收盤(pán)價(jià)的均值,為后面的判斷準(zhǔn)備
myCloseAverage=average_transMinData(myClose,100); //選擇平均周期是100次,對(duì)于5min而言,就是5min總共500分鐘的100次收盤(pán)價(jià)格
// 跨周期調(diào)用數(shù)據(jù),并判斷是否開(kāi)倉(cāng)
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);
}
// 跨周期建倉(cāng)完畢
// 跨周期平倉(cāng)條件
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);
}
}
} // 連續(xù)三次平倉(cāng)時(shí)間的滾動(dòng)記錄.
}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);
}
}
} // 連續(xù)三次平倉(cāng)時(shí)間的滾動(dòng)記錄.
}
// 跨周期平倉(cāng)結(jié)束
// 計(jì)算跨周期連續(xù)三次平倉(cāng)的時(shí)間,若連續(xù)平倉(cāng)時(shí)間大于30*周期長(zhǎng)度,則賦予相應(yīng)全局變量值,達(dá)到開(kāi)鎖的作用
// 總而啟動(dòng)更長(zhǎng)周期的數(shù)據(jù)調(diào)用
if (GetGlobalVar(timeInterval+3)!=999999)
{
if (GetGlobalVar(timeInterval+3)-GetGlobalVar(timeInterval+1)<timeInterval*30)
{
SetGlobalVar(timeInterval,1); // 給開(kāi)鎖變量賦值
}
}
}
End - 網(wǎng)友回復(fù):
果然沒(méi)人理。
如果以上指標(biāo)公式不適用于您常用的行情軟件
或者您想改編成選股公式,以便快速選出某種形態(tài)個(gè)股的話,
相關(guān)文章
-
沒(méi)有相關(guān)內(nèi)容