我把它分成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
沒有留言:
張貼留言