How to enter orders that cancel each other in quantstrat? For example, once I enter a trade, I immediately open two orders: "stop loss" and "take profit". Once one gets filled, the other will be cancelled.
#Enter signal
strategy <- add.rule(strategy, name="ruleSignal",
arguments=list(sigcol="EnterBuy", sigval=TRUE, orderqty=100,
ordertype="market", orderside="long",
pricemethod="market", osFUN=osMaxPos),
type="enter", path.dep=TRUE)
#Stop loss
strategy <- add.rule(strategy, name="ruleSignal",
arguments=list(sigcol="EnterBuy", sigval=TRUE,
orderqty="all", ordertype="stoplimit",
orderside="short", threshold=-5,
tmult=FALSE),
type="exit", path.dep=TRUE)
#Take profit
strategy <- add.rule(strategy, name="ruleSignal",
arguments=list(sigcol="EnterBuy", sigval=TRUE,
orderqty="all", ordertype="stoplimit",
orderside="short", threshold=5,
tmult=FALSE),
type="exit", path.dep=TRUE)
Currently, they are working independently.