|
Amritendu Maji
2017-07-07 11:55:24
|
|
I am trying to write a simple system that ranks all the stocks in the portfolio based on ROC and then buys the number 1 stock out of a portfolio, when the S&P500 close crosses over its 50 day SMA.
Here is the code. Does it make sense?
Also, it will sell when the reverse happens with the S&P500.
Thank you,
Maji
Optimal_SMATime = 50;
a0 = sma(GetSeries("^GSPC", close), Optimal_SMATime);
b0 = GetSeries("^GSPC", close);
Rule1 = cross(b0, a0);
Optimal_rocTime = 50;
Rule2 = comp(Roc(close,Optimal_rocTime), "rank") == 1;
Rule3 = cross(a0, b0);
buy = Rule1 && Rule2;
sell = Rule3;
|
|