Signal and Rule question in Quantstrat

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

Signal and Rule question in Quantstrat

donedge
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!

//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]]

_______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Signal and Rule question in Quantstrat

Joshua Ulrich
On Fri, Jan 23, 2015 at 8:49 AM, Isak Engdahl <[hidden email]> 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.

> //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]]
>
> _______________________________________________
> [hidden email] 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

_______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Signal and Rule question in Quantstrat

Mark Knecht
On Sun, Feb 1, 2015 at 5:48 AM, Joshua Ulrich <[hidden email]> wrote:

> On Fri, Jan 23, 2015 at 8:49 AM, Isak Engdahl <[hidden email]> 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


>> //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]]
>>
>> _______________________________________________
>> [hidden email] 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
>
> _______________________________________________
> [hidden email] 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.

_______________________________________________
[hidden email] 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.
markknecht@gmail.com
Reply | Threaded
Open this post in threaded view
|

Re: Signal and Rule question in Quantstrat

Joshua Ulrich
On Sun, Feb 1, 2015 at 8:20 AM, Mark Knecht <[hidden email]> wrote:

> On Sun, Feb 1, 2015 at 5:48 AM, Joshua Ulrich <[hidden email]> wrote:
>> On Fri, Jan 23, 2015 at 8:49 AM, Isak Engdahl <[hidden email]> 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]]
>>>
>>> _______________________________________________
>>> [hidden email] 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
>>
>> _______________________________________________
>> [hidden email] 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

_______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Signal and Rule question in Quantstrat

Mark Knecht
On Sun, Feb 1, 2015 at 6:31 AM, Joshua Ulrich <[hidden email]> wrote:

> On Sun, Feb 1, 2015 at 8:20 AM, Mark Knecht <[hidden email]> wrote:
>> On Sun, Feb 1, 2015 at 5:48 AM, Joshua Ulrich <[hidden email]> wrote:
>>> On Fri, Jan 23, 2015 at 8:49 AM, Isak Engdahl <[hidden email]> 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.
>

OK, I see your point.

I'll likely go away and be quiet now but without running Isak's code
myself I will say I've been quiet on this list for months now as I
pretty much quit trying to understand how to do what I think is at the
root of Isak's question. (As I read it he's saying 'How to I combine
multiple indicators into a singlerule?') It's not hard in quantstrat
to write indicators, and it's not difficult to create a strategy based
on a single indicator - there are lots of provided examples. However,
as I remember it from months and months ago (I could be wrong, it
might have change, I don't know as I haven't looked) it seemed quite
difficult to turn groups of indicators into executable rules, such as
his entry rule:

PRICE > SMA=250
Slow Stochastic < 20 and crossing above the 20 line

so maybe you can point him to something that addresses just that issue.

For awhile I started creating custom indicator functions outside of
quantstrat such that my 'custom indicator' was pretty much the whole
rule so I didn't have to deal with figuring this out. To me it felt
like it was mostly a documentation/example file question but I got
tired of being a squeeky wheel and stopped working with quantstrat all
together. (I do this trading stuff for fun. To me it wasn't fun. I
bought a MatLab license and I have fun but I keep coming back to R
saying 'Can it be more fun now?')

Anyway, I totally get your point. His code won't run because (I think)
he cannot yet figure out how write a rule using multiple indicators
and in the general case completely inside of quantstrat neither could
I.

FOR CLARITY: I'm not complaining. OpenSource is what it is, it
wouldn't be there without folks like you and the other developers, and
then we user types all make different choices. That's really cool. I'm
only writing this for my own reasons to say why I haven't posted in
months. That said I may be back as my TradeStation/MatLab environment
is working pretty well and I'd like to look at using the R server to
augment things a bit more.

Cheers,
Mark

_______________________________________________
[hidden email] 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.
markknecht@gmail.com
Reply | Threaded
Open this post in threaded view
|

Re: Signal and Rule question in Quantstrat

Ilya Kipnis
Have you all forgotten about my sigAND function?

On Sun, Feb 1, 2015 at 10:12 AM, Mark Knecht <[hidden email]> wrote:

> On Sun, Feb 1, 2015 at 6:31 AM, Joshua Ulrich <[hidden email]>
> wrote:
> > On Sun, Feb 1, 2015 at 8:20 AM, Mark Knecht <[hidden email]>
> wrote:
> >> On Sun, Feb 1, 2015 at 5:48 AM, Joshua Ulrich <[hidden email]>
> wrote:
> >>> On Fri, Jan 23, 2015 at 8:49 AM, Isak Engdahl <[hidden email]>
> 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.
> >
>
> OK, I see your point.
>
> I'll likely go away and be quiet now but without running Isak's code
> myself I will say I've been quiet on this list for months now as I
> pretty much quit trying to understand how to do what I think is at the
> root of Isak's question. (As I read it he's saying 'How to I combine
> multiple indicators into a singlerule?') It's not hard in quantstrat
> to write indicators, and it's not difficult to create a strategy based
> on a single indicator - there are lots of provided examples. However,
> as I remember it from months and months ago (I could be wrong, it
> might have change, I don't know as I haven't looked) it seemed quite
> difficult to turn groups of indicators into executable rules, such as
> his entry rule:
>
> PRICE > SMA=250
> Slow Stochastic < 20 and crossing above the 20 line
>
> so maybe you can point him to something that addresses just that issue.
>
> For awhile I started creating custom indicator functions outside of
> quantstrat such that my 'custom indicator' was pretty much the whole
> rule so I didn't have to deal with figuring this out. To me it felt
> like it was mostly a documentation/example file question but I got
> tired of being a squeeky wheel and stopped working with quantstrat all
> together. (I do this trading stuff for fun. To me it wasn't fun. I
> bought a MatLab license and I have fun but I keep coming back to R
> saying 'Can it be more fun now?')
>
> Anyway, I totally get your point. His code won't run because (I think)
> he cannot yet figure out how write a rule using multiple indicators
> and in the general case completely inside of quantstrat neither could
> I.
>
> FOR CLARITY: I'm not complaining. OpenSource is what it is, it
> wouldn't be there without folks like you and the other developers, and
> then we user types all make different choices. That's really cool. I'm
> only writing this for my own reasons to say why I haven't posted in
> months. That said I may be back as my TradeStation/MatLab environment
> is working pretty well and I'd like to look at using the R server to
> augment things a bit more.
>
> Cheers,
> Mark
>
> _______________________________________________
> [hidden email] 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.
>

        [[alternative HTML version deleted]]

_______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Signal and Rule question in Quantstrat

Joshua Ulrich
On Feb 1, 2015 9:25 AM, "Ilya Kipnis" <[hidden email]> wrote:
>
> Have you all forgotten about my sigAND function?
>
Isak used it. Similar functionality can be achieved with sigFormula.

> On Sun, Feb 1, 2015 at 10:12 AM, Mark Knecht <[hidden email]> wrote:
>>
>> On Sun, Feb 1, 2015 at 6:31 AM, Joshua Ulrich <[hidden email]>
wrote:
>> > On Sun, Feb 1, 2015 at 8:20 AM, Mark Knecht <[hidden email]>
wrote:
>> >> On Sun, Feb 1, 2015 at 5:48 AM, Joshua Ulrich <[hidden email]>
wrote:
>> >>> On Fri, Jan 23, 2015 at 8:49 AM, Isak Engdahl <[hidden email]>
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.
>> >
>>
>> OK, I see your point.
>>
>> I'll likely go away and be quiet now but without running Isak's code
>> myself I will say I've been quiet on this list for months now as I
>> pretty much quit trying to understand how to do what I think is at the
>> root of Isak's question. (As I read it he's saying 'How to I combine
>> multiple indicators into a singlerule?') It's not hard in quantstrat
>> to write indicators, and it's not difficult to create a strategy based
>> on a single indicator - there are lots of provided examples. However,
>> as I remember it from months and months ago (I could be wrong, it
>> might have change, I don't know as I haven't looked) it seemed quite
>> difficult to turn groups of indicators into executable rules, such as
>> his entry rule:
>>
>> PRICE > SMA=250
>> Slow Stochastic < 20 and crossing above the 20 line
>>
>> so maybe you can point him to something that addresses just that issue.
>>
>> For awhile I started creating custom indicator functions outside of
>> quantstrat such that my 'custom indicator' was pretty much the whole
>> rule so I didn't have to deal with figuring this out. To me it felt
>> like it was mostly a documentation/example file question but I got
>> tired of being a squeeky wheel and stopped working with quantstrat all
>> together. (I do this trading stuff for fun. To me it wasn't fun. I
>> bought a MatLab license and I have fun but I keep coming back to R
>> saying 'Can it be more fun now?')
>>
>> Anyway, I totally get your point. His code won't run because (I think)
>> he cannot yet figure out how write a rule using multiple indicators
>> and in the general case completely inside of quantstrat neither could
>> I.
>>
>> FOR CLARITY: I'm not complaining. OpenSource is what it is, it
>> wouldn't be there without folks like you and the other developers, and
>> then we user types all make different choices. That's really cool. I'm
>> only writing this for my own reasons to say why I haven't posted in
>> months. That said I may be back as my TradeStation/MatLab environment
>> is working pretty well and I'd like to look at using the R server to
>> augment things a bit more.
>>
>> Cheers,
>> Mark
>>
>> _______________________________________________
>> [hidden email] 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.
>
>

        [[alternative HTML version deleted]]

_______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Signal and Rule question in Quantstrat

braverock
In reply to this post by Mark Knecht
On 02/01/2015 09:12 AM, Mark Knecht wrote:

> (As I read it he's saying 'How to I combine
> multiple indicators into a singlerule?') It's not hard in quantstrat
> to write indicators, and it's not difficult to create a strategy based
> on a single indicator - there are lots of provided examples. However,
> as I remember it from months and months ago (I could be wrong, it
> might have change, I don't know as I haven't looked) it seemed quite
> difficult to turn groups of indicators into executable rules, such as
> his entry rule:
>
> PRICE > SMA=250
> Slow Stochastic < 20 and crossing above the 20 line
>
> so maybe you can point him to something that addresses just that issue.

I think that this may make more sense if restated a bit

Multiple indicators have been defined, let's say that their labels are
set as:

pc.gt.sma250 # for PRICE > SMA=250
stoch.lt.20 # Slow Stochastic < 20
stock.cross.20 # Slow Stochastic crossing above the 20 line

First, I'm not sure how condition Slow Stochastic < 20 and condition
Slow Stochastic crossing above the 20 line can both be true. Let's skip
that for now.

I believe that what you would be looking for is a sigFormula *signal*.
The rule will likely be ruleSignal, as usual.

The formula argument for sigFormula in the above case might be stated:

formula='pc.gt.sma250 && stock.lt.20 && stoch.cross.20'

The rest of the strategy should be pretty straightforward stuff, only
the sigFormula bit seems to confuse people.

If I have time in the next several days, I'll try to create a demo that
does this (or we would gladly accept a demo from someone else that does
this).

Regards,

Brian


--
Brian G. Peterson
http://braverock.com/brian/
Ph: 773-459-4973
IM: bgpbraverock

_______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Signal and Rule question in Quantstrat

donedge
In reply to this post by Ilya Kipnis
Dear all,

Yes i'm trying to use function SigAnd, but I think I have the logic wrong...

Here are the rules:
1. Price > SMA 250
2. Stochastic signal line must be below 20 and cross above this level. Then
buy.

How do I write such a rule in quantstrat?

Kind Regards,
Isak Engdahl



On Sunday, February 1, 2015, Ilya Kipnis <[hidden email]> wrote:

> Have you all forgotten about my sigAND function?
>
> On Sun, Feb 1, 2015 at 10:12 AM, Mark Knecht <[hidden email]
> <javascript:_e(%7B%7D,'cvml','[hidden email]');>> wrote:
>
>> On Sun, Feb 1, 2015 at 6:31 AM, Joshua Ulrich <[hidden email]
>> <javascript:_e(%7B%7D,'cvml','[hidden email]');>> wrote:
>> > On Sun, Feb 1, 2015 at 8:20 AM, Mark Knecht <[hidden email]
>> <javascript:_e(%7B%7D,'cvml','[hidden email]');>> wrote:
>> >> On Sun, Feb 1, 2015 at 5:48 AM, Joshua Ulrich <[hidden email]
>> <javascript:_e(%7B%7D,'cvml','[hidden email]');>> wrote:
>> >>> On Fri, Jan 23, 2015 at 8:49 AM, Isak Engdahl <[hidden email]
>> <javascript:_e(%7B%7D,'cvml','[hidden email]');>> 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.
>> >
>>
>> OK, I see your point.
>>
>> I'll likely go away and be quiet now but without running Isak's code
>> myself I will say I've been quiet on this list for months now as I
>> pretty much quit trying to understand how to do what I think is at the
>> root of Isak's question. (As I read it he's saying 'How to I combine
>> multiple indicators into a singlerule?') It's not hard in quantstrat
>> to write indicators, and it's not difficult to create a strategy based
>> on a single indicator - there are lots of provided examples. However,
>> as I remember it from months and months ago (I could be wrong, it
>> might have change, I don't know as I haven't looked) it seemed quite
>> difficult to turn groups of indicators into executable rules, such as
>> his entry rule:
>>
>> PRICE > SMA=250
>> Slow Stochastic < 20 and crossing above the 20 line
>>
>> so maybe you can point him to something that addresses just that issue.
>>
>> For awhile I started creating custom indicator functions outside of
>> quantstrat such that my 'custom indicator' was pretty much the whole
>> rule so I didn't have to deal with figuring this out. To me it felt
>> like it was mostly a documentation/example file question but I got
>> tired of being a squeeky wheel and stopped working with quantstrat all
>> together. (I do this trading stuff for fun. To me it wasn't fun. I
>> bought a MatLab license and I have fun but I keep coming back to R
>> saying 'Can it be more fun now?')
>>
>> Anyway, I totally get your point. His code won't run because (I think)
>> he cannot yet figure out how write a rule using multiple indicators
>> and in the general case completely inside of quantstrat neither could
>> I.
>>
>> FOR CLARITY: I'm not complaining. OpenSource is what it is, it
>> wouldn't be there without folks like you and the other developers, and
>> then we user types all make different choices. That's really cool. I'm
>> only writing this for my own reasons to say why I haven't posted in
>> months. That said I may be back as my TradeStation/MatLab environment
>> is working pretty well and I'd like to look at using the R server to
>> augment things a bit more.
>>
>> Cheers,
>> Mark
>>
>> _______________________________________________
>> [hidden email]
>> <javascript:_e(%7B%7D,'cvml','[hidden email]');> 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.
>>
>
>

--


Kind Regards
Isak Engdahl

        [[alternative HTML version deleted]]

_______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: Signal and Rule question in Quantstrat

Ilya Kipnis
sigComparison for price > SMA250. sigThreshold with stochastic with cross =
FALSE
sigAND with cross = TRUE

See some of my old posts on my blog.

On Sun, Feb 1, 2015 at 5:25 PM, Isak Engdahl <[hidden email]> wrote:

> Dear all,
>
> Yes i'm trying to use function SigAnd, but I think I have the logic
> wrong...
>
> Here are the rules:
> 1. Price > SMA 250
> 2. Stochastic signal line must be below 20 and cross above this level.
> Then buy.
>
> How do I write such a rule in quantstrat?
>
> Kind Regards,
> Isak Engdahl
>
>
>
> On Sunday, February 1, 2015, Ilya Kipnis <[hidden email]> wrote:
>
>> Have you all forgotten about my sigAND function?
>>
>> On Sun, Feb 1, 2015 at 10:12 AM, Mark Knecht <[hidden email]>
>> wrote:
>>
>>> On Sun, Feb 1, 2015 at 6:31 AM, Joshua Ulrich <[hidden email]>
>>> wrote:
>>> > On Sun, Feb 1, 2015 at 8:20 AM, Mark Knecht <[hidden email]>
>>> wrote:
>>> >> On Sun, Feb 1, 2015 at 5:48 AM, Joshua Ulrich <
>>> [hidden email]> wrote:
>>> >>> On Fri, Jan 23, 2015 at 8:49 AM, Isak Engdahl <
>>> [hidden email]> 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.
>>> >
>>>
>>> OK, I see your point.
>>>
>>> I'll likely go away and be quiet now but without running Isak's code
>>> myself I will say I've been quiet on this list for months now as I
>>> pretty much quit trying to understand how to do what I think is at the
>>> root of Isak's question. (As I read it he's saying 'How to I combine
>>> multiple indicators into a singlerule?') It's not hard in quantstrat
>>> to write indicators, and it's not difficult to create a strategy based
>>> on a single indicator - there are lots of provided examples. However,
>>> as I remember it from months and months ago (I could be wrong, it
>>> might have change, I don't know as I haven't looked) it seemed quite
>>> difficult to turn groups of indicators into executable rules, such as
>>> his entry rule:
>>>
>>> PRICE > SMA=250
>>> Slow Stochastic < 20 and crossing above the 20 line
>>>
>>> so maybe you can point him to something that addresses just that issue.
>>>
>>> For awhile I started creating custom indicator functions outside of
>>> quantstrat such that my 'custom indicator' was pretty much the whole
>>> rule so I didn't have to deal with figuring this out. To me it felt
>>> like it was mostly a documentation/example file question but I got
>>> tired of being a squeeky wheel and stopped working with quantstrat all
>>> together. (I do this trading stuff for fun. To me it wasn't fun. I
>>> bought a MatLab license and I have fun but I keep coming back to R
>>> saying 'Can it be more fun now?')
>>>
>>> Anyway, I totally get your point. His code won't run because (I think)
>>> he cannot yet figure out how write a rule using multiple indicators
>>> and in the general case completely inside of quantstrat neither could
>>> I.
>>>
>>> FOR CLARITY: I'm not complaining. OpenSource is what it is, it
>>> wouldn't be there without folks like you and the other developers, and
>>> then we user types all make different choices. That's really cool. I'm
>>> only writing this for my own reasons to say why I haven't posted in
>>> months. That said I may be back as my TradeStation/MatLab environment
>>> is working pretty well and I'd like to look at using the R server to
>>> augment things a bit more.
>>>
>>> Cheers,
>>> Mark
>>>
>>> _______________________________________________
>>> [hidden email] 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.
>>>
>>
>>
>
> --
>
>
> Kind Regards
> Isak Engdahl
>
>

        [[alternative HTML version deleted]]

_______________________________________________
[hidden email] 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.