tradingalgorithmic-tradingquantstrat

Quantstrat: sell at next bar (custom)


I am working on modifying the built-in functions in quantstrat which are related to stop-limits. I want to test a system which sells only when closing price is below the stoplimit. I was able to change the comparison data so it sells when close < stoplimit.

However, the sale transaction occurs on the same day that the close triggers the sale. This is a problem I'm working on.

How to change this code to sell on the next day?

 if(orderType == 'stoplimit')
                         txnprice <- min(orderPrice, Op(mktdataTimestamp)[,1])
                     else
                         txnprice <- orderPrice
                     txntime = timestamp

Solution

  • Here's the code I used to control order price:

    txnprice = try(getPrice(x=mktdata[curIndex+1L], prefer=prefer)[,1])
    

    The +1L adds a day before the getPrice acts on the curIndex. This is nice because it also takes prefer.

    I haven't figured out how to change txntime to the next market day. I can just delay it a day:

    txntime = timestamp+1