I am having a problem with two different types of closing out of a trade. For example, when a long position is in effect I would like to have 2 different ways to get out of the trade:
It seems when I attempt to do this only one of the exits is utilized and the other one is discarded. Since the boolean condition is mainly used to take profit would it just make more sense to use that as a take profit or is there a way I could use both?
Below is the code I am using.
// long entry
if (flaglong)
strategy.entry("Long", strategy.long, qty=2)
strategy.exit("Long", strategy.short, stop=low[1]-1.5)
// long exit
if (flagshort1)
strategy.close("Long", qty=2)
You can use both.
Your code should not compile because you are using the strategy.exit()
function wrong. You are passing strategy.short
to its from_entry
argument which should throw a compiler error.
The first argument of the strategy.exit()
function is id
, and the second one is from_entry
.
Call it like below:
if (longCondition)
strategy.entry("Long", strategy.long)
strategy.exit("Long Exit", "Long", stop=low[1]-1.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.