0
votes

For some reason, the profit-and-loss (P&L) doesn't calculate at buyclose; instead, it takes the P&L between buy and sell order. I want the trade to close when the buyclose criteria are met and calculate P&L.

buy = (close> s) and (close > s2)
buyclose = (close < s) or (close < s2)
if (buy)
    strategy.entry("buy", long=true, when=buy)
    strategy.close("buy",when=buyclose)
1
Welcome to Stackoverflow! Please, visit the site below to know how to ask a good question. - AnyDozer

1 Answers

0
votes

In your case the if operator is redundant.

buy = (close> s) and (close>s2)
buyclose = (close<s) or (close<s2)

strategy.entry("buy", long=true, when=buy)
strategy.close("buy", when=buyclose)