이 전략은 K선 형태를 식별하여 가격 형태 거래를 구현한다. K선 형태는 최근에 나타난吊선 형태를 찾아서 형태 신호에 따라 더 많이 또는 더 적게 한다. 거래자는 스톱 스톱 손실의 배수를 설정할 수 있다. 트렌드 추적 스톱 손실은 더 많은 이익을 잠금 할 수 있다.
현재 K선에 대한 함수선 형태 요구사항을 확인한다: 엔터티는 하반기에 위치하고 있으며, 닫기 가격과 열기 가격이 낮은 지점에 가깝다. 반대로 다중 신호를 하면, 엔터티는 상반기에 위치하고 있으며, 닫기 가격이 높은 지점에 가깝다. 마지막 거래 신호의 K선을 찾고, K선 엔터티의 높이를 계산한다.
진입 후 트렌드 추적을 시작하여 스톱 라인을 점진적으로 이익 방향으로 이동하고 스톱 라인은 스톱 또는 스톱 손실이 촉발 될 때까지 변하지 않습니다.
최적화 변수, 보조 지표 등의 방법으로 위험을 줄일 수 있다.
이 전략은 형태 식별을 이용하여 거래 기회를 발견하고, 재검토하는 데 좋은 성과를 내고 있다. 정지/피해 설정은 합리적이며, 단일 거래의 위험을 제어할 수 있다. 변수 최적화 등으로 더 발전하여, 간단한 실용적인 거래 시스템이 될 수 있다.
/*backtest
start: 2023-09-10 00:00:00
end: 2023-09-17 00:00:00
period: 5m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
//
// Pinbar strategy script by samgozman (https://github.com/samgozman)
//
// Detailed instruction how to use this script: https://github.com/samgozman/pinbar-strategy-tradingview
//
// If you liked the script and want to support me: https://paypal.me/sgozman
//
// ++++++++++ Warning: The script is provided for educational purposes only. ++++++++++ //
strategy('Pinbar strategy', default_qty_type=strategy.percent_of_equity, default_qty_value=100, initial_capital=10000)
profitMultiplier = input.float(2.0, "Profit multiplier", minval=0.1, step=0.1, group="Profit options", tooltip="X times signal candle size from high")
lossMultiplier = input.float(1.0, "Loss multiplier", minval=0.1, step=0.1, group="Profit options", tooltip="X times signal candle size from low")
isTrailingStop = input.bool(true, "Use trailing stops?", group="Trading options", tooltip="Highly recommended!")
isCloseOnOppositSignal = input.bool(false, "Close trade if opposit signal occures?", group="Trading options", tooltip="Close long on short signal")
isLongEligible = input.bool(true, "Enter long trades?", group="Trading options")
isShortEligible = input.bool(true, "Enter short trades?", group="Trading options")
useDateFilter = input.bool(true, title="Begin Backtest at Start Date", group="Backtest Time Period")
backtestStartDate = input(timestamp("1 Jan 2021"), title="Start Date", group="Backtest Time Period")
// Predefined time trading zone for back testing
inTradeWindow = true
// HELPER FUNCTIONS //
// calculate candle size for N bars back. Use 0 for current
calcCandle(int periods) =>
math.abs(high[periods] - low[periods])
// if body is below 50% and close/open below 30%
isBearishPinbar(float candle) =>
lower30 = low + candle * 0.30
bottomHalf1 = close < hl2
bottomHalf2 = open < hl2
lowerRegion1 = close < lower30
lowerRegion2 = open < lower30
con1 = bottomHalf1 and bottomHalf2
con2 = lowerRegion1 and lowerRegion2
con3 = high > high[1]
con1 and con2 and con3
// if body is above 50% and close/open above 30%
isBullishPinbar(float candle) =>
upper30 = high - candle * 0.30
topHalf1 = close > hl2
topHalf2 = open > hl2
upperRegion1 = close > upper30
upperRegion2 = open > upper30
con1 = topHalf1 and topHalf2
con2 = upperRegion1 and upperRegion2
con3 = low < low[1]
con1 and con2 and con3
barsSinceLastEntry() =>
strategy.opentrades > 0 ? bar_index - strategy.opentrades.entry_bar_index(strategy.opentrades - 1) : na
// Calculate trading signals
currentCandle = calcCandle(0)
longSignal = isBullishPinbar(currentCandle) and inTradeWindow
shortSignal = isBearishPinbar(currentCandle) and inTradeWindow
// ENTER THE TRADE //
if longSignal and isLongEligible
strategy.entry("buy", strategy.long, when = strategy.position_size == 0)
if shortSignal and isShortEligible
strategy.entry("sell", strategy.short, when = strategy.position_size == 0)
// CALCULATE STOPS //
barsSinceEntry = barsSinceLastEntry()
candleFromEntry = calcCandle(barsSinceEntry)
// long
long_take_limit = strategy.position_avg_price + (candleFromEntry*profitMultiplier)
long_target_percent_profit = long_take_limit / strategy.position_avg_price - 1
long_target_percent_loss = (long_target_percent_profit / profitMultiplier) * lossMultiplier
long_stop_limit = low[barsSinceEntry] * (1 - long_target_percent_loss)
//short
short_take_limit = strategy.position_avg_price - (candleFromEntry*profitMultiplier)
short_target_percent_profit = strategy.position_avg_price / short_take_limit - 1
short_target_percent_loss = (short_target_percent_profit / profitMultiplier) * lossMultiplier
short_stop_limit = high[barsSinceEntry] * (1 + short_target_percent_loss)
// EXIT THE TRADE //
if strategy.position_size > 0 or strategy.position_size < 0
if isTrailingStop
strategy.exit(id="exit", from_entry="buy", trail_price = long_take_limit, stop=long_stop_limit)
strategy.exit(id="exit", from_entry="sell", trail_price = short_take_limit, stop=short_stop_limit)
else
strategy.exit(id="exit", from_entry="buy", limit = long_take_limit, stop=long_stop_limit)
strategy.exit(id="exit", from_entry="sell", limit = short_take_limit, stop=short_stop_limit)
if isCloseOnOppositSignal
strategy.close("buy", when = shortSignal)
strategy.close("sell", when = longSignal)
// PLOT SIGNALS //
plotshape(longSignal, style=shape.arrowup, color=color.new(color.green, 0), size=size.large, location=location.belowbar)
plotshape(shortSignal, style=shape.arrowdown, color=color.new(color.red, 0), size=size.large, location=location.abovebar)