改良版的抄底買入 回測數據

更新於 發佈於 閱讀時間約 12 分鐘
投資理財內容聲明

//@version=6

strategy('抄底 V2.0', overlay = true, pyramiding = 10, default_qty_type = strategy.percent_of_equity, default_qty_value = 10, initial_capital = 1000, commission_value = 0.1)


// BACKTESTING RANGE 日期區間設定

startDate = input.int(title = 'Start Date', defval = 1, minval = 1, maxval = 31)


startMonth = input.int(title = 'Start Month', defval = 1, minval = 1, maxval = 12)


startYear = input.int(title = 'Start Year', defval = 1970, minval = 1800, maxval = 2100)


endDate = input.int(title = 'End Date', defval = 15, minval = 1, maxval = 31)


endMonth = input.int(title = 'End Month', defval = 11, minval = 1, maxval = 12)


endYear = input.int(title = 'End Year', defval = 2030, minval = 1800, maxval = 2100)


// === FUNCTION ===


start = timestamp(startYear, startMonth, startDate, 00, 00)


finish = timestamp(endYear, endMonth, endDate, 23, 59)


window() =>time >= start and time <= finish ? true : false




// // TURN TD 8's & 9's ON / OFF


showBuyTDs = input(true, title = 'Show TD Buy')


showSellTDs = input(true, title = 'Show TD Sell')


len = input.int(10, 'len')




// // TD CALCS


buySignals = 0


buySignals := close < close[len] ? buySignals[1] == 21 ? 1 : buySignals[1] + 1 : 0




sellSignals = 0


sellSignals := close > close[len] ? sellSignals[1] == 21 ? 1 : sellSignals[1] + 1 : 0




BuyOrSell = math.max(buySignals, sellSignals)


TDbuy = showBuyTDs and bool(buySignals) and BuyOrSell < 9


TDbuy_up = showBuyTDs and bool(buySignals) and BuyOrSell >= 9


TD9buy = showBuyTDs and bool(buySignals) and BuyOrSell == 9


TD13buy = showBuyTDs and bool(buySignals) and BuyOrSell == 13


TD17buy = showBuyTDs and bool(buySignals) and BuyOrSell == 17


TD21buy = showBuyTDs and bool(buySignals) and BuyOrSell == 21




TDsell = showSellTDs and bool(sellSignals) and BuyOrSell < 9


TDsell_down = showSellTDs and bool(sellSignals) and BuyOrSell >= 9


TD9sell = showSellTDs and bool(sellSignals) and BuyOrSell == 9


TD13sell = showSellTDs and bool(sellSignals) and BuyOrSell == 13


TD17sell = showSellTDs and bool(sellSignals) and BuyOrSell == 17


TD21sell = showSellTDs and bool(sellSignals) and BuyOrSell == 21


// TD LABELS


plotshape(TD9buy, style = shape.labelup, text = '9', color = color.new(color.green, 0), textcolor = color.new(color.white, 0), size = size.tiny, location = location.belowbar)


plotshape(TD13buy, style = shape.labelup, text = '13', color = color.new(color.green, 0), textcolor = color.new(color.white, 0), size = size.tiny, location = location.belowbar)


plotshape(TD17buy, style = shape.labelup, text = '17', color = color.new(#4286d9, 0), textcolor = color.new(color.white, 0), size = size.tiny, location = location.belowbar)


plotshape(TD21buy, style = shape.labelup, text = '低', color = color.new(#2c2fff, 0), textcolor = color.new(color.white, 0), size = size.tiny, location = location.belowbar)




plotshape(TD9sell, style = shape.labeldown, text = '9', color = color.new(color.red, 0), textcolor = color.new(color.white, 0), size = size.tiny, location = location.abovebar)


plotshape(TD13sell, style = shape.labeldown, text = '13', color = color.new(color.red, 0), textcolor = color.new(color.white, 0), size = size.tiny, location = location.abovebar)


plotshape(TD17sell, style = shape.labeldown, text = '17', color = color.new(#ff0000, 0), textcolor = color.new(color.white, 0), size = size.tiny, location = location.abovebar)


plotshape(TD21sell, style = shape.labeldown, text = '高', color = color.new(#ff0ce7, 0), textcolor = color.new(color.white, 0), size = size.tiny, location = location.abovebar)


//


//---- Table Position & Size code start {----//


bullishpin = TD9buy or TD13buy or TD17buy or TD21buy


bearishpin = TD17sell


//


// 追蹤進場狀態


var bool enteredTD9 = false


var bool enteredTD13 = false




if window() and TD9buy and not enteredTD9

strategy.entry('TD9 Long', strategy.long)

enteredTD9 := true // 設定已進場

if window() and TD13buy and not enteredTD13

strategy.entry('TD13 Long', strategy.long)

enteredTD13 := true // 設定已進場

if window() and (TD17buy or TD21buy) // TD17 和 TD21 沒有限制

strategy.entry('TD17/21 Long', strategy.long)// 條件重置邏輯(可選)

if window() and bearishpin and close > strategy.position_avg_price

strategy.close_all() //多單出場 ID 條件

enteredTD9 := false

enteredTD13 := false// 如果出場,重置進場狀態

//

raw-image
raw-image

策略規則:

1 分批買進,下跌9天買入一次,每次投入10%資金,最多投入10次。

2 上漲時,股價超過當前入場的平均價,出清股票。

3 適用於各種績優股、高殖率股。



avatar-img
1會員
7內容數
~~
留言0
查看全部
avatar-img
發表第一個留言支持創作者!
youngchih 的沙龍 的其他內容
//@version=6 indicator('目標設定', overlay = true, max_lines_count = 40) // 輸入 ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
平均K線 (Heikin Ashi) 平均K線圖 (Heikin Ashi) 是一種圖表技術,可用於預測未來價格走勢。它類似於傳統的K線圖。但是,與常規K線圖不同,平均K線圖試圖透過消除強勁的價格波動來更好地識別市場趨勢,從而濾除一些市場噪音。 平均K線圖圖表上的K線如何計算? 平均K線圖使用
//@version=6 indicator('階梯交易線', overlay = true) // 變數初始化 var float ls = 1.0 // 初始化變數 ls,表示持有的交易信號,初始值為1(表示多頭)-1(表示空頭)0盤整 var float se = 0.0 // 初
//@version=6 indicator('目標設定', overlay = true, max_lines_count = 40) // 輸入 ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
平均K線 (Heikin Ashi) 平均K線圖 (Heikin Ashi) 是一種圖表技術,可用於預測未來價格走勢。它類似於傳統的K線圖。但是,與常規K線圖不同,平均K線圖試圖透過消除強勁的價格波動來更好地識別市場趨勢,從而濾除一些市場噪音。 平均K線圖圖表上的K線如何計算? 平均K線圖使用
//@version=6 indicator('階梯交易線', overlay = true) // 變數初始化 var float ls = 1.0 // 初始化變數 ls,表示持有的交易信號,初始值為1(表示多頭)-1(表示空頭)0盤整 var float se = 0.0 // 初
你可能也想看
Google News 追蹤