In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in a publication is governed by House Rules. You can favorite it to use it on a chart.
study(title="trade by two-bars", shorttitle="by2bars", overlay=true) data = (close>open) == (close>open) dir = close < close correct = (close < close) == (open<close) plotshape(data and dir, color=lime, style=shape.arrowup, text="Buy", location=location.abovebar ) plotshape(data and not dir, color=red, style=shape.arrowdown, text="Sell", location=location.belowbar) barcolor(data and correct?yellow:(data?black:na)) yellow_bars = (data and correct) black_bars = -(data and not correct) plot(yellow_bars,"success",green,8,histogram) plot(black_bars,"failure",red,8,histogram) yellow_bars_so_far = cum(yellow_bars) black_bars_so_far = cum(black_bars) total_revenue = yellow_bars_so_far + black_bars_so_far plot(total_revenue,"total revenue",blue)