Identifying Trapped Traders
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Meesemoo

//@version=4
study("Identifying Trapped Traders")

lookback = input(defval = 10, title = "How many bars lookback?", minval = 2, maxval = 500, type = input.integer)
trading_fees = input(defval = true, title = "Account for Trading fees?", type=input.bool)

fee = 0.0
if trading_fees
    fee := (hl2 * 0.002)

trapped_buyers = 0.0
trapped_sellers = 0.0

for i = 0 to lookback
    if high[i] > (hl2 - fee)
        trapped_buyers := trapped_buyers + (hl2 - high[i])
    
    if low[i] < (hl2 + fee)
        trapped_sellers := trapped_sellers + (hl2 - low[i])
        
plot(trapped_buyers, color = color.red)
plot(trapped_sellers, color = color.green)
plot(0, color = color.black)

fill(plot(0), plot(trapped_buyers, color = color.red), color = color.red, transp = 80)
fill(plot(0), plot(trapped_sellers, color = color.green), color = color.green, transp = 80)