2013年1月5日 星期六

★SHRK-32程式系統(程式碼)

     今天在國外網站看到下面這串程式碼,我覺得語法背後的觀念很有趣,在這裡分享給大家,有興趣的可以練習一下。

先匯入函數
Type : Function (TrueFalse), Name : sym_shark
input: symmetry(numericsimple);
vars: apex(0),
wb(0);

apex = (high + low) / 2;
wb = high[2] - low[2];

if high < high[1] and low > low[1] and
high[1] < high[2] and low[1] > low[2] and
apex <= high[2] - (wb * symmetry) and
apex >= low[2] + (wb * symmetry) then
sym_shark = true
else sym_shark = false;

匯入上面函數後再來測試下面的策略:

Type : Signal, Name : SHRK-32 System
input: symmetry(.28);
vars: cont(0),
revb(0),
revs(0);

if cont <> 0 and marketposition = 0 then begin
if close < high[3 + cont] and close > low[3 + cont] then cont = cont + 1;
if close > high[3 + cont] then begin
buy close;
revb = cont + 3;
cont = 0;
end;
if close < low[3 + cont] then begin
sell close;
revs = cont + 3;
cont = 0;
end;
end;
if revb <> 0 then begin
if close > low[revb] then revb = revb + 1
else if close < low[revb] then begin
sell close;
revb = 0;
end;
end;
if revs <> 0 then begin
if close < high[revs] then revs = revs + 1
else if close > high[revs] then begin
buy close;
revs = 0;
end;
end;
if sym_shark(symmetry)[1] = true then begin
if close > high[3] then buy close;
if close < low[3] then sell close;
cont = cont + 1;
end;
if sym_shark(symmetry) = true and marketposition <> 0 then begin
exitlong close;
exitshort close;
end;
if barssinceentry = 78 then begin
if marketposition = 1 then begin
exitlong close;
buy open;
end;
if marketposition = -1 then begin
exitshort close;
sell open;
end;
end;
if revb > 100 then revb = 0;
if revs > 100 then revs = 0;

0 留言:

張貼留言

如果有私人問題想請教,請透過網站右方『與站長聯絡』之表單,謝謝!

----------------------------------------------------------------------------------------------------
網站聲明(Disclaimer)
本教學網站內所提供之程式碼(包括函數、指標、訊號)屬開放程式碼,用意在於讓使用者學習程式語法之撰寫,使用者可以任意修改語法內容並調整參數。本網站所有之內容(包括文章、影片、歷史紀錄、程式碼、教材)限用於個人學習使用,請勿轉寄、濫用,嚴禁私自串接帳戶交易。
-------------------------------------------------------------------------------------------------