[英]pine script different strategy.exit
我很難擁有兩種不同的strategy.exit
。 一個用於止盈,另一個用於追蹤止損。 如果我將兩者放在同一個strategy.exit
行中,該策略就可以正常工作,但我希望圖表上有兩個不同的標簽,用於 TP,其他標簽用於 TSL。 如果我放了兩個strategy.exit
,只有獲利工作。
// Get inputs
atrLength = input.int(title="ATR Length", defval=21, minval=1)
useStructure = input.bool(title="Use Structure?", defval=true)
lookback = input.int(title="How Far To Look Back For High/Lows", defval=9, minval=1)
atrStopMultiplier = input.float(title="ATR Multiplier", defval=0.85, minval=0.1, step = 0.05)
// Calculate data
atr = ta.atr(atrLength)
lowestLow = ta.lowest(low, lookback)
highestHigh = ta.highest(high, lookback)
longStop = (useStructure ? lowestLow : close) - atr * atrStopMultiplier
shortStop = (useStructure ? highestHigh : close) + atr * atrStopMultiplier
//-------------------------------------------------------------------------------------- ATR Trailing Stop Loss --------------------------------------------------------------------------
//-------------------------------------------------------------------------------------- Take Profit -------------------------------------------------------------------------------------
longProfitPerc = input.float(title="Long Take Profit (%)", minval=0.0, step=0.1, defval=1) * 0.01
shortProfitPerc = input.float(title="Short Take Profit (%)", minval=0.0, step=0.1, defval=1) * 0.01
// Figure out take profit price
longExitPrice = strategy.position_avg_price * (1 + longProfitPerc)
shortExitPrice = strategy.position_avg_price * (1 - shortProfitPerc)
// Submit exit orders for take profit
if strategy.position_size > 0
strategy.exit(id='Long STOP', limit=longExitPrice, alert_message="close BTCUSDT a=usdm")
strategy.exit(id = 'L - TSL', stop = longStop)
if strategy.position_size < 0
strategy.exit(id='Short STOP', limit=shortExitPrice, alert_message="close BTCUSDT a=usdm")
strategy.exit(id = 'S - TSL', stop = shortStop)
擁有一個strategy.exit()
並使用strategy.exit()
() 的comment_profit
和comment_loss
屬性。
strategy.exit(id='Long Exit', limit=longExitPrice, stop = longStop, alert_message="close BTCUSDT a=usdm", comment_profit="Long - TP", comment_loss="Long SL")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.