Swap Ratio on TradingView
Posted: Wed Jul 31, 2024 12:47 pm
Here's a TradingView PINE Script to generate the swap ratio for XRP to EVR

Code: Select all
//@version=5
indicator("Auto Swap Ratio", overlay=true)
// Define the symbols for XRP and EVR
xrpSymbol = "BITRUE:XRPUSDT"
evrSymbol = "BITRUE:EVRUSDT"
// Fetch price data for XRP and EVR on the current timeframe
xrpPrice = request.security(xrpSymbol, timeframe.period, close)
evrPrice = request.security(evrSymbol, timeframe.period, close)
// Calculate the swap ratio between XRP and EVR
swapRatio = evrPrice / xrpPrice
// Convert swapRatio to string with two decimal places
swapRatioString = str.tostring(swapRatio, "#.00")
// Define colors and size for the label
labelColor = input.color(color.white, title="Label Color")
textColor = input.color(color.black, title="Text Color")
labelSize = input(size.small, title="Label Size")
// Plot the swap ratio as a label on the chart for each bar
if bar_index % 10 == 0 // Adjust the frequency of labels to avoid clutter
label.new(bar_index, high, text=swapRatioString, style=label.style_label_down, color=labelColor, textcolor=textColor, size=labelSize)
// Display the current swap ratio as a plot for better visualization
plot(swapRatio, title="Swap Ratio", color=color.blue, linewidth=2)