Translate

2013年7月9日 星期二

程式碼 : 使用黃金比例策略製成的訊號

想必因該也有很多人在想策略時 ,也有想到使用費式定律,我想很多人因該也覺得,期貨硬是要將這帶入也太牽強了些吧 . 不過我們還是試試看強帶入會是怎樣的一個狀況 .
我把它分成4個狀態2個買訊2個賣訊,當然要分的更細的話也是可以,在此我先寫成4個.
進場的訊號都還滿準確的,但重點還是出場訊號,在此我只po 進場訊號 ,出場訊號需要各位再想想囉 !  以下是程式碼 ,可以直接copy 使用看看.

Parameter: L停損金額(10000),停損金額(9000),Length(5)
var: StopLossAmount(0), OrderPrice(0)
if date<>date[1] and time= 85000 then
value1 =highest(high,59)[1]
value2=lowest(low,59)[1]
value6 = close[1] 
end if
value3=value1-value2
value4=value3 * 0.618
value5=value3*0.382
if  marketposition=0 and close  cross under value6 -value4 then
sell("sell")  next bar on market
end if

if   marketposition=0 and close  cross over  value6 + value4 then
buy("buy") next bar on market
end if 

if  marketposition=0 and close cross under value6 + value5 then
sell("sell2") next bar on market
end if

if  marketposition=0 and close cross over value6 - value5 then
buy("buy2")  next bar on market
end if 

If MarketPosition = 1 Then
 StopLossAmount = 停損金額 + Commission_B
    OrderPrice = Entryprice(0) - (StopLossAmount / PointValue)
 ExitLong ("多單停損") NEXT Bar at OrderPrice Stop
 dt + =1
End if

If MarketPosition = -1 Then
 StopLossAmount = 停損金額 + Commission_S
 OrderPrice = EntryPrice(0) + (StopLossAmount/ PointValue)
 ExitShort ("空單停損") NEXT Bar at OrderPrice Stop
 dt + =1
End if

If MarketPosition = 1 Then
CNDL_LongBody(Length)
 StopLossAmount = L停損金額 + Commission_B
    OrderPrice = Entryprice(0) - (StopLossAmount / PointValue)
 ExitLong ("長陰多單停損") THIS Bar at OrderPrice Stop
dt + =1
End if

If MarketPosition = -1 Then
CNDL_LongBody(Length)
 StopLossAmount = L停損金額 + Commission_S
 OrderPrice = EntryPrice(0) + (StopLossAmount/ PointValue)
 ExitShort ("長陽空單停損") THIS Bar at OrderPrice Stop
 dt + =1
End if
Posted by Picasa

沒有留言:

張貼留言