Power Language是以每根k棒的開盤、最高、最低、收盤與成交量為思考基礎換言之,程式會去判斷每一根k棒在發生何種狀況下,而去建立買入、賣出訊號
買賣訊號的形成,基本上會有以下三種:
變數宣告區
進場買賣訊號區
出場平倉區
基本買賣訊號的構成
進場訊號 語法中要出現buy sell
一個情況發生下,以一種價格或下單模式進行買賣動作
If close cross over value1 then
buy(“long”) next bar at market
end if
模擬下單模式
市價單 buy(“long”) next bar at market
此根k出現買入訊號,進場價格為下一根k的市價,也就是開盤價。
停損單 buy(“long”) at 30 stop
以價格30為停損價位,換句話說,價格觸到30後 下單,價格可能高於30。
限價單 exitshort(“XS”) at 50 limit
以價格50為出場價位,價格一定會小於等於50
當根收盤價單 buy(“long”) this bar on close
基本出場訊號的組成
出場程式中,exitlong 多單出場 與 exitshort 空單出場一定要出現。
結構與進場訊號相似,但條件是中會出現marketposition
If marketposition=1 and barssinceentry=10 then
exitlong(“XL”) next bar at market
End if
指標語法介紹
指標最重要的函數就是畫線draw,簡單的指標最先還是變數宣告,與買賣訊號寫法相似,下方以真實區間為例說明:
Parameters:len(4);
variables:value1(0);
Value1=averagetruerange(len)
Draw1(value1, "averagetruerange")
長短均線交易策略
Parameters: FastLength(10), slowlength(30)
If MA(close,fastlength) cross above MA(close,slowlength) then
Buy ("買進") next bar at market
End If
If MA(close,fastlength) cross below MA(close,slowLength) then
Sell ("賣出") next bar at market
End If
均線交易策略
Parameters: slowlength(30)
If close cross above MA(close,slowlength) then
Buy ("買進") next bar at market
End If
If close cross below MA(close,slowLength) then
Sell ("賣出") next bar at market
End If
均線出場訊號
Parameters: fastlength(10),slowlength(30)
if close
end if
if close>ma(close,fastlength) and currentcontracts=-1 then
exitshort("賣出平倉") next Bars at market
end if
台指期波動性策略 進場訊號
Parameters: VtyPercentLE(1.2),VtyPercentSE(0.6),VtyPercentLX(2),VtyPercentSX(0.9)
If MarketPosition <> 1 Then
Buy ("買進") Next Bar at Close + (VtyPercentLE * AverageTrueRange(5)) Stop
End If
If MarketPosition <> -1 Then
Sell ("賣出") Next Bar at Close - (VtyPercentSE * AverageTrueRange(5)) Stop
End If
台指期波動性策略 出場訊號
ExitLong ("多出") Next Bar at Close - (VtyPercentLX * AverageTrueRange(5)) Stop
ExitShort ("空補") Next Bar at Close + (VtyPercentSX * AverageTrueRange(5)) Stop
台指期波動性策略主要是由平均真實區間作調整所形成的買賣訊號,每日的真實區間都可能變動,當收盤價觸及到真實區間後進行買進賣出的動作
KD指標的計算
Step1 計算RSV
RSV=(Ct-Ln)/(Hn-Ln)*100
Ct為收盤價 Ln為n日內的最低價
Hn為n日內的最高價
Step2 計算K與D
Kt=RSV*(1/3)+Kt-1*(2/3)
Dt=Kt*(1/3)+Dt-1 *(2/3)
KD指標語法說明
Parameters : HighLowTerm(14), kLength(3), dLength(3), OverSold(20), OverBought(80)
Value1 = FastD( High, Low, Close, HighLowTerm)
DrawBase1( OverBought, "Over Bought", DarkGray )
DrawBase2( OverSold, "Over Sold", DarkGray )
Draw2( Round(MA( Value1, dLength),2), "Slow %D", Blue)
Draw1( Round( Value1,2), "Slow %K", Red)
KD交易策略語法說明
Parameters : HighLowTerm(9), kLength(3), dLength(3), OverSold(20), OverBought(80)
variables:value(0),value2(0);
Value1 = FastD( High, Low, Close, HighLowTerm)
value2=MA( Value1, dLength)
if value1>OverBought and value2>OverBought and value1 cross over value2 then
buy("long") next bar at market
end if
if value1 < OverSold and value2 < OverSold and value1 cross below value2 then
sell("short") next bar at market
end if
RSI交易策略語法說明
parameters:len(9),overbought(80),oversought(20)
if rsi(close,len)>overbought then
sell("賣出") this bar on close
end if
if rsi(close,len)
end if
MACD指標的計算方式
Step1:先計算兩條長短均線,例如12日均與26日均。
Step2: 12日均減去26日均 形成DIF值
Step3IF取9日平均 為MACD值
MACD 交易策略
Parameters: FastMA(10),SlowMA(20),MacdMA(9)
variables:value1(0)
value1=MACD(close,FastMA,SlowMA)
If value1 crosses over EMA(value1,MacdMA) then
buy("買進") next bar at market
End if
If value1 crosses below EMA(value1,MacdMA) then
sell("賣出") next bar at market
End if
MACD 進階策略
DIF與MACD 的差離值,此差離值>30則買進,<-20則賣出。
Parameters: FastMA(10),SlowMA(20),MacdMA(9)
variables:value1(0)
value1=MACD(close,FastMA,SlowMA)
value2= EMA(value1,MacdMA)
value3=value2-value1
If value3>30 then
buy("買進") next bar at market
End if
If value3<-20 then
sell("賣出") next bar at market
End if
週k線策略(利用週線資料)
If close-open>0 then
buy(“買進”) next bar at market
End if
If close-open<0 then
sell(“賣出”) next bar at market
End if
ROC交易策略
當ROC指標連續三日增加則買進,連續3日減少則賣出
variables:ROC(0)
ROC=close/close[9]
if ROC>ROC[1] and ROC[1]>ROC[2] and ROC[2]>ROC[3] then
buy("買進") next bar at market
end if。
if ROC < ROC[1] and ROC[1] < ROC[2] and ROC[2] < ROC[3] then
sell(“賣出") next bar at market
end if。
停損訊號程式碼說明
Parameter: DollarRisk(10000)
Variables: StopLossAmount(0), OrderPrice(0)
If MarketPosition = 1 Then
StopLossAmount = DollarRisk + Commission_B
OrderPrice = Entryprice(0) - (StopLossAmount / PointValue)
ExitLong ("停損L") this Bar at OrderPrice Stop
End if
If MarketPosition = -1 Then
StopLossAmount = DollarRisk + Commission_S
OrderPrice = EntryPrice(0) + (StopLossAmount/ PointValue)
ExitShort ("停損S") this Bar at OrderPrice Stop
End if
If MarketPosition = 1 Then
StopLossAmount = DollarRisk + Commission_B
OrderPrice = Entryprice(0) - (StopLossAmount / PointValue)
ExitLong ("停損L") this Bar at OrderPrice Stop
End if
StopLossAmount 代表總損失的金額
Commission_B 代表手續費
PointValue 每1點的價值 例如台指期1點200元
停利訊號程式碼
Parameter: profit(10000)
Variables: OrderPrice(0)
If MarketPosition = 1 Then
OrderPrice = Entryprice(0) + (profit / PointValue)
ExitLong ("停利L") this Bar OrderPrice limit
End if
If MarketPosition = -1 Then
OrderPrice = EntryPrice(0) - (profit/ PointValue)
ExitShort ("停利S") this Bar OrderPrice limit
End if
If MarketPosition = 1 Then
OrderPrice = Entryprice(0) + (profit / PointValue)
ExitLong ("停利L") this Bar OrderPrice limit
End if
多單停利 profit 利潤設定為10000元,進場後必須賺到10000元以上才停利出場(profit / PointValue)顯示此10000元相當於幾點
以台指期為例,pointvalue=200,所以orderprice=50 ,利用限價單的原因是在於平倉的價格要比預定的還要好。
沒有留言:
張貼留言