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?
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
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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.