How to prevent Expert advisor from picking the dynamic values of RSI instead of OHLC values during live market?

HI,

I backtested a script based on MACD crossover and RSI OHLC values. In backtest, only OHLC values of RSI were considered and the success rate was >65%. But when i tested the same script in live market the results were different. Instead of picking the RSI value at the end of a 1 min candlestick chart it was picking the dynamic RSI value which changes multiple times within 1 min timeframe.

How to rectify this? how to write a script so that only the RSI value at the end of 1 min candlestick will be picked?

Script which i used:

BUY when: 

SET A = MACD(13, 26, 9,EXPONENTIAL)
SET B = MACDSIGNAL(13, 26, 9, EXPONENTIAL)
CROSSOVER(A,B) = TRUE AND RSI (CLOSE,14)<=50

SELL when:

RSI (CLOSE,14)>60

replace CLOSE with REF(CLOSE,1)