Translate

顯示具有 HTS 語法 標籤的文章。 顯示所有文章
顯示具有 HTS 語法 標籤的文章。 顯示所有文章

2013年9月9日 星期一

移動式停損停利的方法

   

我們在在製作完策略的時候都習慣性的加入停損的語法. 有固定性的停損方式,以及移動型的停損方式,固定式停損方式,並不是那麼的聰明,但是卻是非常絕對的!

移動式停損停利的好處在於這個策略是很聰明的,但相對的它的變動性也較大.虧損有可能也相對較大.

在此稍微介紹一下我這策略的想法

2013年8月22日 星期四

A/D Line (騰落指標)

騰落指標 : 

此指標是累計漲和跌家數之差值

ADL =累計股票上漲家數總和 - 累計股票下跌加數總和

使用 :

大盤下跌 ADL 卻由下降轉為上升,此種為背離現象, 為買進訊號 .

大盤上漲 ADL 卻由上升轉為下降,此種為背離現象, 為賣出訊號.



Posted by Picasa

基本指標 %B (偏離指標)

多空正向趨勢指標

使用:
100.30 以上則正向乖離開始偏大
99.70 以下則逆向乖離開始偏大

此指標用來當濾網,準確度還蠻高的
但不要用來當進出場使用



公式 :
(價格-移動平均線+下降係數 *方根值)  /  ((上漲係數-下跌係數) *方根值)*100-50








直接取用 value3 得值即可
Parameter: Price(Close), Length(20), UpMultiplier(2.0), DnMultiplier(-2.0)
Value1 = MA(Price, Length) + UpMultiplier * StdDev(Price, Length)
Value2 = MA(Price, Length) + DnMultiplier * StdDev(Price, Length)
 value3=(Price - Value2) / (Value1 - Value2) * 100 - 50
Posted by Picasa

2013年8月6日 星期二

HTS 函數II

CNDL_Engulfing
本根是否吞噬上根
條件一 = 此根實體高大於上根實體高 且 此根實體低小於或等於上根實體低
成立傳回true,不成立傳回false

CNDL_TrendUp
傳回是否為上漲走勢,
絛件一 = 前第二根收盤小於前一根收盤 且 前一根收盤小於本根收盤
若 條件一成立 回傳 true
不成立 回傳 false


 CNDL_Harami
此根最高價和最低價,完全包含在前一根K線的實體內,一般稱母子線
條件一 = 此根實體高小於上根實體高 且 此根實體低大於上根實體低

成立傳回 TRUE 否則傳回 FALSE

HTS 函數



CNDL_Range

傳回一個k線最高點 - 最低點的差值

CNDL_Marubozu
傳回是否為無上下影線的實體,
是則傳回 True;否就傳回False

CNDL_GapUp
跳空上漲
傳回是否跳空上漲

若為真傳回True,否傳回False


CNDL_GapDown
跳空下跌
傳回是否跳空下跌
判斷式:本根開盤小於 前一根收盤
若為真傳回True,否傳回False

2013年7月29日 星期一

三關價語法

上:今低+(今高-今低)乘以 1.382
中:今高+今低)/2
下: 今高-(今高-今低)乘以 1.382

突破 上關則買
跌破 下關則空

以下是HTS語法











Up = low[1] + (high[1]-low[1])*1.382
  Mid = (high[1] - low[1])/2
  Down = high[1] - (high[1]-low[1])*1.382

If cndl_trendup and open > Up then
buy("3buy")next bar on market
end if

If CNDL_TrendDown and open < Down then
sell("3sell")next bar on market
end if

我覺得這個方式並不是很好 ,可以將high 改為higest 試試看 ,因鈣會更有參考價值.
Posted by Picasa

2013年7月19日 星期五

針對1分線所作的程式績效


上圖為今日我針對1分線所作的程式績效,證明了在某種狀態下,形態學還是有非常大的參考價值

上圖的策略的概念是用連續三線攻擊的策略,當來到當日最低點或最高點時,出現了連續三根的
攻擊,意思是說低檔時連續三根紅k則買進,高檔時連續三根黑k則放空,再加上使用乖離作為濾網

連續三根紅k程式碼

If CNDL_TrendDown[2]                  and
 CNDL_WhiteLine[2]                 and
 CNDL_WhiteLine[1]                 and
 CNDL_WhiteLine                    and
 Open[1] >= Min(Open[2], Close[2]) and
 Open[1] <= Max(Open[2], Close[2]) and
 Open >= Min(Open[1], Close[1])    and
 Open <= Max(Open[1], Close[1])    and
 Close[1] >= Close[2]              and
 Close >= Close[1] Then
 End If

連續三根黑k程式碼

Parameter: Length(10)
If CNDL_TrendDown[3]      and
 CNDL_BlackLine[3]     and
 CNDL_BlackLine[2]     and
 CNDL_BlackLine[1]     and
 Open[1] < Open[2]     and
 Open[2] < Open[3]     and
 Close[1] < Close[2]   and
 Close[2] < Close[3]   and
 Low[1] < Low[2]       and
 Low[2] < Low[3]       and
 Open[2] > Close[3]    and
 Open[1] > Close[2]    and
 CNDL_LongBody(Length) and
 CNDL_WhiteLine        and
 Open < Low[1]         and
 Close > High[3] Then
End If


 
 

2013年7月18日 星期四

當程式交易遇到結算日時

 由於結算換月後,如果次月份的指數並無跟上的時候,就會產生較大的逆價差,
並且也會造成所有指標的鈍化,也容易造成程式的不準確,所以也必須有其它的方式針對這一事件來作處理. 可以選擇不進場,或是使用GAP來追加,這就要視個人需求了.
另一個情況是當沖程式,常會使用到時間出場,然而結算當日只到13:30就結束,所以也須加上此判別式.


以下是計算結算日的程式碼


 IF DATE[1] <> DATE  THEN
    if DayOfMonth( Date ) >14 and DayOfMonth( Date ) <22 and DayOfWeek( Date ) =3 then
      TxtView =TXT_New( Date, Time, Low - 5 Points, "↑"+"|n"+"結算日" )
      TXT_SetStyle( TxtView, 2, 1 ) 
      TXT_SetColor( TxtView, BLUE  )
  end if
end if

 

2013年7月17日 星期三

盤整當沖程式(程式碼)

期貨市場裡幾乎有7成以上的盤都是盤整形式, 或成箱型模式或是收斂模式,所以幾乎盤整時都趨向收手不進場,就算進場後也容易被迫停損,所以此時就使用盤整模式的程式下去操作也未嘗不可.
以下是盤整模式的程式碼,大家可以參考看看,然而這比較適合盤整階段,如果遇到了順勢盤,或開放型態的盤時,就容易虧損,所以必須再配合其它的策略操作 .在這只提供參考,不負任何盈虧的責任喔!









Parameter: Price(close)
var : CDPA(0),AH(0),NH(0),NL(0),AL(0),DS(0),DB(0)
 
  IF DATE[1] <> DATE  THEN
  DS=0
  DB =0  
  VALUE1= HIGHEST(CLOSE,59)
  VALUE2=LOWEST(CLOSE,59)
  IF TIME=85000 THEN
  VALUE3=CLOSE[1]
  END IF
  CDPA=(VALUE1+VALUE2+(VALUE3*2))/4
  AH=CDPA+(VALUE1-VALUE2)
  NH=CDPA*2-VALUE2
  NL=CDPA*2-VALUE1
  AL=CDPA-(VALUE1-VALUE2)
  END IF
  IF TIME >=85000 AND TIME <132000 THEN
  CONDITION1 =TRUE
  ELSE
  CONDITION1 =FALSE
  END IF 
IF  CONDITION1 AND  DS=0 AND  CLOSE>=NH THEN
SELL("NH") NEXT BAR ON MARKET
DS + =1
END IF
IF  CONDITION1 AND   DB = 0 AND CLOSE <=NL THEN
BUY("NL") NEXT BAR ON MARKET
DB + =1
END IF
IF CONDITION1 AND CLOSE > AH THEN
BUY("+AH") NEXT BAR ON MARKET
END IF
IF CONDITION1 AND  CLOSE <AL THEN
SELL("+AL") NEXT BAR ON MARKET
END IF

IF CurrentContracts <=-1 AND CLOSE > AH THEN
ExitSHORT from entry("NH") NEXT BAR ON MARKET
END IF
IF CurrentContracts=-2 AND CLOSE > NL THEN
ExitSHORT ("ALL_NL") NEXT BAR ON MARKET
END IF

 IF CURRENTCONTRACTS >=1 AND CLOSE <AL THEN
 ExitLong from entry("NL") NEXT BAR ON MARKET
 END IF

  IF CURRENTCONTRACTS =2 AND CLOSE <NH THEN
 ExitLong("ALL_AH") NEXT BAR ON MARKET
 END IF

IF TIME=133000 THEN
EXITSHORT("TO") THIS BAR ON CLOSE
EXITLONG("BTO")THIS BAR ON CLOSE
END IF


Posted by Picasa

2013年7月16日 星期二

多空轉則指標(程式碼)



 多空轉折指標 :
將多空更加明顯的顯現,
並且將壓力和支撐也標示出來

以下是程式碼 (HTS)
copy 貼上後可以直接使用






Variables:JJ(0),AA(0),B(0),TxtView(0)
JJ=(CLOSE+HIGH+LOW)/3
AA=EMA(JJ,10)
B=AA[1]
IF AA>B THEN
   DRAWBAR1(AA,B,AA,B,"多空",YELLOW,YELLOW,1)
END IF
IF AA[1]<B[1] THEN
   IF AA>B then
   TxtView = TXT_New( Date, Time,H + 50 Points,
          NumToStr(Low,2) + "|n")
   TXT_SetStyle( TxtView, 2, 2 ) 
   TXT_SetColor( TxtView, Blue )      
   End IF      
End IF
IF AA<B then
DRAWBAR1(AA,B,AA,B,"多空",blue,blue)
End IF
IF AA[1]>B[1] THEN
   IF AA<B then
   TxtView = TXT_New( Date, Time,L - 50 Points,
          NumToStr(Low,2) + "|n")
   TXT_SetStyle( TxtView, 2, 2 ) 
   TXT_SetColor( TxtView, RED )      
   End IF
End IF

原概念出處已無可考
Posted by Picasa

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

2013年7月8日 星期一

使用CCI 做成當沖程式(程式碼)

這是我多年前使用的程式 ! 其實還蠻穩定的 .雖然並無非常可觀的績效,不過這也是一種參考點 !

Parameter: n(10) ,Price(close), Length(20), UpMultiplier(2.0), DnMultiplier(-2.0),Length_1(30),L停損金額(2400),停損金額(1200)
var : up100(0) , low100(0) ,center(0),StopLossAmount(0), OrderPrice(0),DT(0)
if date[0] <> date[1] then DT=0 end if
up100 =100
low100=-100
center=0
/////////時間////////////
Condition1= time > 133000
Condition2= time > 90000
Condition3= time < 130000
/////////////////////////
//////買進//////////////
Condition4= cci(Length) cross over low100
//////買平倉////////////
Condition5= cci(Length) cross over low100
Condition8= cci(Length) cross over center
Condition9= cci(Length) cross over up100
//////濾網條件//////////
Condition6= vhf(n,length)>0.333
Condition7= vhf(n,length)<0.333
Condition10= cci(Length) cross under low100
Condition11= cci(Length) cross under center
Condition12= cci(Length) cross under up100

if (Condition2 and Condition3 ) and ( Condition6 and (Condition5)and( cci(Length)>-90)  ) or ( Condition6 and (Condition9)and( cci(Length)>110)  ) and dt =0 then
buy("買") next bar on market
DT=DT+1
end if

if (marketposition=1) and (Condition1 )or (Condition12 and Condition10) then
exitlong("買出") next bar on market
end if
if (Condition2 and Condition3 ) and ( Condition6 and (Condition12)and( cci(Length)>-90)  ) or ( Condition6 and (Condition10)and( cci(Length)>110)  ) and dt =0 then

sell("賣") next bar on market
DT=DT+1
end if
if (marketposition=-1) and (Condition1 )or ( Condition5 and Condition9 )then
exitshort("賣出") next bar on market
end if
If MarketPosition = 1 Then
 StopLossAmount = 停損金額 + Commission_B
    OrderPrice = Entryprice(0) - (StopLossAmount / PointValue)
 ExitLong ("多單停損") NEXT Bar at OrderPrice Stop
End if

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

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

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

if time>=131500  then
exitlong("b_out")NEXT BAR ON MARKET                                          
end if
if time>=131500 then
exitshort("s_out")NEXT BAR ON MARKET
end if
if  time>131500 then
EXITLONG ("T_BOUT") THIS BAR ON CLOSE
EXITSHORT ("T_SOUT") THIS BAR ON CLOSE
END IF


Posted by Picasa

2013年7月3日 星期三

MarketPosition 和 CurrentContracts 的差別 ?

MarketPosition  只能顯示多單 無單 和空單  沒辦法顯示現況內有幾口
MarketPosition  =1 有多單
MarketPosition  =0 無單
MarketPosition  =-1 有多單

CurrentContracts  只能顯示有幾口單,沒辦法顯示多單還是空單
CurrentContracts  =10 表示有10口單.但不知道是多單憨是空單
所以有時在程式中要作加減碼動作的時候,就必須知道此時倉內有幾口多單還是空單 ?
舉的例子 :
//假設條件一買進,二 成立時加碼買進

if MarketPosition  =0 and condition1 then 
buy("Buy1") next bar on market
end if
if MarketPosition  *  CurrentContracts  >=1 and condition2 then
buy("Buy2") next bar on market
end if

//假設條件三成立時 出一口多單 , 條件四成立時出掉全部

if MarketPosition  *  CurrentContracts  >0 and condition1 then 
exitlong("ExitBuy") next bar on market
end if
if MarketPosition  *  CurrentContracts  >0 and condition2 then
exitlong("AllExit") all contracts next bar at market
end if

其實重點是在於,將MarketPosition  *  CurrentContracts   這樣就可以知道倉內現在有幾口多單,
還是幾口空單了!
Posted by Picasa

2013年7月1日 星期一

程式語法 買賣點函數(名:W_Dragon )

這是我數年前所使用的一個買賣點型態函數 ,現在讓大家玩玩看 !

此函數名為 W_Dragon
W_Dragon =1 買進訊號
W_Dragon =0 放空訊號

純粹參考使用,不要直接拿去當買賣使用喔 ! 此範例為函數型態,所以須新增於函數內後再使用.
沒有出場機制,要自行加入喔 !



If CNDL_TrendDown[2]            and
 CNDL_WhiteLine[2]                 and
 CNDL_WhiteLine[1]                 and
 CNDL_WhiteLine                     and
 Open[1] >= Min(Open[2], Close[2]) and
 Open[1] <= Max(Open[2], Close[2]) and
 Open >= Min(Open[1], Close[1])    and
 Open <= Max(Open[1], Close[1])    and
 Close[1] >= Close[2]              and
 Close >= Close[1] and  time>85500 Then
 condition1=true
End If
If CNDL_TrendDown                   and
   CNDL_LongBody(10)               and
   CNDL_BlackLine                      and
   CNDL_UpShadow < CNDL_Height * 0.1   and
   CNDL_DownShadow < CNDL_Height * 0.1 Then
   condition1=false
End If
If CNDL_TrendUp[1]        and
 CNDL_WhiteLine[1]     and
 CNDL_BlackLine        and
 CNDL_LongBody(10) and
 CNDL_Engulfing Then
 condition1=false
End If
If CNDL_TrendUp[2]                                   and
 CNDL_LongBody(10)[2]                         and
 CNDL_WhiteLine[2]                                and
 CNDL_ShortBody(10)[1]                        and
 !CNDL_Doji[1]                                    and
 Min(Close[1], Open[1]) > Max (Close[2], Open[2]) and
 CNDL_BlackLine                                   and
 Close < Close[2] Then
 condition1=false
End If
if close[2]<open[2] and close[1]<open[1] and close<open then
condition1=false
end if
if condition1=true then
W_Dragon  =1
else
W_Dragon  =0
end if
Posted by Picasa

期貨買賣進出查詢語法

期貨買賣查詢

EntryDate:  買賣日期
EntryName:買賣訊號名稱
EntryPrice: 買賣價格
EntryTime: 買賣時間
EntryType: 多空形式,多為1,空為-1
ExitDate:    平倉日期
ExitName:  平倉訊號名稱
ExitPrice:   平倉價
ExitTime:   平倉時間
CurrentEntries : 大於0 時表示有未平倉數
CurrentContracts  : 傳回現有的倉位數
AvgEntryPrice : 傳回交易平均成交價
 
Posted by Picasa

2013年6月27日 星期四

一天只下一趟單 語法

衝浪吧!
當沖交易者,有時會考慮交易過度頻繁,所以常會限制,交易的次數,比如一天只作1~2趟,後面如再有訊號也不在下單,諸如此類的策略,以下為我用的方法.


vars:DayOnce(0)

If  Date[0] <> Date[1] Then
    DayOnce=0
End If

if  策略一 = true and DayOnce=0 Then
   Buy("buy") Next Bar On Market
   DT + =1
end if

如要改成2口 把橘色DayOnce=0  改成DayOnce<2 以此類推
方法簡單吧 !

Posted by Picasa

停損語法

在此介紹一下我常用的一個停損方法.

語法 :
If MarketPosition = 1 Then
    StopLossPoint = Amount + Commission_B
    Order = Entryprice(0) - (StopLossPoint / PointValue)
    ExitLong ("多單停損") NEXT Bar at Order Stop
End if


MarketPosition = 1  (多單 , 空單的話改為負數,0 為無單狀態)
StopLossPoint  (停損的金額)
Amount  (預設停損的金額)Commission_B (手續費)
ExitLong  (多單出場)
PointValue (取決於所點選的視窗,如大台為200,小台則為50)

多單停損的話,將 MarketPosition 改為-1 , ExitLong ("多單停損") 改為ExitShort("空單停損") 即可

蠻基本的一個停損語法,可試試看囉 !
                                    
Posted by Picasa