Swap Ratio on TradingView

Discuss your code and ask for help here.
Post Reply
Numerus
Posts: 13
Joined: Wed Jul 10, 2024 1:37 pm
Contact:

Swap Ratio on TradingView

Post by Numerus »

Here's a TradingView PINE Script to generate the swap ratio for XRP to EVR
Image

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)
wroomwroom
Posts: 15
Joined: Wed Jul 31, 2024 5:59 pm

Re: Swap Ratio on TradingView

Post by wroomwroom »

Looking good, this is really useful for arbitrage trading! Great job sir :)
NickFields
Posts: 3
Joined: Wed Jul 31, 2024 6:29 pm

Re: Swap Ratio on TradingView

Post by NickFields »

Really interested in this
Post Reply