R-quantum vectors cancel each other

How to enter orders that cancel each other in a quantum? For example, as soon as I enter a trade, I immediately open two orders: “stop loss” and “take profit”. As soon as someone fills, the other will be canceled.

#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) 

They are currently working independently.

+3
source share
1 answer

SVN r 1010 adds code to the quantstand to simplify the use of OCO (One Cancels Other) order sets. The "macd" demo has an example that uses the new orderset parameter to provide OCO functionality in output orders.

svn (r1010 ). , , .

, , :

#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="long", threshold=-5, 
                                    tmult=FALSE, orderset='altexits'), 
                     type="exit", path.dep=TRUE)

#Take profit

strategy <- add.rule(strategy, name="ruleSignal", 
                     arguments=list(sigcol="EnterBuy", sigval=TRUE,
                                    orderqty="all", ordertype="stoplimit", 
                                    orderside="long", threshold=5, 
                                    tmult=FALSE, orderset='altexits'),
                     type="exit", path.dep=TRUE) 

orderset = 'altexits' ruleSignal.

+8

All Articles