期货期权交流能否把下面的tb源码转换成mc的源码 [MC]
-
咨询内容:
Params Numeric bollinglengths(50); Numeric trendliqlength(50); Numeric numstddevs(2); Numeric swingprcnt1(0.5); Numeric swingprcnt2(0.75); Numeric atrlength(10); Numeric swingtrendswitch(50); Vars BoolSeries swing(False); NumericSeries cmival; NumericSeries buyeasierday(0); NumericSeries selleasierday(0); NumericSeries trendlokbuy; NumericSeries trendloksell; NumericSeries trendbuypt; NumericSeries trendsellpt; NumericSeries keyofday; NumericSeries ma1; NumericSeries midd; Numeric swingprotstop; Numeric atr; Numeric swingbuypt; Numeric swingsellpt; Begin Commentary("BarInterval= "+Text(BarInterval)); cmival=Abs(Close[1]-Close[31])/(Highest(High[1],30)-Lowest(Low[1],30)); trendloksell=Average(Low[1],3*240/BarInterval); trendlokbuy=Average(High[1],3*240/BarInterval); keyofday=(HighD(0)+LowD(0)+CloseD(0))/3; If(Date<>Date[1]){ If(CloseD(1)>keyofday[1]) { selleasierday=1;//空头日 }Else{ buyeasierday=1;//多头日 } } Atr=XAverage(TrueRange,atrlength*240/BarInterval); If(buyeasierday==1){ swingbuypt=OpenD(0)+swingprcnt1*atr; swingsellpt=OpenD(0)-swingprcnt2*atr; } If(selleasierday==1){ swingbuypt=OpenD(0)+swingprcnt2*atr; swingsellpt=OpenD(0)-swingprcnt1*atr; } swingbuypt=Max(swingbuypt,trendlokbuy); swingsellpt=Min(swingsellpt,trendloksell); PlotNumeric("Buy",swingbuypt); PlotNumeric("Sell",swingsellpt); ma1=Average(Close[1],trendliqlength);//趋势均线 midd=Average(Close[1],bollinglengths);//布林中线 trendbuypt=midd+numstddevs*StandardDev(Close[1],bollinglengths); trendsellpt=midd-numstddevs*StandardDev(Close[1],bollinglengths); If(cmival<swingtrendswitch/100) { If(MarketPosition==0&&High[1]>=swingbuypt) //开多仓 { Buy(1,Max(Open,swingbuypt)); swing=True; } If(MarketPosition==0&&Low[1]<=swingsellpt) //开空仓 { SellShort(1,Min(Open,swingsellpt)); swing=True; } If(MarketPosition>0&&Low[1]<=swingsellpt) //多头反手 { SellShort(1, Min(Open,swingsellpt)); swing=True; } If(MarketPosition<0&&High[1]>=swingbuypt) //空头反手 { Buy(1, Max(Open,swingbuypt)); swing=True; } }Else{ swingprotstop=atr*3; If(MarketPosition==0&&High[1]>=trendbuypt) //开多仓 { Buy(1,Max(Open,trendbuypt)); swing=False; } If(MarketPosition==0&&Low[1]<=trendsellpt) //开空仓 { SellShort(1,Min(Open,trendsellpt)); swing=False; } If(MarketPosition>0&&swing) //多头止损 { If(Low[1]<=EntryPrice-swingprotstop) { Sell(1,Min(Open, EntryPrice-swingprotstop)); }Else If(Low[1]<=ma1) { Sell(1,Min(Open,ma1)); } } If(MarketPosition<0&&swing) //空头止损 { If(High[1]>=EntryPrice+swingprotstop) { BuyToCover(1,Max(Open, EntryPrice+swingprotstop)); }Else If(High[1]>=ma1) { BuyToCover (1,Max(Open,ma1)); } } } End
-
MC技术部:
inputs: bollinglengths(50), trendliqlength(50), numstddevs(2), swingprcnt1(0.5), swingprcnt2(0.75), atrlength(10), swingtrendswitch(50);
Vars: swing(False), cmival(0), buyeasierday(0), selleasierday(0), trendlokbuy(0), trendloksell(0), trendbuypt(0), trendsellpt(0), keyofday(0),
ma1(0), midd(0), swingprotstop(0), atr(0), swingbuypt(0), swingsellpt(0);
Commentary("BarInterval= "+Text(BarInterval));
cmival=Absvalue(Close[1]-Close[31])/(Highest(High[1],30)-Lowest(Low[1],30));
trendloksell=Average(Low[1],3*240/BarInterval);
trendlokbuy=Average(High[1],3*240/BarInterval);
keyofday=(HighD(0)+LowD(0)+CloseD(0))/3;
if date<>date[1] then
if closed(1)>keyofday[1] then
selleasierday=1
else buyeasierday=1;
Atr=XAverage(TrueRange,atrlength*240/BarInterval);
If buyeasierday=1 then begin
swingbuypt=OpenD(0)+swingprcnt1*atr;
swingsellpt=OpenD(0)-swingprcnt2*atr;
end;
If selleasierday=1 then begin
swingbuypt=OpenD(0)+swingprcnt2*atr;
swingsellpt=OpenD(0)-swingprcnt1*atr;
end;
swingbuypt=Maxlist(swingbuypt,trendlokbuy);
swingsellpt=Minlist(swingsellpt,trendloksell);
ma1=Average(Close[1],trendliqlength);
midd=Average(Close[1],bollinglengths);
trendbuypt=midd+numstddevs*StandardDev(Close[1],bollinglengths,1);
trendsellpt=midd-numstddevs*StandardDev(Close[1],bollinglengths,1);
If cmival<(swingtrendswitch/100) then begin
If MarketPosition=0 and High[1]>=swingbuypt then begin
Buy 1 shares next bar at Maxlist(Open,swingbuypt) limit;
swing=True;
end;
If MarketPosition=0 and Low[1]<=swingsellpt then begin
SellShort 1 shares next bar at Minlist(Open,swingsellpt) limit;
swing=True;
end;
If MarketPosition>0 and Low[1]<=swingsellpt then begin
SellShort 1 shares next bar at Minlist(Open,swingsellpt) limit;
swing=True;
end;
If MarketPosition<0 and High[1]>=swingbuypt then begin
Buy 1 shares next bar at Maxlist(Open,swingbuypt) limit;
swing=True;
end
Else begin
swingprotstop=atr*3;
If MarketPosition=0 and High[1]>=trendbuypt then begin
Buy 1 shares next bar at Maxlist(Open,trendbuypt) limit;
swing=False;
end;
If MarketPosition=0 and Low[1]<=trendsellpt then begin
SellShort 1 shares next bar at Minlist(Open,trendsellpt) limit;
swing=False;
end;
If MarketPosition>0 and swing then
If Low[1]<=EntryPrice-swingprotstop then
Sell 1 shares next bar at Minlist(Open, EntryPrice-swingprotstop) limit
Else If Low[1]<=ma1 then
Sell 1 shares next bar at Minlist(Open,ma1) limit;
If MarketPosition<0 and swing then
If High[1]>=EntryPrice+swingprotstop then
BuyToCover 1 shares next bar at Maxlist(Open, EntryPrice+swingprotstop) limit
Else If High[1]>=ma1 then
BuyToCover 1 shares next bar at Maxlist(Open,ma1) limit;
end;
end;
以上部分是翻译过来的MC代码,但是有几点需要告诉您:
一、opend、highd、lowd和closed在TB和MC中都有这些函数,功能也是一样的,但是TB的这四个函数取的是日K线上的四个价格,而MC的这四个函数取的是时间段00:00:00到23:59:59时间范围内的开高低收四个价格。
二、entryprice同样在MC和TB中都有,功能也是一样的,但是TB中只是表示当前部位的第一笔进场价格,不带参数;而MC中这个后面不带参数和带有参数0意思是一样的,都表示当前未平仓部位第一笔进场价格,后面带1表示前一个平仓部位第一笔进场的价格,以此类推,后面还可以带其它正数表示相应的意思。
三、函数standarddev需要有三个参数,已经帮您更改了。
四、如果您需要更准确的用MC执行您的交易策略,您需要贴上您的策略逻辑。
有思路,想编写各种指标公式,程序化交易模型,选股公式,预警公式的朋友
可联系技术人员 QQ: 511411198 进行 有偿 编写!(不贵!点击查看价格!)
相关文章
-
没有相关内容