-
Notifications
You must be signed in to change notification settings - Fork 115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
quantstrat: Avoding consecutive entry orders #120
Comments
Thanks @rfinfun for the reproducible example. Let me see if i can assist.
# Add this line after you initialize the account and portfolio
addPosLimit(portfolio=p, symbol_str, timestamp = first(index(get(symbol_str))), 100, 1 ) #set max pos
# Add to your rules so they become:
s <- add.rule(
s, name='ruleSignal', type='enter', label='StochEntryLong',
arguments = list(
sigcol="StochEntryLong", sigval=TRUE, orderqty=orderQ,
TxnFees=.txnfees,
ordertype='market', orderside='long', orderset = "ocolong", osFUN=osMaxPos
)
)
s <- add.rule(
s, name='ruleSignal', type='exit', label='StochExitLong',
arguments = list(
sigcol="StochExitLong", sigval=TRUE, replace = TRUE, orderqty="all",
ordertype='market', orderside='long', orderset = "ocolong", osFUN=osMaxPos
)
) Now, I have a similar problem in a Turtles strategy i am adding to quantstrat. See the issue at #119. There must be a better solution than a maxPos, and i think i have solved for this with custom signals or custom indicators in the past. If i come up with something more elegant i will let you know.
|
Hi @jahmon0703 I will try that. It is not so elegant. I will be glad to look at your turtles implementation if that is helpful. I will research Kaiman filters, too. That sounds very elegant. Regards, Andreas |
I should add the osFUN param is probably where you want to solve your problem, and worth a look is some posts and code from @IlyaKipnis. https://quantstrattrader.wordpress.com/2014/09/02/the-limit-of-atr-order-sizing/ In Ilya's osDollarATR function for example (see https://github.com/IlyaKipnis/IKTrading/blob/master/R/osDollarATR.R), he takes the current position as an argument for determining the subsequent trade size. This example should be sufficient for you to define your own position management. [EDIT] Should probably ask @IlyaKipnis if we can include his osDollarATR function and example demo in quantstrat... |
Thanks, osFUN works as expected. IKTrading does not run on R 3.6.3, while DSTrading does. Maybe there are some additional functions that would be worth including in quantstrat. To build conditions a generic function would help: Allowing to evaluate multiple variables e.g. AND, OR, XOR, XAND, NOT or the like. I have seen comments frin @IlyaKipnis that the internals of R slow down sigFormula significantly. I have observed that, too and switched to generating the signals in my own function. Thanks. |
Custom signal functions will always be faster, as they don't need to parse the whole object, just the information of interest, and you can take care not to make copies. An in-between approach would be to convert to |
Dear all, and thanks to Jasen for inviting me to post my question and a reproducable example here. I am an engineer by education, marketer by profession and R fan for about five years counting.
This is the first attempt at coding a strategy, utilizing a filter for trend direction based on Bollinger Bands and a Stochastic cross over for entry and exit. The strategy is far from complete - I am still learning to code and study specific behaviors of indicators. There is no problem with the code, it does what the code says.
Please note consecutive entry orders on the chart in 2015 March and April with no closing order in between and again in December. I trust that this could happen with any strategy, where exit orders had no signal to activate. What is the quantstrat-way of eliminating this behavior of multiple entries?
The filter is obviously not very responsive, the second order in December occurs after both lower highs and lower lows. Is there a quantstrat way of identifying a trend with higher/lower lows and highs or is that too much charting and not enough technical analysis?
Thanks in advance and kind regards,
Andreas
The text was updated successfully, but these errors were encountered: