Untitled
//@version=5 indicator(title="Adem Baba OBVM with Weighted Average Ratio", shorttitle="Adem Baba OBVM WAR", format=format.volume, timeframe="", timeframe_gaps=true) // === Temel Değişkenler === src = close var cumVol = 0. cumVol += nz(volume) if barstate.islast and cumVol == 0 runtime.error("No volume is provided by the data vendor.") // === Body Ratio Hesabı === gap_size = math.abs(open - close[1]) gapAdjustedBody = math.abs(close - open + gap_size) totalRange = high - low + gap_size bodyRatio = totalRange != 0 ? gapAdjustedBody / totalRange : 0 // === Close Position Ratio Hesabı === closePosRatio = totalRange != 0 ? math.abs((2 * close - low - high) / (high - low)) : 0 // === Kullanıcı Tanımlı Ağırlıklar === bodyWeight = input.float(0.7, title="Body Ratio Weight", minval=0, maxval=1, step=0.1, group="Weighted Average Settings") closePosWeight = input.float(0.3, title="Close Position Ratio Weight", minval=0, maxval=1, step=0.1, group="Weighted Average Settings") // === Ağırlık Toplamı Kontrolü === if bodyWeight + closePosWeight != 1 runtime.error("Body Ratio Weight and Close Position Ratio Weight must sum up to 1!") // === Ortalama Hesaplama === averageRatio = bodyWeight * bodyRatio + closePosWeight * closePosRatio // === Filtrelenmiş Hacim === filteredVolume = volume * averageRatio // === Geliştirilmiş OBV Hesaplaması === obv = ta.cum(math.sign(ta.change(src) != 0 ? ta.change(src) : 1) * filteredVolume) // === OBV Grafiği === plot(obv, color=#2962FF, title="Enhanced OBVM with Weighted Average Ratio") // === Moving Average Inputs === GRP1 = "Moving Average 1" ma1TypeInput = input.string("SMA", "Type", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group=GRP1, display=display.data_window) ma1LengthInput = input.int(5, "Length", minval=3, group=GRP1, display=display.data_window) ma1ColorInput = input.color(color.yellow, "Color", group=GRP1, display=display.data_window) ma1DisplayInput = input.bool(true, "Display MA", group=GRP1, display=display.data_window) GRP2 = "Moving Average 2" ma2TypeInput = input.string("EMA", "Type", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group=GRP2, display=display.data_window) ma2LengthInput = input.int(22, "Length", minval=3, group=GRP2, display=display.data_window) ma2ColorInput = input.color(color.orange, "Color", group=GRP2, display=display.data_window) ma2DisplayInput = input.bool(true, "Display MA", group=GRP2, display=display.data_window) GRP3 = "Moving Average 3" ma3TypeInput = input.string("WMA", "Type", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group=GRP3, display=display.data_window) ma3LengthInput = input.int(200, "Length", minval=3, group=GRP3, display=display.data_window) ma3ColorInput = input.color(color.purple, "Color", group=GRP3, display=display.data_window) ma3DisplayInput = input.bool(true, "Display MA", group=GRP3, display=display.data_window) // === Moving Average Calculation === ma(source, length, MAtype) => switch MAtype "SMA" => ta.sma(source, length) "EMA" => ta.ema(source, length) "SMMA (RMA)" => ta.rma(source, length) "WMA" => ta.wma(source, length) "VWMA" => ta.vwma(source, length) // === Moving Average plots === ma1 = ma1DisplayInput ? ma(obv, ma1LengthInput, ma1TypeInput) : na ma2 = ma2DisplayInput ? ma(obv, ma2LengthInput, ma2TypeInput) : na ma3 = ma3DisplayInput ? ma(obv, ma3LengthInput, ma3TypeInput) : na plot(ma1, "MA 1", color=ma1ColorInput, display=ma1DisplayInput ? display.all : display.none) plot(ma2, "MA 2", color=ma2ColorInput, display=ma2DisplayInput ? display.all : display.none) plot(ma3, "MA 3", color=ma3ColorInput, display=ma3DisplayInput ? display.all : display.none)
Leave a Comment