Repository: QuantConnect/Lean

Issue #2853: RenkoBar Consolidator not functioning as expected
Created: 2019-01-23T00:13:09Z
Expected Behavior
Consolidator will build bars at appropriate intervals according to the argument passed to RenkoConsolidator(10) -- in this case, $10.
Actual Behavior
Despite a number of occasions where there is a $10 difference, the consolidator fails to build bars until late in the time series -- that is, there are instances where the stock price fluctuates around $121 when it's starting price was around $111.
Potential Solution
Examine and update the behavior of the Renko Consolidator.
Reproducing the Problem
This code will reproduce the problem and show a RenkoBar plot overlaid with an asset price plot.
def Initialize(self):

        self.SetStartDate(2012,1, 1)  #Set Start Date
        self.SetEndDate(2013,1,1)    #Set End Date
        self.SetCash(100000)           #Set Strategy Cash

        self.AddEquity("SPY", Resolution.Hour)
        renko_bar = RenkoConsolidator(10)
        renko_bar.DataConsolidated += self.OnDataConsolidated
        self.SubscriptionManager.AddConsolidator('SPY', renko_bar)
        
        renko_plot = Chart('Renko')
        renko_plot.AddSeries(Series('Renko Bar', SeriesType.Bar, 4))
        renko_plot.AddSeries(Series('Stock', SeriesType.Bar, 0))        
    
    def OnData(self, data):
        
        if data.Dividends.ContainsKey('SPY'):
            return
        self.Plot('Renko', 'Stock', data['SPY'].Close)
        self.Log(str(self.Time) + '   SPY Ceiling: $' + str(np.ceil(data['SPY'].Close)))
        self.Log(str(self.Time) + '   SPY Floor: $' + str(np.floor(data['SPY'].Close)))
            
    def OnDataConsolidated(self, sender ,bar):
        self.Plot('Renko', 'Renko Bar', bar.Close)
        self.Log(str(self.Time) + '   Renko Bar: $' + str(bar.Close))

Checklist

 I have completely filled out this template
 I have confirmed that this issue exists on the current master branch
 I have confirmed that this is not a duplicate issue by searching issues
 I have provided detailed steps to reproduce the issue

Duplicate issue #4841: RenkoBar printing incorrect bar on price reversal
Created: 2020-10-11T21:30:07Z
Expected Behavior
We are considering Renko charts. Let a bar size B.
Let a rising bar with an opening price of Y and a closing price of Y+B.
Let the next bar be a falling bar.
The latter bar will have an opening price of Y and closing price of Y-B.
Let a falling bar with an opening price of Y and a closing price of Y-B
Let the next bar be a rising bar.
The latter bar will have an opening price of Y and closing price of Y+B.
see an example chart on wikipedia
Actual Behavior
Let a rising bar with an opening price of Y and a closing price of Y+B.
Let the next bar be a falling bar.
The latter bar will have an opening price of Y+B and a closing price of Y.
Let a falling bar with an opening price of Y and a closing price of Y-B
Let the next bar be a rising bar.
The latter bar will have an opening price of Y-B and closing price of Y.
Potential Solution
Direction of the previous Renko bar must be considered to set the limits of the next bar.
If the last consolidated Renko bar was rising, then the bar being consolidated must have an upper limit UL of
UL =  open + bar size,
and a lower limit LL of
LL = open - 2*bar size
If the last consolidated Renko bar was falling, then the bar being consolidated must have an upper limit UL of
UL =  open + 2*bar size,
and a lower limit LL of
LL = open - bar size
Reproducing the Problem
class RenkoConsolidatorAlgorithm(QCAlgorithm):
    def Initialize(self):
        self.SetStartDate(2012, 1, 1)
        self.SetEndDate(2012, 2, 1)
        self.AddForex("EURUSD", Resolution.Minute, Market.FXCM)
        renkoClose = RenkoConsolidator(0.003)
        renkoClose.DataConsolidated += self.HandleRenkoClose
        self.SubscriptionManager.AddConsolidator("EURUSD", renkoClose)

    def OnData(self, data):
        pass

    def HandleRenkoClose(self, sender, data):
        self.Log(f"open: {data.Open} close: {data.Close} direction: {data.Direction}")


System Information
online platform https://www.quantconnect.com/terminal/
Checklist

 I have completely filled out this template
 I have confirmed that this issue exists on the current master branch
 I have confirmed that this is not a duplicate issue by searching issues
 I have provided detailed steps to reproduce the issue

Closing comment (2021-01-11T19:33:02Z): Potential duplicate of #2853