Help get this topic noticed by sharing it on Twitter, Facebook, or email.

How to calculate (or get) the 'life time' value of an open position in Pine Script?

For example, I want to close a position at the current market price if it has been opened >1 month ago , how do I code that? Thanks
1 person has
this question
  • Here's just to better explain my problem:

    if __BUY_CONDITION__
    strategy.entry("BUY", strategy.long)
    time_when_bought = time

    if __SELL_CONDITION__ and ( - time_when_bought > 1 month)
    strategy.entry("SELL", strategy.short)

    The above code does not work because 'time_when_bought' variable is defined within a local loop and thus not available for checking in the sell condition block... is there any way to make it work?
  • (some HTML allowed)
    How does this make you feel?
    Add Image

    e.g. kidding, amused, unsure, silly indifferent, undecided, unconcerned happy, confident, thankful, excited sad, anxious, confused, frustrated