The code is below.
//@version=4
strategy("52 Weeks High with Trailing Stop", overlay=true)
// Define input variables
trailStopPercent = input(1.0, "Trailing Stop Percentage")
// Calculate the 52-week high
high52Weeks = highest(high, 252)
// Define entry conditions
enterLong = close \> high52Weeks
// Define exit conditions
exitLong = close \< low\[1\] \* (1 - trailStopPercent / 100)
// Calculate position size based on account capital
accountCapital = strategy.equity
positionSize = accountCapital \* 0.01 // 1% of account capital
// Execute long trade
if enterLong and strategy.position_size == 0
strategy.entry("Long", strategy.long, qty = positionSize)
// Exit long trade
if exitLong
strategy.close("Long")
// Plotting 52-week high
plot(high52Weeks, "52 Weeks High", color=color.blue, linewidth=2)
Run the code, expecting results in the strategy, displayed in the performance window in trading view but unfortunately did not return any results. It only displayed the overly on the chart but not the actual strategy results and performance.