Can't SellAtClose and BuyAtClose in the same bar
Author: kbellare
Creation Date: 2/21/2016 12:44 PM
profile picture

kbellare

#1
I have a simple strategy which Buys At Close, holds for a month (20 days) and Sells At Close (code below). Problem is the script doesn't execute the BuyAtClose at the same bar as SellAtClose.

To make matters worse, it "thinks" it has bought (i.e. IsLastPositionActive = true after the BuyAtClose command), so it doesn't buy at the next bar either, but skips 20 days and Buys at the next month. As a result my Exposure is only 50% and it's holding cash every alternate month. The Trade tab shows the same outcome.

- How do i make the script BuyAtClose after Selling At Close in the same bar?

CODE:
Please log in to see this code.
profile picture

Eugene

#2
The script is fine. You're having the same issue as in the penultimate thread:

Exposure is less than expected with SetContext, take #2

It's due to some trades being skipped. Take a look at the number of trades not included due to insufficient capital.
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).