@Kory, thank you very much for your kind explanation. I would like to do through investigation before throwing real money into it.
Now I add below log to follow the buy/sell decision maker after your RSI calculation:
log.info("Current XIV price %.2f @ RSI_2 level %d, previous %d, %d and RSI_7 level %d, previous %d, %d" %(data.current(context.XIV, 'price'), rsi[-1], rsi[-2], rsi[-3], rsi7[-1], rsi7[-2], rsi7[-3]))
I find that sometimes the rsi[-2] of current my_rebalance schedule does not match the rsi[-1] of last schedule. And in a few cases it impacts the buy/sell criteria. See below example:
2017-01-04 12:59 my_rebalance:142 INFO Current XIV price 52.84 @ RSI_2 level 87, previous 99, 99 and RSI_7 level 93, previous 95, 94
2017-01-05 08:29 my_rebalance:142 INFO Current XIV price 52.17 @ RSI_2 level 36, previous 84, 99 and RSI_7 level 84, previous 96, 98
At 12:59 the RSI is 87, and at 8:29 the following day the RSI drops to 36. By algorithm I should sell XIV, however because the RSI[-2] read is 84 rather than 87, now I end up not selling XIV.
That puzzles me what causes the data mismatch?