Hi

I thought I had found a solution to this by adding the signal:

add.signal(strategy.st, name="sigFormula",
    arguments = list(columns = c("longEntry"),
    formula = "lag(longEntry, 8) == 1", cross=FALSE), label="fixedExit")


and a new rule:

add.rule(strategy.st, name = "ruleSignal",
    arguments = list(sigcol = "fixedExit",
    sigval = TRUE,
    orderqty = "all",
    ordertype = "market",
    orderside = "long", TxnFees = txnFees,
    replace = FALSE,
    prefer = "Open"), type= "exit", path.dep = TRUE)

I placed the rule before the old exit one assuming it would then take precedent and because the rule was a sell all one it would do no harm for the other rule to trigger as all = 0 at that stage.

It made a difference but I was not sure if it was working properly (ie sell either when the normal sale is triggered or on 8 days whichever is the earlier). So I temporarily removed the old longExit signal and associated rule. That should have mean that I only got sales on the 8th trading day after a purchase but this showed up in the order book:

Order.Qty Order.Price Order.Type Order.Side Order.Threshold Order.Status Order.StatusTime Prefer Order.Set Txn.Fees Rule Time.In.Force 2003-08-07 "3261" "2.92237690558407" "market" "long" NA "closed" "2003-08-08 00:00:00" "Open" NA "-8" "ruleSignal.rule" "" 2003-08-19 "all" "2.95346608774812" "market" "long" NA "closed" "2003-08-20 00:00:00" "Open" NA "-8" "ruleSignal.rule" "" 2003-11-11 "3073" "3.92345478910284" "market" "long" NA "closed" "2003-11-12 00:00:00" "Open" NA "-8" "ruleSignal.rule" "" 2003-11-21 "all" "3.66852349535765" "market" "long" NA "closed" "2003-11-24 00:00:00" "Open" NA "-8" "ruleSignal.rule" "" 2003-12-10 "2638" "3.46333489307494" "market" "long" NA "closed" "2003-12-11 00:00:00" "Open" NA "-8" "ruleSignal.rule" "" 2003-12-22 "all" "3.01565066991264" "market" "long" NA "closed" "2003-12-23 00:00:00" "Open" NA "-8" "ruleSignal.rule" "" 2004-01-13 "3591" "3.07782903424074" "market" "long" NA "closed" "2004-01-14 00:00:00" "Open" NA "-8" "ruleSignal.rule" "" 2004-01-23 "all" "2.9223831234205" "market" "long" NA "closed" "2004-01-26 00:00:00" "Open" NA "-8" "ruleSignal.rule" "" 2004-01-28 "3603" "2.76693721260026" "market" "long" NA "closed" "2004-01-29 00:00:00" "Open" NA "-8" "ruleSignal.rule" "" 2004-01-30 "all" "2.81046206762993" "market" "long" NA "closed" "2004-02-02 00:00:00" "Open" NA "-8" "ruleSignal.rule" "" Please note the last line shows a purchase and sale only two calendar days apart. They were weekdays. That is not in accordance with the indicator or rule I wrote. In fact mktdata shows:

2004-01-28                 1         0         1         0
2004-01-29                 0         0         0         0
2004-01-30                 0         0         0         0
2004-02-02                 0         0         0         0
2004-02-03                 0         0         0         0
2004-02-04                 0         0         0         0
2004-02-05                 0         0         0         0
2004-02-06                 0         0         0         0
2004-02-09                 0         0         0         1

with the signals on the correct days.

Just a sanity check. Can anyone tell me where I am going wrong, presumably in writing that rule.

-----------------------------------------------------------------------------------------------------------------------------------
Stephen Choularton PhD, FIoD

On 27/05/2016 4:43 PM, Stephen Choularton wrote:
Hi

I am trying to implement Harry's Connor's RSI from his book Quantative Trading ...

I have it working as is and have varied it to some shares in the ASX.

However, I want to pursue the idea of a fixed time (8 day) sell rule that takes place if the normal rule doesn't produce a sale before.

I added this rule at line 127 of the file 3. strategy.R:

add.rule(strategy.st, name = "ruleSignal",
    arguments = list(sigcol = "longExit",
    sigval = TRUE,
    orderqty = "all", delay = 691200,
    ordertype = "market",
    orderside = "long", TxnFees = txnFees,
    replace = FALSE,
    prefer = "Open"), type= "exit", path.dep = TRUE)

but it seems to have no effect.

I attach all the code. You run it in the numbered order of the files.

I wonder if anyone can help me make this sort of rule work.

-----------------------------------------------------------------------------------------------------------------------------------
Stephen Choularton PhD, FIoD
0413 545 182

_______________________________________________
R-SIG-Finance@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.

Reply via email to