先看看圖吧:
可以看到…我是在出場時順手寫了一個進場條件…把不應該出掉的單子補回來的作法…盤中實際訊號轉變的情況目前沒測試過…應該是可行才對…這還得讓需要加減碼策略的人自行試試看了…
程式碼如下:
Value1 = average(close, 5)
Value2 = average(close, 10)
if currentcontracts = 0 and Value1 cross over Value2 then
buy("b1") 1 contracts next bar at market
end if
if currentcontracts = 1 and Value1 cross over Value2 then
buy("b2") 1 contracts next bar at market
end if
if currentcontracts = 2 and close < average(close, 30) and entryname(0) = "b2" then
exitlong next bar at market
buy("b3") 1 contracts next bar at market
end if
當然…如果有人可以提供更好的寫法的話…那就更好囉。
這樣的做法 讓手續費........
回覆刪除很可觀!!^^"
allen: 只是舉個簡單的例子而已囉..因為有朋友問到加減碼的 HTS 寫法..所以就寫了個簡單的程式
回覆刪除^^" D K 大
回覆刪除那是我問的~~~在msn上
也問過日盛的營業員了
他們也沒辦法哩
呵呵
看來只好先放棄了!!
可以試試看(以DK大的範例改寫成5分當沖):
回覆刪除Value1 = average(close, 5)
Value2 = average(close, 10)
value3 = average(close, 20)
if time = 85000 then
value4 = 1
end if
if currentcontracts = 0 and Value1 cross over Value2 and value4 = 1 and time < 130000 then
buy("b1") 1 contracts next bar at market
end if
if currentcontracts = 1 and Value2 cross over Value3 and value4 = 1 and time < 130000 then
buy("b2") 1 contracts next bar at market
end if
if currentcontracts = 1 and close < average(close, 30) and close < close[1] and entryname(0) = "b1" then
exitlong("平1") from entry("b1") next bar at market
end if
if currentcontracts = 2 and close < average(close, 20) and close < close[1] and entryname(0) = "b2" then
exitlong("平2") from entry("b1") next bar at market
end if
if currentcontracts = 1 and close < average(close, 30) and close < close[1] and entryname(0) = "b2" then
exitlong("平3") from entry("b2") next bar at market
end if
if close - entryprice(0) > 300 then
exitlong("停利") next bar at market
end if
if time = 132500 then
exitlong("收盤多平") next bar at market
exitshort("收盤空平") next bar at market
value4 = 0
end if
但是在[設定同一方向連續下單]要選" 同一SIGNAL名,不同SIGNAL名,全部開放"
多口數要平倉時,要以先進先出為原則,每一狀況都必須要個別處理,例如:0->1->0的狀況和0->1->2->1->0的狀況,這樣尾盤平倉才能全部出
可以把這個例子貼到HTS實際測試就知道了,我已經實測過了,若有錯誤之處,請指教
但是在TS上entryname(0)好像不能用,不知道要改成什麼?想請教DK大,不然就無法用TS來回測了
dylon: 感謝提供例子...另外在 TS 上是沒有 entryname 可以用..所以我如果處理到這種情況..通常是在倉位轉變後..去檢查是哪一個絛件成立..再利用一個變數去存..
回覆刪除