inputs:NoDays(2), N(2),MULT1(2), MULT2(2);
vars:valuea(0),valueb(0),valuec(0), VAL1(0), VAL2(0);
valuea=highest(high,NoDays);
valueb=lowest(low,NoDays);
VAL1= Average(VALUEA,NODAYS);
VAL2= Average(VALUEB,NODAYS);
IF VALUEA CROSSES ABOVE VAL1 AND VALUEB > VAL2 THEN BUY this bar ON CLOSE;
IF VALUEB CROSSES ABOVE VAL2 AND VALUEA > VAL1 THEN BUY this bar ON CLOSE;
IF VALUEA CROSSES BELOW VAL1 AND VALUEB < VAL2 THEN SELLshort this bar ON CLOSE;
IF VALUEB CROSSES BELOW VAL2 AND VALUEA < VAL1 THEN SELLshort this bar ON CLOSE;
VALUE1 = ((HIGHEST (HIGH, N)) - ((LOWEST (LOW, N))));
VALUE2= VALUE1 * MULT1;
VALUE3= VALUE1 * MULT2;
{VALUE2=TARGET, VALUE3 = STOPLOSS}
IF MARKETPOSITION = 1 THEN BEGIN
sell TOMORROW AT ENTRYPRICE + VALUE2 LIMIT;
sell TOMORROW AT ENTRYPRICE - VALUE3 STOP;
END ;
IF MARKETPOSITION = -1 THEN BEGIN
buytocover TOMORROW AT ENTRYPRICE + VALUE3 STOP;
buytocover TOMORROW AT ENTRYPRICE - VALUE2 LIMIT;
END ;
測試台指期的結果:
後記:
要學好程式交易最快的方式,就是拿範例練習,強迫自己練習寫,看過策略夠多了,未來在寫策略的時候,自然會有很多創意(例如把A策略的通道,導入B策略的突破邏輯,而創造出來的C策略意外發現可以打遍天下無敵手)。程式交易的創作就像當年大家都在賣奶茶,結果突然出現一個人覺得奶茶很單調,在裡面加入了粉圓,結果就意外創造出現在風靡歐亞的珍珠奶茶了。粉圓及奶茶都是既有產品,簡單作個組合而已,但是如果你沒有吃過粉圓及奶茶,你就不可能創造出珍珠奶茶這個產品。
1 留言:
最近也發現國外知名策略邏輯,真的有很多值得深入學習的! 如R-Breaker, Dual Thrust...
張貼留言
如果有私人問題想請教,請透過網站右方『與站長聯絡』之表單,謝謝!