[R-SIG-Finance] Signal and Rule question in Quantstrat

Joshua Ulrich josh.m.ulrich at gmail.com
Sun Feb 1 15:31:55 CET 2015


On Sun, Feb 1, 2015 at 8:20 AM, Mark Knecht <markknecht at gmail.com> wrote:
> On Sun, Feb 1, 2015 at 5:48 AM, Joshua Ulrich <josh.m.ulrich at gmail.com> wrote:
>> On Fri, Jan 23, 2015 at 8:49 AM, Isak Engdahl <isak.engdahl at gmail.com> wrote:
>>> Dear members,
>>>
>>> I have a questions how to set up the signals and rules correct for this
>>> stategy in Quantstrat.
>>>
>>> Price must be above SMA=250 and below the 20 line in the Slow Stochastic
>>> indicator.
>>>
>>> The trigger for a buy signal is when the signal line of the stochastic
>>> indicator close above the 20 line.
>>>
>>> Enter trade
>>> PRICE > SMA=250
>>> Slow Stochastic < 20 and crossing above the 20 line
>>>
>>> Exit trade
>>> PRICE < SMA=250
>>> Slow Stoch > 80 and closes below the 80 line
>>>
>>> The rules and examples can be found here:
>>> http://stockcharts.com/public/1107832
>>>
>>> Here is the code I have come up with now. Please help!
>>>
>> Help with what?  You haven't stated any problem.
>>
>
> Joshua,
>    I think Isak provided code and asked if it works, or what he has to
> do to make it work. It didn't seem a wholly unreasonable question. (to
> me...)
> Mark
>
I don't know how to answer "does this code work?"  It doesn't do much.
It just defines a strategy, some indicators, signals, and rules.  I'm
not suggesting it's a wholly unreasonable question; but I doubt it's
going to result in anyone providing help to Isak.

I suspect most people are not going to take the time to run this
strategy, then ensure he set it up correctly, and make any necessary
fixes.  In short, Isak needs to put in more effort and come back when
he has a more specific question.

>
>>> //Isak
>>>
>>> #parameters
>>> nFastK <- 5
>>> nSlowD <- 1
>>> nSMA <- 250
>>> buyThresh <- 20
>>> sellThresh <- 80
>>>
>>> ######################################################################################
>>> #indicator
>>> add.indicator(strategy.st, name="stoch",
>>>               arguments=list(HLC=quote(HLC(mktdata)), nFastK=nFastK,
>>> nSlowD=nSlowD),
>>>               label="stoch")
>>>
>>> add.indicator(strategy.st, name="SMA",
>>>               arguments=list(x=quote(Cl(mktdata)), n=nSMA),
>>>               label="sma")
>>> ###############################################################################
>>> #signals
>>> add.signal(strategy.st, name="sigComparison",
>>>            arguments=list(columns=c("Close", "sma"), relationship="gt"),
>>>            label="filter")
>>>
>>> add.signal(strategy.st, name="sigThreshold",
>>>            arguments=list(column="stoch", threshold=buyThresh,
>>>                           relationship="lt", cross=FALSE),
>>>            label="stochLtThresh")
>>>
>>> add.signal(strategy.st, name="sigAND",
>>>            arguments=list(columns=c("filter", "stochLtThresh"), cross=TRUE),
>>>            label="longEntry")
>>> add.signal(strategy.st, name="sigThreshold",
>>>            arguments=list(column="stoch", threshold=sellThresh,
>>>                           relationship="gt", cross=TRUE),
>>>            label="longExit")
>>> ###############################################################################
>>> #rules
>>>
>>> #Long entry rule
>>> add.rule(strategy.st, name="ruleSignal",
>>>          arguments=list(sigcol="longEntry",
>>>                         sigval=TRUE,
>>>                         replace=FALSE,
>>>                         orderside="long",
>>>                         ordertype="market",
>>>                         orderqty=100,
>>>                         osFUN="osFixedDollar",
>>>                         orderset="ocolong"),
>>>          type="enter",label="LE")
>>>
>>> #Long exit rule
>>> add.rule(strategy.st, name="ruleSignal",
>>>          arguments=list(sigcol="longExit",
>>>                         sigval=TRUE,
>>>                         replace=FALSE,
>>>                         orderside="long",
>>>                         ordertype="market",
>>>                         orderqty="all",
>>>                         orderset="ocolong"),
>>>          type="exit",label="LX")
>>>
>>>         [[alternative HTML version deleted]]
>>>
>>> _______________________________________________
>>> R-SIG-Finance at r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
>>> -- Subscriber-posting only. If you want to post, subscribe first.
>>> -- Also note that this is not the r-help list where general R questions should go.
>>
>>
>>
>> --
>> Joshua Ulrich  |  about.me/joshuaulrich
>> FOSS Trading  |  www.fosstrading.com
>>
>> _______________________________________________
>> R-SIG-Finance at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
>> -- Subscriber-posting only. If you want to post, subscribe first.
>> -- Also note that this is not the r-help list where general R questions should go.



-- 
Joshua Ulrich  |  about.me/joshuaulrich
FOSS Trading  |  www.fosstrading.com



More information about the R-SIG-Finance mailing list