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

Isak Engdahl isak.engdahl at gmail.com
Sun Feb 1 23:25:32 CET 2015


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 <ilya.kipnis at gmail.com> wrote:

> Have you all forgotten about my sigAND function?
>
> On Sun, Feb 1, 2015 at 10:12 AM, Mark Knecht <markknecht at gmail.com
> <javascript:_e(%7B%7D,'cvml','markknecht at gmail.com');>> wrote:
>
>> On Sun, Feb 1, 2015 at 6:31 AM, Joshua Ulrich <josh.m.ulrich at gmail.com
>> <javascript:_e(%7B%7D,'cvml','josh.m.ulrich at gmail.com');>> wrote:
>> > On Sun, Feb 1, 2015 at 8:20 AM, Mark Knecht <markknecht at gmail.com
>> <javascript:_e(%7B%7D,'cvml','markknecht at gmail.com');>> wrote:
>> >> On Sun, Feb 1, 2015 at 5:48 AM, Joshua Ulrich <josh.m.ulrich at gmail.com
>> <javascript:_e(%7B%7D,'cvml','josh.m.ulrich at gmail.com');>> wrote:
>> >>> On Fri, Jan 23, 2015 at 8:49 AM, Isak Engdahl <isak.engdahl at gmail.com
>> <javascript:_e(%7B%7D,'cvml','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.
>> >
>>
>> 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
>>
>> _______________________________________________
>> R-SIG-Finance at r-project.org
>> <javascript:_e(%7B%7D,'cvml','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.
>>
>
>

-- 


Kind Regards
Isak Engdahl

	[[alternative HTML version deleted]]



More information about the R-SIG-Finance mailing list