Im wanting to create a Take Profit parametre that exit a position when a certain condition is met, for example
Long_take_Profit = ta.crossunder(adx, plus)
any solutions on how to turn this condition in to its float counter part or alternativley just use the condition itself. Thanks
TP (or limit ) is usually a line that the price must cross
But in this case (ADX cross DI), just use the condition itself.
if strategy.position_size > 0 and Long_take_Profit
strategy.exit(
id = 'Long Exit',
from_entry = 'Long Entry')
Since you want to close your position conditionally, you should use strategy.close()
.
If you additionally want to check if you are in profit, you can use the strategy.opentrades.profit
built-in variable.
is_in_profit = (strategy.opentrades.profit(strategy.opentrades - 1)) > 0
if (Long_take_Profit and is_in_profit)
strategy.close("Long")
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.