Hello. My idea is to buy stocks, when the closing price is higher than the opening price and the stock is in a range between 10 and 0 zero percent under the All Time High. If I test the following code with the S&P 500 stocks, I get only 117 trades from the year 2000 until 2022. So, I think, that I have done a mistake with the All time high filter. What can I improve that it will work correctly?
HighestValue = Ref(HHV(High,99999),-1);
ATHfiltero90 = C > (HighestValue*0.90);
Buy = C > O AND ATHfiltero90;
Sell = 0;
SL= Optimize("SL", 10, 2, 10, 1); // 10% loss
ApplyStop( stopTypeLoss, stopModePercent, SL, True);
TP = Optimize("TP", 10, 2, 10, 1); // 10% profit
ApplyStop( stopTypeProfit, stopModePercent, TP, True);