In Pine script, the time of a trailing stop trigger can be obtained using the time
built-in variable. This variable returns the Unix timestamp of the current bar or candle.
For example, if you want to record the time when a trailing stop is triggered, you can assign the value of time
to a variable or use it in a label
function like this:
//@version=4
strategy("My Strategy")
trailing_stop = strategy.position_avg_price * 0.9 // 10% trailing stop
trailing_stop_triggered_time = 0
if strategy.position_size > 0
if close < trailing_stop
strategy.exit("Trailing Stop", "Buy", trail_percent = 10)
trailing_stop_triggered_time := time
plot(trailing_stop)
label.new(bar_index, trailing_stop, "Trailing Stop", color.red)
if trailing_stop_triggered_time
label.new(bar_index, low - atr(14), tostring(trailing_stop_triggered_time), xloc.bar_time)
In this example, the trailing_stop_triggered_time
variable is assigned the value of time
when the trailing stop is triggered. Then, in the if trailing_stop_triggered_time
block, a label is added to the chart to display the timestamp of the trigger.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2021-06-02 11:00:00 +0000
Seen: 11 times
Last updated: Mar 21 '22
Is it possible for you to assist me with understanding the time complexity?
At compile time, how can I change a C string into an integer?
What is the process to activate the screen time off feature in Android using AOSP customization?
What is the meaning of charged_seconds and compute_seconds in Redshift serverless?
What are the steps for formatting time in various hh:mm:ss formats in Excel?
How to convert time differences between different time zones?