Hi Sachin,
1) The short answer is: the resolution is too low.
Here is the real answer: Since we are using daily resolution, the time of daily bar arrives is out of market hour. Therefore, every order is placed when the market is closed, and filled on the next day.
An example would be: On 2018-06-26, the closing price triggers risk management model and submitted an order to liquidate. However, that order is filled on 2018-06-27 with the new closing price on that day. And as it is filled, self.Portfolio.Invested becomes false again and another buy order is placed (and filled immediately). Moreover, although those two orders are filled, the portfolio values (unrealized profit, absolute holding cost) which are involved in the risk management calculation are not updated immediately. In fact, the new values will be effective when the next bar arrives (tomorrow). However, the closing price of 2018-06-27 still triggers risk management and another Liquidate() takes place. This is why you saw both buy and sell on 2018-06-27.
To avoid this: use minute resolution or higher. You would see what you expected: sell when risk management is triggered, and buy back when next bar arrives.
2) The reason is there was no insight triggered. I would recommand to user higher resolution or reduce the period (currently 60). To reduce backtest running time, besides using low resolution, we could also set end date to use less data. For example:
self.SetEndDate(2018, 12, 1)
3) It is a legacy issue and we will fix it soon. Meanwhile, you could use
self.SetBenchmark("SPY")
or select S&P500 benchmark by this:
4) In order to plot the values, I attached the RsiAlphaModel below the original code, and added the plot statement in Update() method. "Strategy equity graph" is our default chart and it's better not to modify it. We could always create a new chart for our own use. Please check for the last session in initialize() for my implementation, and here is our documentation page regarding charting.
Hope it helps.