lbilli / rib

An R implementation of Interactive Brokers API
GNU General Public License v3.0
34 stars 7 forks source link

fCondition #10

Open Camilo-Mora opened 3 years ago

Camilo-Mora commented 3 years ago

great work with this package.

May I ask if it is possible to include more than one condition in your fCondition function?

For instance, in a trailing stop order, could it be possible to use a different trailing offset for say two or more given prices?...

say, I go long at $10 and, place a trailing stop 1% below. can one set a conditional second trailing stop at 0.5%, when price is above $11?

this could make your function very useful to adjusts offset values, when there is a strong trending, like explained here

lbilli commented 3 years ago

Thanks for the feedback. The function fCondition() is just a simple helper that creates a template condition that can be customized and attached to an order.

The supported condition types are the ones made available by IB and are listed here. The way conditions can be attached to orders in TWS is demonstrated in this video.

Similar tasks can be accomplished with this package: here's an example of how to attach two conditions (Price AND Time) to an order:

# Condition 1: price of AAPL > 200
cond1 <- fCondition("Price")
cond1$conId    <- 265598L
cond1$exchange <- "SMART"
cond1$is_more  <- TRUE
cond1$value    <- 200
cond1$conjunction <- "a"         # AND

# Condition 2: time > Jul 6 15:00
cond2 <- fCondition("Time")
cond2$is_more <- TRUE
cond2$value   <- "20210706 15:00:00 EDT"

# Attach to order
order$conditions <- list(cond1, cond2)
Camilo-Mora commented 3 years ago

wow, this is really something....i can see this function being automatized to ride the waves up and down a price trend... excellent function...thanks.