您現(xiàn)在的位置:程序化交易>> 期貨公式>> (MC)multicharts>> MC知識>>正文內(nèi)容

代碼問題,求教 [MC]

  • MC用戶求助:

    只是想實現(xiàn) 止損后,反手交易,并且手?jǐn)?shù)翻倍。

    所以手?jǐn)?shù)應(yīng)該是1 2 4 8 16 32 這樣倍增。

    但現(xiàn)在總是出現(xiàn)跳躍,不知道是為什么。

    不用一定在哪個品種上測試,小品種上都可以測試,螺紋,大豆,豆粕等等都行。

    例如下圖1 2 4 然后沒有8 直接跳到了16 。

    32后 直接跳到了128

    是和模式(bar內(nèi)?)有關(guān)?還是代碼?

    ?

    全部代碼如下:

    inputs:

    ? ? ? ? ?Zhiyingx( 9999) , ? ? ?

    Zhiying( 9999) ,

    Zhisun( 5 ) ;

    ? ? ? ?

    ?

    variables:

    ? ?nn(4) ,

    ? ? ? ? ?ww(3) , ? ? ??

    ?

    var0( 0 ), var1( 0 ), var2( 0 ),Length( 20 ),Zhiyings( 20 ),TNUMSEQLOSS( 0 ),

    shoushua( 1 ), shoushu(1), yici(0)?

    ;

    ?

    yici=0;

    var0 = BollingerBand( Close, Length, 1 ) ;

    var1 = BollingerBand( Close , Length, -1 ) ;

    var2 = Average(C,Length);

    ?

    ?

    condition3 = TIME>900 and TIME<2300;

    ?

    condition1 = c[1]>o[1] and c[1]>Average(c[1],26) and condition3 ;;

    ?

    condition2 = c[1]<o[1] and c[1]<Average(c[1],26) and condition3 ;;

    ?

    ?

    if TNUMSEQLOSS<ww then begin

    Zhiyings=Zhiying;

    end

    Else begin

    ? ? ? ?Zhiyings=Zhiyingx;

    end;

    ?

    if TNUMSEQLOSS<nn then begin

    shoushua=shoushu;

    end

    Else begin

    ? ? ? ? shoushu=0.5;

    ? ? ? ?end;

    ?

    ?

    ?

    ?

    condition4 = CurrentBar > 1 and H>Zhisun+avgentryprice and marketposition=-1 and condition3 ;

    ?

    condition5 = CurrentBar > 1 and l<avgentryprice-Zhisun and marketposition=1 and condition3 ;

    ?

    ?

    condition6 = CurrentBar > 1 and l<avgentryprice-Zhiyings and marketposition=-1 and condition3 ;

    ?

    condition7 = CurrentBar > 1 and h>avgentryprice+Zhiyings and marketposition=1 and condition3 ;

    ?

    ?

    if (condition1 or yici[1]=1) ?and marketposition=0 then begin

    ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??

    Buy ( "kai1" ) 1 Contract next bar at Open stop ;

    ?

    end;

    ?

    if (condition2 or yici[1]=-1) and marketposition=0 ?then begin

    ?

    ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??

    Sell Short ( "kai2" ) 1 Contract ?next bar at Open stop ;

    ?

    end;

    ?

    if condition4 ?and condition5=False then begin

    ? ? ? ? ? TNUMSEQLOSS=TNUMSEQLOSS+1;

    ? ? ? ? ? print(date," ",time," buy ?TNUMSEQLOSS: ",TNUMSEQLOSS);

    ? ? ? ? ? shoushu=Power(2,TNUMSEQLOSS);?

    ? ? ? ? ? ?print(date," ",time," buy ?shoushu: ",shoushu);

    ?

    buy ?( "kui1" ) ?shoushu Contracts ? ? ? next bar at Zhisun+avgentryprice ?stop ;

    end;

    ?

    ?

    ?

    if condition5 and condition4=False then begin

    ?

    ? ? ? ? ? ?TNUMSEQLOSS=TNUMSEQLOSS+1;

    ? ? ? ? ? ?print(date," ",time," sellshort TNUMSEQLOSS: ",TNUMSEQLOSS);

    ? ? ? ? ? ?shoushu=Power(2,TNUMSEQLOSS);?

    ? ? ? ? ? ?print(date," ",time," sellshort shoushu: ",shoushu);

    sellshort( "kui2" ) ?shoushu Contracts ? ?next bar at avgentryprice-Zhisun ?stop ;

    ?

    end;

    ?

    ?

    if condition6 then begin

    ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??

    buytocover ?( "ying1" ) next bar at avgentryprice-Zhiyings ?stop ;

    shoushu=1;

    TNUMSEQLOSS=0;

    yici=-1;

    end;

    ?

    if condition7 then begin

    ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??

    sell( "ying2" ) next bar at avgentryprice+Zhiyings stop ;

    shoushu=1;

    ? ? ? ?TNUMSEQLOSS=0;

    ? ? ? ?yici=1;

    end;

    ?

    ?

  • MC回復(fù)討論一:

    if condition4 ?and condition5=False then begin

    ? ? ? ? ? TNUMSEQLOSS=TNUMSEQLOSS+1;

    ? ? ? ? ? print(date," ",time," buy ?TNUMSEQLOSS: ",TNUMSEQLOSS);

    ? ? ? ? ? shoushu=Power(2,TNUMSEQLOSS);?

    ? ? ? ? ? ?print(date," ",time," buy ?shoushu: ",shoushu);

    buy ?( "kui1" ) ?shoushu Contracts ? ? ? next bar at Zhisun+avgentryprice ?stop ;

    end;

    if condition5 and condition4=False then begin

    ? ? ? ? ? ?TNUMSEQLOSS=TNUMSEQLOSS+1;

    ? ? ? ? ? ?print(date," ",time," sellshort TNUMSEQLOSS: ",TNUMSEQLOSS);

    ? ? ? ? ? ?shoushu=Power(2,TNUMSEQLOSS);?

    ? ? ? ? ? ?print(date," ",time," sellshort shoushu: ",shoushu);

    sellshort( "kui2" ) ?shoushu Contracts ? ?next bar at avgentryprice-Zhisun ?stop ;

    end;

    以上代碼是您累加變量TNUMSEQLOSS的地方,也是問題的所在,之所以出現(xiàn)”跳躍“是因為重復(fù)累加,也就是條件連續(xù)滿足導(dǎo)致連續(xù)累加;因為您使用的是條件單,而條件單不一定委托出去就會成交,但是您在條件成立時肯定會累加變量TNUMSEQLOSS,所以導(dǎo)致兩者的不一致;解決方法是,確定條件單成交之后再累加變量TNUMSEQLOSS

    ?

    ?

  • MC回復(fù)討論二:

    判斷是否成交的方法有很多:

    第一、在沒有加倉的情況下,通過當(dāng)根bar的marketposition與前一根bar的marketposition的信息對比進行判斷,但是由于marketposition沒有回溯的功能,但您需要先將marketposition的值賦值給新建的變量mp,然后通過判斷mp[1]<>mp

    第二、在有加倉的情況下,您還需要考慮關(guān)鍵字currentcontracts等持倉部位信息的變化,以此來判斷。

    第三、策略屬性中有重新計算的設(shè)置,可以勾選“委托單成交”,這個用來判斷委托單成交有點復(fù)雜,不建議使用。

    ?

  • MC回復(fù)討論三:

    inputs:

    ? ? ? ? ?Zhiyingx( 9999) , ? ? ?

    Zhiying( 9999) ,

    Zhisun( 5 ) ;

    ? ? ? ?

    ?

    variables:

    ? ?nn(4) ,

    ? ? ? ? ?ww(3) , ? ? ??

    ?

    var0( 0 ), var1( 0 ), var2( 0 ),Length( 20 ),Zhiyings( 20 ),TNUMSEQLOSS( 0 ),

    shoushua( 1 ), shoushu(1), yici(0), mp(0);;

    ?

    yici=0;

    var0 = BollingerBand( Close, Length, 1 ) ;

    var1 = BollingerBand( Close , Length, -1 ) ;

    var2 = Average(C,Length);

    ?

    ?

    condition3 = TIME>900 and TIME<2300;

    ?

    condition1 = c[1]>o[1] and c[1]>Average(c[1],26) and condition3 ;;

    ?

    condition2 = c[1]<o[1] and c[1]<Average(c[1],26) and condition3 ;;

    ?

    ?

    if TNUMSEQLOSS<ww then begin

    Zhiyings=Zhiying;

    end

    Else begin

    ? ? ? ?Zhiyings=Zhiyingx;

    end;

    ?

    if TNUMSEQLOSS<nn then begin

    shoushua=shoushu;

    end

    Else begin

    ? ? ? ? shoushu=0.5;

    ? ? ? ?end;

    ?

    ?

    mp=marketposition;

    ?

    condition4 = CurrentBar > 1 and H>Zhisun+avgentryprice and marketposition=-1 and condition3 ?and ?mp[1]<>mp;

    ?

    condition5 = CurrentBar > 1 and l<avgentryprice-Zhisun and marketposition=1 and condition3 and ?mp[1]<>mp;

    ?

    ?

    condition6 = CurrentBar > 1 and l<avgentryprice-Zhiyings and marketposition=-1 and condition3 ;

    ?

    condition7 = CurrentBar > 1 and h>avgentryprice+Zhiyings and marketposition=1 and condition3 ;

    ?

    ?

    if (condition1 or yici[1]=1) ?and marketposition=0 then begin

    ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??

    Buy ( "kai1" ) 1 Contract next bar at Open stop ;

    ?

    end;

    ?

    if (condition2 or yici[1]=-1) and marketposition=0 ?then begin

    ?

    ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??

    Sell Short ( "kai2" ) 1 Contract ?next bar at Open stop ;

    ?

    end;

    ?

    if condition4 ?and condition5=False then begin

    ? ? ? ? ? TNUMSEQLOSS=TNUMSEQLOSS+1;

    ? ? ? ? ? print(date," ",time," buy ?TNUMSEQLOSS: ",TNUMSEQLOSS);

    ? ? ? ? ? shoushu=Power(2,TNUMSEQLOSS);?

    ? ? ? ? ? ?print(date," ",time," buy ?shoushu: ",shoushu);

    ?

    buy ?( "kui1" ) ?shoushu Contracts ? ? ? next bar at Zhisun+avgentryprice ?stop ;

    ?

    ?

    end;

    ?

    ?

    ?

    if condition5 and condition4=False then begin

    ?

    ? ? ? ? ? ?TNUMSEQLOSS=TNUMSEQLOSS+1;

    ? ? ? ? ? ?print(date," ",time," sellshort TNUMSEQLOSS: ",TNUMSEQLOSS);

    ? ? ? ? ? ?shoushu=Power(2,TNUMSEQLOSS);?

    ? ? ? ? ? ?print(date," ",time," sellshort shoushu: ",shoushu);

    sellshort( "kui2" ) ?shoushu Contracts ? ?next bar at avgentryprice-Zhisun ?stop ;

    ?

    end;

    ?

    ?

    if condition6 then begin

    ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??

    buytocover ?( "ying1" ) next bar at avgentryprice-Zhiyings ?stop ;

    shoushu=1;

    TNUMSEQLOSS=0;

    yici=-1;

    end;

    ?

    if condition7 then begin

    ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??

    sell( "ying2" ) next bar at avgentryprice+Zhiyings stop ;

    shoushu=1;

    ? ? ? ?TNUMSEQLOSS=0;

    ? ? ? ?yici=1;

    end;

    ?

    ?

    ?

    我按照您說的改了,這樣基本交易1,2次就不交易了,這是怎么回事?

    ?

  • MC回復(fù)討論四:

    inputs:

    ? ? ? ? ?Zhiyingx( 9999) , ? ? ?

    Zhiying( 9999) ,

    Zhisun( 5 ) ;

    ? ? ? ?

    ?

    variables:

    ? ?nn(4) ,

    ? ? ? ? ?ww(3) , ? ? ??

    ?

    var0( 0 ), var1( 0 ), var2( 0 ),Length( 20 ),Zhiyings( 20 ),TNUMSEQLOSS( 0 ),

    shoushua( 1 ), shoushu(1), yici(0), mp(0);;

    ?

    yici=0;

    var0 = BollingerBand( Close, Length, 1 ) ;

    var1 = BollingerBand( Close , Length, -1 ) ;

    var2 = Average(C,Length);

    ?

    ?

    condition3 = TIME>900 and TIME<2300;

    ?

    condition1 = c[1]>o[1] and c[1]>Average(c[1],26) and condition3 ;;

    ?

    condition2 = c[1]<o[1] and c[1]<Average(c[1],26) and condition3 ;;

    ?

    ?

    if TNUMSEQLOSS<ww then begin

    Zhiyings=Zhiying;

    end

    Else begin

    ? ? ? ?Zhiyings=Zhiyingx;

    end;

    ?

    if TNUMSEQLOSS<nn then begin

    shoushua=shoushu;

    end

    Else begin

    ? ? ? ? shoushu=0.5;

    ? ? ? ?end;

    ?

    ?

    mp=marketposition;

    ?

    condition4 = CurrentBar > 1 and H>Zhisun+avgentryprice and marketposition=-1 and condition3 ?and ?mp[1]<>mp;

    ?

    condition5 = CurrentBar > 1 and l<avgentryprice-Zhisun and marketposition=1 and condition3 and ?mp[1]<>mp;

    ?

    ?

    condition6 = CurrentBar > 1 and l<avgentryprice-Zhiyings and marketposition=-1 and condition3 ;

    ?

    condition7 = CurrentBar > 1 and h>avgentryprice+Zhiyings and marketposition=1 and condition3 ;

    ?

    ?

    if (condition1 or yici[1]=1) ?and marketposition=0 then begin

    ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??

    Buy ( "kai1" ) 1 Contract next bar at Open stop ;

    ?

    end;

    ?

    if (condition2 or yici[1]=-1) and marketposition=0 ?then begin

    ?

    ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??

    Sell Short ( "kai2" ) 1 Contract ?next bar at Open stop ;

    ?

    end;

    ?

    if condition4 ?and condition5=False then begin

    ? ? ? ? ? TNUMSEQLOSS=TNUMSEQLOSS+1;

    ? ? ? ? ? print(date," ",time," buy ?TNUMSEQLOSS: ",TNUMSEQLOSS);

    ? ? ? ? ? shoushu=Power(2,TNUMSEQLOSS);?

    ? ? ? ? ? ?print(date," ",time," buy ?shoushu: ",shoushu);

    ?

    buy ?( "kui1" ) ?shoushu Contracts ? ? ? next bar at Zhisun+avgentryprice ?stop ;

    ?

    ?

    end;

    ?

    ?

    ?

    if condition5 and condition4=False then begin

    ?

    ? ? ? ? ? ?TNUMSEQLOSS=TNUMSEQLOSS+1;

    ? ? ? ? ? ?print(date," ",time," sellshort TNUMSEQLOSS: ",TNUMSEQLOSS);

    ? ? ? ? ? ?shoushu=Power(2,TNUMSEQLOSS);?

    ? ? ? ? ? ?print(date," ",time," sellshort shoushu: ",shoushu);

    sellshort( "kui2" ) ?shoushu Contracts ? ?next bar at avgentryprice-Zhisun ?stop ;

    ?

    end;

    ?

    ?

    if condition6 then begin

    ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??

    buytocover ?( "ying1" ) next bar at avgentryprice-Zhiyings ?stop ;

    shoushu=1;

    TNUMSEQLOSS=0;

    yici=-1;

    end;

    ?

    if condition7 then begin

    ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ??

    sell( "ying2" ) next bar at avgentryprice+Zhiyings stop ;

    shoushu=1;

    ? ? ? ?TNUMSEQLOSS=0;

    ? ? ? ?yici=1;

    end;

    ?

    ?

    ?

    我按照您說的改了,這樣基本交易1,2次就不交易了,這是怎么回事?

 

有思路,想編寫各種指標(biāo)公式,程序化交易模型,選股公式,預(yù)警公式的朋友

可聯(lián)系技術(shù)人員 QQ: 511411198  點擊這里給我發(fā)消息進行 有償 編寫!不貴!點擊查看價格!


【字體: 】【打印文章】【查看評論

相關(guān)文章

    沒有相關(guān)內(nèi)容
主站蜘蛛池模板: 99久久国产综合精品麻豆| 人妻丰满熟AV无码区HD| 4480yy私人影院论| 好硬好湿好大再深一点动态图 | 天天视频一区二区三区| 久久精品国产亚洲夜色AV网站| 激情六月在线视频观看| 四虎成年永久免费网站| 青草国产精品久久久久久| 国产欧美va欧美va香蕉在线观看| 69sex久久精品国产麻豆| 天天躁日日躁狠狠躁中文字幕 | www.jizzonline.com| 成人毛片在线播放| 久久er99热精品一区二区| 欧美黑人xxxx性高清版| 伊人影视在线观看日韩区| 精品久久久久久亚洲精品| 和几个女同事的激情性事| 色综合久久中文字幕| 国产女人18一级毛片视频| 四虎国产精品高清在线观看| 在线中文字幕有码中文| linmm视频在线观看| 少妇无码一区二区二三区 | www一区二区| 国产精品午夜无码AV天美传媒| 99精品国产综合久久久久五月天| 成人免费淫片免费观看| 中文字幕永久免费视频| 日本b站一卡二不卡| 久久综合九色综合欧美就去吻| 欧美成人高清WW| 亚洲欧美丝袜制服在线| 男人好大好硬好爽免费视频| 免费无码成人av在线播放不卡| 精品剧情v国产在免费线观看| 国产一区二区日韩欧美在线| 香港三级电影在线观看| 国产私拍福利精品视频| 你懂的视频网站|