November 2019
Beginner
394 pages
10h 31m
English
Now, let's implement and plot a relative strength indicator on our dataset:
import statistics as statstime_period = 20 # look back period to compute gains & lossesgain_history = [] # history of gains over look back period (0 if no gain, magnitude of gain if gain)loss_history = [] # history of losses over look back period (0 if no loss, magnitude of loss if loss)avg_gain_values = [] # track avg gains for visualization purposesavg_loss_values = [] # track avg losses for visualization purposesrsi_values = [] # track computed RSI valueslast_price = 0 # current_price - last_price > 0 => gain. current_price - last_price < 0 => loss.for close_price in close: if last_price == 0: last_price = close_price ...