gogo2/Niki/niki-refactored.pine

86 lines
3.2 KiB
Plaintext

//@version=5
indicator("DrNiki's Market Nuker", shorttitle="DrNiki's Market Nuker", overlay=true)
// Function to calculate RSI
rsiLength = input(14, title="RSI Length")
calcRSI() => ta.rsi(close, rsiLength)
// Function to calculate Stochastic RSI
stochRsiLength = input(14, title="Stochastic RSI Length")
calcStochRSI() => ta.stoch(close, close, close, stochRsiLength)
// Function to calculate Wavetrend
n1 = input(10, "Channel Length")
n2 = input(21, "Average Length")
calcWavetrend() =>
ap = hlc3
esa = ta.ema(ap, n1)
d = ta.ema(math.abs(ap - esa), n1)
ci = (ap - esa) / (0.015 * d)
tci = ta.ema(ci, n2)
wt1 = tci
wt2 = ta.sma(wt1, 4)
[wt1, wt2]
// Function to calculate On Balance Volume (OBV)
calcOBV() =>
var float obv = na
obv := close > close[1] ? obv + volume : close < close[1] ? obv - volume : obv
obv
// Function to calculate MFI
mfiLength = input(7, title="MFI Length")
calcMFI() => ta.mfi(close, mfiLength)
// Function to calculate points for a symbol
calcPoints(symbol) =>
rsiValue = calcRSI()
stochRsiValue = calcStochRSI()
[wt1, wt2] = calcWavetrend()
obv = calcOBV()
mfiValue = calcMFI()
longPoints = 0
shortPoints = 0
longPoints := rsiValue > rsiValue[1] ? longPoints + 1 : longPoints
shortPoints := rsiValue < rsiValue[1] ? shortPoints + 1 : shortPoints
longPoints := stochRsiValue > stochRsiValue[1] ? longPoints + 1 : longPoints
shortPoints := stochRsiValue < stochRsiValue[1] ? shortPoints + 1 : shortPoints
longPoints := wt1 > wt1[1] ? longPoints + 1 : longPoints
shortPoints := wt1 < wt1[1] ? shortPoints + 1 : shortPoints
longPoints := obv > obv[1] ? longPoints + 1 : longPoints
shortPoints := obv < obv[1] ? shortPoints + 1 : shortPoints
longPoints := mfiValue > 50 ? longPoints + 1 : longPoints
shortPoints := mfiValue < 50 ? shortPoints + 1 : shortPoints
[longPoints, shortPoints]
// Symbols array
symbols = array.new_string(5)
array.set(symbols, 0, "US30")
array.set(symbols, 1, "GOLD")
array.set(symbols, 2, "DXY")
array.set(symbols, 3, "BTCUSDT.P")
array.set(symbols, 4, syminfo.tickerid)
// Calculate points for each symbol
var symbolPoints = array.new_int(2, 0)
for symbol in symbols
[longPoints, shortPoints] = calcPoints(symbol)
var logMessage = "Symbol: " + symbol + ", Long: " + str.tostring(longPoints) + ", Short: " + str.tostring(shortPoints)
log.info(logMessage)
array.set(symbolPoints, 0, array.get(symbolPoints, 0) + longPoints)
array.set(symbolPoints, 1, array.get(symbolPoints, 1) + shortPoints)
// Calculate total long and short probabilities
totalLongPoints = array.get(symbolPoints, 0)
totalShortPoints = array.get(symbolPoints, 1)
combinedProbabilityLong = totalLongPoints / (array.size(symbols) * 3) * 100
combinedProbabilityShort = totalShortPoints / (array.size(symbols) * 3) * 100
// Display combined probabilities
var labelBox = label.new(na, na, "")
label.set_xy(labelBox, bar_index, high)
label.set_text(labelBox, "Combined Probabilities\nLong: " + str.tostring(combinedProbabilityLong) + "%\nShort: " + str.tostring(combinedProbabilityShort) + "%")
label.set_color(labelBox, color.new(color.blue, 0))
label.set_style(labelBox, label.style_label_left)