kcchan717 發表於 20-3-29 22:38

新手問題想請教各位前輩

各位前輩好
我在學寫一個指標,是採用廿組的平均線去作出交易決定,當一組的平均線的短期線上穿長短線,數值+5(廿組總數最高100),但是特寫了出來指標數值不停累積超出100的先範圍了,請問我該如何寫呢?

下面的是編碼,謝謝各位前輩的指導!


input: Displace( 0 );
variables: MACS(0);

value16=AverageFC(Close,1);
value17=AverageFC(Close,2);
value18=AverageFC(Close,3);
value19=AverageFC(Close,4);
value20=AverageFC(Close,5);
value21=AverageFC(Close,6);
value22=AverageFC(Close,7);
value23=AverageFC(Close,8);
value24=AverageFC(Close,9);
value25=AverageFC(Close,10);
value26=AverageFC(Close,11);
value27=AverageFC(Close,12);
value28=AverageFC(Close,13);
value29=AverageFC(Close,14);
value30=AverageFC(Close,15);
value31=AverageFC(Close,16);
value32=AverageFC(Close,17);
value33=AverageFC(Close,18);
value34=AverageFC(Close,19);
value35=AverageFC(Close,20);
value36=AverageFC(Close,21);
value37=AverageFC(Close,22);
value38=AverageFC(Close,23);
value39=AverageFC(Close,24);
value40=AverageFC(Close,25);
value41=AverageFC(Close,26);
value42=AverageFC(Close,27);
value43=AverageFC(Close,28);
value44=AverageFC(Close,29);
value45=AverageFC(Close,30);
value46=AverageFC(Close,31);
value47=AverageFC(Close,32);
value48=AverageFC(Close,33);
value49=AverageFC(Close,34);
value50=AverageFC(Close,35);
value51=AverageFC(Close,36);
value52=AverageFC(Close,37);
value53=AverageFC(Close,38);
value54=AverageFC(Close,39);
value55=AverageFC(Close,40);
value56=AverageFC(Close,41);
value57=AverageFC(Close,42);
value58=AverageFC(Close,43);
value59=AverageFC(Close,44);
value60=AverageFC(Close,45);
value61=AverageFC(Close,46);
value62=AverageFC(Close,47);
value63=AverageFC(Close,48);
value64=AverageFC(Close,49);
value65=AverageFC(Close,50);
value66=AverageFC(Close,51);
value67=AverageFC(Close,52);
value68=AverageFC(Close,53);
value69=AverageFC(Close,54);
value70=AverageFC(Close,55);
value71=AverageFC(Close,56);
value72=AverageFC(Close,57);
value73=AverageFC(Close,58);
value74=AverageFC(Close,59);
value75=AverageFC(Close,60);
value76=AverageFC(Close,61);
value77=AverageFC(Close,62);
value78=AverageFC(Close,63);
value79=AverageFC(Close,64);
value80=AverageFC(Close,65);
value81=AverageFC(Close,66);
value82=AverageFC(Close,67);
value83=AverageFC(Close,68);
value84=AverageFC(Close,69);
value85=AverageFC(Close,70);
value86=AverageFC(Close,71);
value87=AverageFC(Close,72);
value88=AverageFC(Close,73);
value89=AverageFC(Close,74);
value90=AverageFC(Close,75);
value91=AverageFC(Close,76);
value92=AverageFC(Close,77);
value93=AverageFC(Close,78);
value94=AverageFC(Close,79);
value95=AverageFC(Close,80);

if value16>value19 then MACS=MACS+5;
if value17>value23 then MACS=MACS+5;
if value18>value27 then MACS=MACS+5;
if value19>value31 then MACS=MACS+5;
if value20>value35 then MACS=MACS+5;
if value21>value39 then MACS=MACS+5;
if value22>value43 then MACS=MACS+5;
if value23>value47 then MACS=MACS+5;
if value24>value51 then MACS=MACS+5;
if value25>value55 then MACS=MACS+5;
if value26>value59 then MACS=MACS+5;
if value27>value63 then MACS=MACS+5;
if value28>value67 then MACS=MACS+5;
if value29>value71 then MACS=MACS+5;
if value30>value75 then MACS=MACS+5;
if value31>value79 then MACS=MACS+5;
if value32>value83 then MACS=MACS+5;
if value33>value87 then MACS=MACS+5;
if value34>value91 then MACS=MACS+5;
if value35>value95 then MACS=MACS+5;

condition1 = Displace >= 0 or CurrentBar > AbsValue( Displace ) ;
if condition1 then
    begin
    Plot1( MACS, "MACS" ) ;

end;





aloe95 發表於 20-3-30 10:40

本帖最後由 vikio 於 20-3-30 11:08 編輯

視你的條件新增MACS=0,讓它歸零

if XXX then MACS=0;
XXX如:每天的第一根K、月結算後...等


easytrader788 發表於 20-4-4 13:37

請參考這篇 特別的均線評分策略 - 移動平均匯合

https://easytrader788.blogspot.com/2014/05/blog-post.html

jason680 發表於 20-4-10 05:02

有需要基礎(程式)教學...

請私訊或gmail (id + gmail)
頁: [1]
查看完整版本: 新手問題想請教各位前輩