RSI MACD Same Ratio
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © dkndkn

//@version=5
indicator("RSI MACD Same Ratio", overlay=false)

// ----------------------------------------------------------------------------------------------------
// INPUT
// ----------------------------------------------------------------------------------------------------
// 共通
float src = input.source(close, title="source")
// RSI
int period_rsi = input.int(14, title="RSI period")
// MACD
int period_macd_fast = input.int(12, title="MACD fast period")
int period_macd_slow = input.int(26, title="MACD slow period")
int period_macd_signal = input.int(9, title="MACD signal period")
int macd_coef = input.int(20, title="adjustment ratio")

// ----------------------------------------------------------------------------------------------------
// LOGIC
// ----------------------------------------------------------------------------------------------------
// RSI
float rsi = ta.rsi(src, period_rsi)
// MACD
[macd_line, signal_line, hist_line] = ta.macd(src, period_macd_fast, period_macd_slow, period_macd_signal)

// RSIの最大値を50とし、最小値を-50とする
float w_rsi = rsi - 50

// MACDの比率をRSIに合わせる
float w_macd_line = macd_line * macd_coef
float w_signal_line = signal_line * macd_coef
float w_hist_line = hist_line * macd_coef

// ----------------------------------------------------------------------------------------------------
// PLOT
// ----------------------------------------------------------------------------------------------------
// RSI
plot(w_rsi, title="RSI", color=color.green, linewidth=1, style=plot.style_line)
// MACD
plot(w_macd_line, title="MACD", color=color.red, linewidth=1, style=plot.style_line)
plot(w_signal_line, title="MACD signal", color=color.blue, linewidth=1, style=plot.style_line)
plot(w_hist_line, title="MACD hist", color=color.new(color.gray, 60), linewidth=1, style=plot.style_histogram)

// EOF