Reputation: 11
I try to create two different strategy.exit function for one entry(one of them is for limit, other one is for stop). Because I want to take different comments from these two exit function.
Related code snippet:
strategy.entry("Longi" , direction = strategy.long, limit = close + 5)
strategy.exit("LongKapa" , from_entry = "Longi" , limit = xxx)
strategy.exit("LongKapa" , from_entry = "Longi" , stop = xxx)
But strategy tester neglect second one. So how can I get two different comments without using strategy.order in if block ?
Upvotes: 1
Views: 3873
Reputation: 309
strategy.exit
has dedicated comment arguments for that purpose: comment, comment_profit, comment_loss, comment_trailing
, which are used based on the condition, which triggered the exit. Check help for details, but in your example you'd use:
strategy.exit("LongKapa" , from_entry = "Longi" ,
limit = xxx, stop = xxx,
comment_profit = 'Limit triggered',
comment_loss = 'Stop triggered'
)
Upvotes: 1
Reputation: 82
You should give it unique id's otherwise you will modify
and not create
a new one.
strategy.entry("Longi" , direction = strategy.long, limit = close + 5, qty=2)
strategy.exit("LongKapa-1" , from_entry = "Longi" , limit = xxx, qty=1)
strategy.exit("LongKapa-2" , from_entry = "Longi" , stop = xxx, qty=1)
https://www.tradingview.com/pine-script-reference/v5/#fun_strategy{dot}exit
Upvotes: 3
Reputation: 122
Use logical or
. Applicable to boolean expressions.
longCondition = ta.crossunder(ta.sma(close, 20), ta.sma(close, 50))
if (longCondition)
strategy.entry("My Long Entry Id", strategy.long)
exitCondition = ta.crossunder(ta.sma(close, 10), ta.sma(close, 20)) or ta.crossunder(ta.sma(close, 10), ta.sma(close, 50))
if (exitCondition)
strategy.exit("exit", "My Long Entry Id", profit = 10, loss = 5)
Upvotes: 1