My current strategy is as such, i try to buy the top 3 performing sectors in the watchlist X (having xle, spy, xlk, gld etc etc inside) by way of seeing which has the highest gain. my code is as such
//Ranking criteria (Highest % gain in the week)
Gain=100*((Close-Open)/Open);
//Ranking
PositionScore = Gain;
Buy = PositionScore<4; // chose the top 3 highest gain tickers in the watchlist X
Sell = PositionScore>5; // sell those that fall out from the top 5
Now, i wish to take it a step further. instead of buying the tickers in the watchlist, which are all funds. i plan to buy the best performing stock in the fund instead of the fund itself.
For example, the best performing fund in watchlist X is xle, so i wish to buy the best perfoming stock in the xle fund (made up of slb, eog, cop, mpc, pxd etc), say PXD.
I have already created each fund's watchlist so XLE has a watchlist that contains all the stocks making up XLE.
However, i do not know how to code the portion of selecting the best performing stock in the XLE watchlist.
// code that will map each fund to its watchlist number.
wlistIndex = // assign the watchlist index here
list_symbols = CATEGORYGETSYMBOLS(categoryWatchlist, wlistIndex, 0);
then scroll down in the same manual page, you can see FOR loop to iterate over all the symbols and perform simple ranking by comparing and storing the better symbol in a variable.
Thanks nsm51, but how will the program know which watchlist to look into to get the stocks? for example, xle, xlf, xlv came up the top 3 among the watchlist X, how will the system know to look into xle, xlf, xlv?
i tried to 'extract' the #1, #2, #3 in the positionscore ranking and then try to get the program to look into the watchlist but failed. code is below