晒个程序,扔砖的扔砖啊,不要对我客气 - 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 - 网友回复:
果然没人理。
如果以上指标公式不适用于您常用的行情软件
或者您想改编成选股公式,以便快速选出某种形态个股的话,
相关文章
-
没有相关内容