EasyTrader ArtNo 159
短期多頭: 低點高於先前最低K棒的高點
短期空頭: 高點低於先前最高K棒的低點
先從指標開始觀察 ,指標程式碼怎麼作呢 ? 在內建函數中有幾個可以運用
{ 高低點左右強度相同 - 以上圖中間最高K棒的兩邊都有 2根較低的K棒}
SwingHigh - 在給定區間內找尋最近 N次特定強度的轉折高點
SwingHighBar - 回傳找到的高點相對目前K棒的距離
SwingLow - 在給定區間內找尋最近 N次特定強度的轉折低點
SwingLowBar - 回傳找到的低點相對目前K棒的距離
如果要找過去 15根K棒中 ,最近一次強度為 2的轉折高點
SwingHigh( 1 {最近一次} , High {高點} , 2 {強度} , 15{ K棒數} ) ;
{ 高低點左右強度不同 - 以上圖中間最高K棒的左邊是 2根較低的K棒,右邊是 3根較低K棒}
PivotHighVS - 在給定區間內找尋最近 N次特定強度的轉折高點
PivotHighVSBar - 回傳找到的高點相對目前K棒的距離
PivotLowVS - 在給定區間內找尋最近 N次特定強度的轉折低點
PivotLowVSBar - 回傳找到的低點相對目前K棒的距離
如果要找過去 15根K棒中 ,最近一次左 2 強度右 3 的轉折高點
PivotHighVS ( 1 {最近一次} , High {高點} , 2 {左強度} , 3 {右強度}15{ K棒數} ) ;
{ 將主程式內的 HBL (HighBarLow) 與 LBH (LowBarHigh) 那段放在指標就可以繪出上圖 }
input:EntryType(1),ExitType(1) ,LongLen(15),ShortLen(15),StrengthL(2),StrengthS(2),GapLong(50),GapShort(50),NBarL(2),NBarS(2),ATRs_L(2),ATRs_S(2) ;
Vars:HighBarLow1(0),HighBarNo1(0),HighBarLow2(0),HighBarNo2(0),HighBarLow3(0),HighBarNo3(0),HBL(0);
Vars:LowBarNo1(0),LowBarHigh1(0),LowBarNo2(0),LowBarHigh2(0),LowBarNo3(0),LowBarHigh3(0),LBH(0);
Vars:HR1(-1),HR2(-1),HR3(-1),LR1(-1),LR2(-1),LR3(-1) ;
Vars: MP(0),isBalanceDay(false) ;
HR1 = -1 ;
HR2 = -1 ;
HR3 = -1 ;
LR1 = -1 ;
LR2 = -1 ;
LR3 = -1 ;
MP = MarketPosition ;
if DAYofMonth(Date) > 14 and DAYofMonth(Date) < 22 and DAYofWeek(Date)= 3 then isBalanceDay = True else isBalanceDay =False ;
{ 利用 SwingHigh 相關函數找出區間的的轉折高點 ,若無轉折點則以區間最高的低點作參考 ,本例先尋找最近的三個轉折高點作比較}
HR1 = SwingHigh(1,High,StrengthL,LongLen) ;
if HR1 > -1 then Begin
HighBarNo1 = SwingHighBar(1,High,StrengthL,LongLen) ;
HighBarLow1 = Low[HighBarNo1] ;
HBL = HighBarLow1 ;
HR2 = SwingHigh(2,High,StrengthL,LongLen) ;
if HR2 > -1 then Begin
HighBarNo2 = SwingHighBar(2,High,StrengthL,LongLen) ;
HighBarLow2 = Low[HighBarNo2] ;
if High[HighBarNo2] > High[HighBarNo1] then HBL = HighBarLow2 ;
HR3 = SwingHigh(3,High,StrengthL,LongLen) ;
if HR3 > -1 then Begin
HighBarNo3 = SwingHighBar(3,High,StrengthL,LongLen) ;
HighBarLow3 = Low[HighBarNo3] ;
if High[HighBarNo3] > MaxList(High[HighBarNo2],High[HighBarNo1]) then HBL = HighBarLow3 ;
end;
end;
end else HBL = Highest(Low,LongLen) [1];
{ 利用 SwingLow 相關函數找出區間的的轉折低點 ,若無轉折點則以區間最低的高點作參考 ,本例先尋找最近的三個轉折低點作比較}
LR1 = SwingLow(1,Low,StrengthS,ShortLen) ;
if LR1 > -1 then Begin
LowBarNo1 = SwingLowBar(1,Low,StrengthS,ShortLen) ;
LOwBarHigh1 = High[LowBarNo1] ;
LBH = LowBarHigh1 ;
LR2 = SwingLow(2,Low,StrengthS,ShortLen) ;
if LR2 > -1 then Begin
LowBarNo2 = SwingLowBar(2,Low,StrengthS,ShortLen) ;
LowBarHigh2 = High[LowBarNo2] ;
if Low[LowBarNo2] < Low[LowBarNo1] then LBH = LowBarHigh2 ;
LR3 = SwingLow(3,Low,StrengthS,ShortLen) ;
if LR3 > -1 then Begin
LowBarNo3 = SwingLowBar(3,Low,StrengthS,ShortLen) ;
LowBarHigh3 = High[LowBarNo3] ;
if Low[LowBarNo3] > MinList(Low[LowBarNo2],Low[LowBarNo1]) then LBH = LowBarHigh3 ;
end;
end;
end else LBH = Lowest(High,ShortLen)[1] ;
{ 如果不想寫的這麼複雜 ,最簡單的方式就是
HBL = Highest(Low,LongLen) [1] ; { 期間內最高的低點 }
LBH = Lowest(High,ShortLen)[1] ; { 期間內最低的高點 }
}
{ 利用收盤價 / 最高價 /最低價作測試的依據 ,並以高低點距離作濾網 }
if EntryType = 1 then Begin
if HBL > LBH+GapShort and Close Cross Under HBL then Sell next bar at Market ;
if HBL > LBH+GapLong and Close Cross Over LBH then Buy next bar at Market ;
end;
if EntryType = 2 then Begin
if HBL > LBH+GapLong and Close Cross Over HBL then Buy next bar at Market ;
if HBL > LBH+GapShort and Close Cross Under LBH then Sell next bar at Market ;
end;
{ 原策略邏輯進場 }
if EntryType = 3 then Begin
if HBL > LBH+GapShort and High Cross under HBL then Sell next bar at Market ;
if HBL > LBH+GapLong and Low Cross over LBH then Buy next bar at Market ;
end;
{ 加上出場條件 }
if ExitType = 1 then Begin
if MP > 0 and BarsSinceEntry = NBarL then ExitLong next bar at Market ;
if MP < 0 and BarsSinceEntry = NBarS then ExitShort next bar at Market ;
end;
if ExitType = 2 then Begin
{Inputs: ATRs_L(3);}
Variables: PosHigh(0), ATRVal_L(0);
ATRVal_L = AvgTrueRange(10) * ATRs_L;
If BarsSinceEntry = 0 Then
PosHigh = High;
If MarketPosition = 1 Then Begin
If High > PosHigh Then
PosHigh = High;
ExitLong ("ATR") Next Bar at PosHigh - ATRVal_L Stop;
End
else
ExitLong ("ATR eb") Next bar at High - ATRVal_L Stop;
{Inputs: ATRs_S(3);}
Variables: PosLow(0), ATRVal_S(0);
ATRVal_S = AvgTrueRange(10) * ATRs_S;
If BarsSinceEntry = 0 Then
PosLow = Low;
If MarketPosition = -1 Then Begin
If Low < PosLow Then
PosLow = Low;
ExitShort ("ATR_1") Next Bar at PosLow + ATRVal_S Stop;
End else
ExitShort ("ATR_1 eb") Next bar at Low + ATRVal_S Stop;
end;
if IsBalanceDay then setExitonClose ;
{ 高低點左右強度相同 - 以上圖中間最高K棒的兩邊都有 2根較低的K棒}
SwingHigh - 在給定區間內找尋最近 N次特定強度的轉折高點
SwingHighBar - 回傳找到的高點相對目前K棒的距離
SwingLow - 在給定區間內找尋最近 N次特定強度的轉折低點
SwingLowBar - 回傳找到的低點相對目前K棒的距離
如果要找過去 15根K棒中 ,最近一次強度為 2的轉折高點
SwingHigh( 1 {最近一次} , High {高點} , 2 {強度} , 15{ K棒數} ) ;
{ 高低點左右強度不同 - 以上圖中間最高K棒的左邊是 2根較低的K棒,右邊是 3根較低K棒}
PivotHighVS - 在給定區間內找尋最近 N次特定強度的轉折高點
PivotHighVSBar - 回傳找到的高點相對目前K棒的距離
PivotLowVS - 在給定區間內找尋最近 N次特定強度的轉折低點
PivotLowVSBar - 回傳找到的低點相對目前K棒的距離
如果要找過去 15根K棒中 ,最近一次左 2 強度右 3 的轉折高點
PivotHighVS ( 1 {最近一次} , High {高點} , 2 {左強度} , 3 {右強度}15{ K棒數} ) ;
{ 將主程式內的 HBL (HighBarLow) 與 LBH (LowBarHigh) 那段放在指標就可以繪出上圖 }
input:EntryType(1),ExitType(1) ,LongLen(15),ShortLen(15),StrengthL(2),StrengthS(2),GapLong(50),GapShort(50),NBarL(2),NBarS(2),ATRs_L(2),ATRs_S(2) ;
Vars:HighBarLow1(0),HighBarNo1(0),HighBarLow2(0),HighBarNo2(0),HighBarLow3(0),HighBarNo3(0),HBL(0);
Vars:LowBarNo1(0),LowBarHigh1(0),LowBarNo2(0),LowBarHigh2(0),LowBarNo3(0),LowBarHigh3(0),LBH(0);
Vars:HR1(-1),HR2(-1),HR3(-1),LR1(-1),LR2(-1),LR3(-1) ;
Vars: MP(0),isBalanceDay(false) ;
HR1 = -1 ;
HR2 = -1 ;
HR3 = -1 ;
LR1 = -1 ;
LR2 = -1 ;
LR3 = -1 ;
MP = MarketPosition ;
if DAYofMonth(Date) > 14 and DAYofMonth(Date) < 22 and DAYofWeek(Date)= 3 then isBalanceDay = True else isBalanceDay =False ;
{ 利用 SwingHigh 相關函數找出區間的的轉折高點 ,若無轉折點則以區間最高的低點作參考 ,本例先尋找最近的三個轉折高點作比較}
HR1 = SwingHigh(1,High,StrengthL,LongLen) ;
if HR1 > -1 then Begin
HighBarNo1 = SwingHighBar(1,High,StrengthL,LongLen) ;
HighBarLow1 = Low[HighBarNo1] ;
HBL = HighBarLow1 ;
HR2 = SwingHigh(2,High,StrengthL,LongLen) ;
if HR2 > -1 then Begin
HighBarNo2 = SwingHighBar(2,High,StrengthL,LongLen) ;
HighBarLow2 = Low[HighBarNo2] ;
if High[HighBarNo2] > High[HighBarNo1] then HBL = HighBarLow2 ;
HR3 = SwingHigh(3,High,StrengthL,LongLen) ;
if HR3 > -1 then Begin
HighBarNo3 = SwingHighBar(3,High,StrengthL,LongLen) ;
HighBarLow3 = Low[HighBarNo3] ;
if High[HighBarNo3] > MaxList(High[HighBarNo2],High[HighBarNo1]) then HBL = HighBarLow3 ;
end;
end;
end else HBL = Highest(Low,LongLen) [1];
{ 利用 SwingLow 相關函數找出區間的的轉折低點 ,若無轉折點則以區間最低的高點作參考 ,本例先尋找最近的三個轉折低點作比較}
LR1 = SwingLow(1,Low,StrengthS,ShortLen) ;
if LR1 > -1 then Begin
LowBarNo1 = SwingLowBar(1,Low,StrengthS,ShortLen) ;
LOwBarHigh1 = High[LowBarNo1] ;
LBH = LowBarHigh1 ;
LR2 = SwingLow(2,Low,StrengthS,ShortLen) ;
if LR2 > -1 then Begin
LowBarNo2 = SwingLowBar(2,Low,StrengthS,ShortLen) ;
LowBarHigh2 = High[LowBarNo2] ;
if Low[LowBarNo2] < Low[LowBarNo1] then LBH = LowBarHigh2 ;
LR3 = SwingLow(3,Low,StrengthS,ShortLen) ;
if LR3 > -1 then Begin
LowBarNo3 = SwingLowBar(3,Low,StrengthS,ShortLen) ;
LowBarHigh3 = High[LowBarNo3] ;
if Low[LowBarNo3] > MinList(Low[LowBarNo2],Low[LowBarNo1]) then LBH = LowBarHigh3 ;
end;
end;
end else LBH = Lowest(High,ShortLen)[1] ;
{ 如果不想寫的這麼複雜 ,最簡單的方式就是
HBL = Highest(Low,LongLen) [1] ; { 期間內最高的低點 }
LBH = Lowest(High,ShortLen)[1] ; { 期間內最低的高點 }
}
{ 利用收盤價 / 最高價 /最低價作測試的依據 ,並以高低點距離作濾網 }
if EntryType = 1 then Begin
if HBL > LBH+GapShort and Close Cross Under HBL then Sell next bar at Market ;
if HBL > LBH+GapLong and Close Cross Over LBH then Buy next bar at Market ;
end;
if EntryType = 2 then Begin
if HBL > LBH+GapLong and Close Cross Over HBL then Buy next bar at Market ;
if HBL > LBH+GapShort and Close Cross Under LBH then Sell next bar at Market ;
end;
{ 原策略邏輯進場 }
if EntryType = 3 then Begin
if HBL > LBH+GapShort and High Cross under HBL then Sell next bar at Market ;
if HBL > LBH+GapLong and Low Cross over LBH then Buy next bar at Market ;
end;
{ 加上出場條件 }
if ExitType = 1 then Begin
if MP > 0 and BarsSinceEntry = NBarL then ExitLong next bar at Market ;
if MP < 0 and BarsSinceEntry = NBarS then ExitShort next bar at Market ;
end;
if ExitType = 2 then Begin
{Inputs: ATRs_L(3);}
Variables: PosHigh(0), ATRVal_L(0);
ATRVal_L = AvgTrueRange(10) * ATRs_L;
If BarsSinceEntry = 0 Then
PosHigh = High;
If MarketPosition = 1 Then Begin
If High > PosHigh Then
PosHigh = High;
ExitLong ("ATR") Next Bar at PosHigh - ATRVal_L Stop;
End
else
ExitLong ("ATR eb") Next bar at High - ATRVal_L Stop;
{Inputs: ATRs_S(3);}
Variables: PosLow(0), ATRVal_S(0);
ATRVal_S = AvgTrueRange(10) * ATRs_S;
If BarsSinceEntry = 0 Then
PosLow = Low;
If MarketPosition = -1 Then Begin
If Low < PosLow Then
PosLow = Low;
ExitShort ("ATR_1") Next Bar at PosLow + ATRVal_S Stop;
End else
ExitShort ("ATR_1 eb") Next bar at Low + ATRVal_S Stop;
end;
if IsBalanceDay then setExitonClose ;
2 留言:
請問站長,EntryType是指?不同的進出廠策略嗎?謝謝!
站長大人,我有相同的問題,怎麼才能看到先前的回覆? 另外,還有EntryType。
謝謝!
張貼留言
如果有私人問題想請教,請透過網站右方『與站長聯絡』之表單,謝謝!