2440  

 

在powerlanguage裡面有幾個常用的基本語法,用來給程式下命令 ,80%以上的流程控制都是用這些指令

1. if ...... then......

這是最常用的指令;  如果下雨了...就要撐傘; 如果遇到紅燈...就要停車...不然就是直走

範例   if close cross over average(close,10) then buy next bar at market.......

2. begin......end 

有一個begin 就需要對應一個 end ,是一起搭配使用  包含一至多行的陳述式

範例:

if marketposition<>0 and time>1330 then begin

   sell next bar at market

   buytocover next bar at market

end;

3. switch......case

和 if ... then不同的是 switch...case  針對數值或字串比較,if ... then針對布林值做比較

範例:

switch(bartype)  begin

  case1: plot1(average(c,close10));

  case2: plot1(average(c,close20));

  case3: plot1(average(c,close60));

end;

4. for...to...begin...end;

從什麼時候開始到什麼時候做什麼事情;例如 從早上9:00開始直到下午6:00,每個小時敲一次鐘.....

範例: 

var0 = 0 ;

for Value1 = 0 to Len - 1

begin

var0 = var0 + PriceValue[Value1] ;

end ;

Summation = var0 ;

5.while......begin...end

也是迴圈語法的一種。比較少用到

 

arrow
arrow
    文章標籤
    Powerlanguage 程式交易語法
    全站熱搜

    元大期貨楊宗儒 發表在 痞客邦 留言(0) 人氣()