Skip to content

Instantly share code, notes, and snippets.

@KebabLord
Last active January 6, 2025 19:17
Show Gist options
  • Save KebabLord/afdd1279993214c25791362b76141f1e to your computer and use it in GitHub Desktop.
Save KebabLord/afdd1279993214c25791362b76141f1e to your computer and use it in GitHub Desktop.
24 Hour Comparative Plot for TradingView
// Plot's -24 hours' plot by @Kebablord
// Lack's future / lookahead data feature tho. Dunno how to do it.
// Used @Hermetism's Multi Coin Compare code as base, so some credits also goes to @Violent and @HomelessLemon
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
//@version=5
indicator(title='[H] Compare', shorttitle='[H] Compare', overlay=true)
t = input.bool(true, title='Show Table', group='Table', tooltip='Show the table')
tablePositionY = input.string('top', title='Y-Position', options=['top', 'middle', 'bottom'], group="Table", inline="1")
tablePositionX = input.string('right', title='X-Position', options=['left', 'center', 'right'], group="Table", inline="1")
var table dataTable = table.new(tablePositionY + '_' + tablePositionX, 1, 5, border_width=7)
////////////////////////////////////////////////////////////////////////////////
// Compare
////////////////////////////////////////////////////////////////////////////////
int compareNumber = input.int(3, maxval=5, title='Number of Comparisons', tooltip='Maximum of 5')
compareSym = input.symbol('BINANCE:BTCUSDT', 'Compare Symbol', group="Coin")
shiftHours = input.float(24, 'Shift-Hours', group="Coin")*60
compareRes = input.timeframe('60', 'Timeframe', group="Coin")
compareMult = input.bool(title='Multiply', defval=true, tooltip='If the coin you are comparing has a lower price than the main symbol you will need to multiply instead of divide', group="Coin")
compareDiv = input.float(1, 'Divider', minval=0.05, step=0.05, tooltip='The amount to divide the current price for the comparison', group="Coin")
compareColor = input(title='Compare Color', defval=#ff9800, group="Coin")
compareSource = input.source(close, "Source", group="Coin")
// Get the price of BTCUSDT 24 hours ago
comparePrice = request.security(compareSym, compareRes, compareSource)[shiftHours]
plot(compareMult ? compareNumber >= 1 ? comparePrice * compareDiv : na : compareNumber >= 1 ? comparePrice / compareDiv : na, '[1] Compare Price', color=compareColor, style=plot.style_stepline, linewidth=2)
////////////////////////////////////////////////////////////////////////////////
// Output
////////////////////////////////////////////////////////////////////////////////
if barstate.islast and t==true and compareNumber>0
compareText = compareSym + " " + str.tostring(comparePrice, format="0.##########")
tableBgColor = input(color.rgb(120, 123, 134, 85), "Table Background Color", group="Table")
if(compareNumber>=1)
table.cell(dataTable, 0, 0, text=compareText, bgcolor=tableBgColor, text_color=compareColor)
@KebabLord
Copy link
Author

This script basically creates a plot for the specified token with specified time shift so you can compare 24 hours ago's plot with today's.
image

Settings:
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment