Hi guys,
I have a problem regarding the coding for a trailing stop set at 1% from the security’s high (which obviously changes during the day depending on the high). When I had a look at the forum I found some posts about trailing stops, so I had a look and tried to incorporate them into my idea (just buy those three securities that have the highest MACD). I am restricting myself to the ‘Q1500US’ dataset.
Basically, there are two algorithms that I am presenting here, the only difference between them lying in line 74 and 75. The first algorithm I post here uses line 75 (instead of 74) and the result is that all securities that are bought during a day are held until 10pm (despite the selling condition of the trailing stop). The second algorithm uses line 74 and the result here is that the trailing stop works for one security but not for the other 2 securities (if 3 securities are bought at all).
Hence, I have the following questions:
1. Why is on some days only one security bought? Does that have to do with pipeline screening among all securities and choosing the top 3 MACD among those, while my filter puts another constraint (Q1500US) on there so that in the end only those in the top 3 MACD of all securities AND those in Q1500US are included? How can I change the coding so that the top 3 MACD securities from US1500 are chosen?
2. With regards to the first algorithm, why doesn’t it sell before 10pm?
3. With regards to the second algorithm, why does the trailing stop only works for one security in the portfolio but not for all of them?