Normalized Performance ComparisonThis script visualizes the relative performance of a primary asset against a benchmark composed of three reference assets. Here's how it works:
User Inputs:
- Users specify ticker symbols for three reference assets (default: Platinum, Palladium, Rhodium).
Data Retrieval:
- Fetches closing prices for the primary asset (the one the script is applied to) and the three reference assets.
Normalization:
- Each asset's price is normalized by dividing its current price by its initial price at the start of the chart. This allows for performance comparison on a common scale.
Benchmark Creation:
- The normalized prices of the three reference assets are combined to create a composite benchmark.
Ratio Calculation:
- Computes the ratio of the normalized primary asset price to the combined normalized benchmark price, highlighting relative performance.
Plotting:
- Plots this ratio as a blue line on the chart, showing the primary asset's performance relative to the benchmark over time.
This script helps users quickly assess how well the primary asset is performing compared to a set of reference assets.
Benchmark
benchLibrary "bench"
A simple banchmark library to analyse script performance and bottlenecks.
Very useful if you are developing an overly complex application in Pine Script, or trying to optimise a library / function / algorithm...
Supports artificial looping benchmarks (of fast functions)
Supports integrated linear benchmarks (of expensive scripts)
One important thing to note is that the Pine Script compiler will completely ignore any calculations that do not eventually produce chart output. Therefore, if you are performing an artificial benchmark you will need to use the bench.reference(value) function to ensure the calculations are executed.
Please check the examples towards the bottom of the script.
Quick Reference
(Be warned this uses non-standard space characters to get the line indentation to work in the description!)
```
// Looping benchmark style
benchmark = bench.new(samples = 500, loops = 5000)
data = array.new_int()
if bench.start(benchmark)
while bench.loop(benchmark)
array.unshift(data, timenow)
bench.mark(benchmark)
while bench.loop(benchmark)
array.unshift(data, timenow)
bench.mark(benchmark)
while bench.loop(benchmark)
array.unshift(data, timenow)
bench.stop(benchmark)
bench.reference(array.get(data, 0))
bench.report(benchmark, '1x array.unshift()')
// Linear benchmark style
benchmark = bench.new()
data = array.new_int()
bench.start(benchmark)
for i = 0 to 1000
array.unshift(data, timenow)
bench.mark(benchmark)
for i = 0 to 1000
array.unshift(data, timenow)
bench.stop(benchmark)
bench.reference(array.get(data, 0))
bench.report(benchmark,'1000x array.unshift()')
```
Detailed Interface
new(samples, loops) Initialises a new benchmark array
Parameters:
samples : int, the number of bars in which to collect samples
loops : int, the number of loops to execute within each sample
Returns: int , the benchmark array
active(benchmark) Determing if the benchmarks state is active
Parameters:
benchmark : int , the benchmark array
Returns: bool, true only if the state is active
start(benchmark) Start recording a benchmark from this point
Parameters:
benchmark : int , the benchmark array
Returns: bool, true only if the benchmark is unfinished
loop(benchmark) Returns true until call count exceeds bench.new(loop) variable
Parameters:
benchmark : int , the benchmark array
Returns: bool, true while looping
reference(number, string) Add a compiler reference to the chart so the calculations don't get optimised away
Parameters:
number : float, a numeric value to reference
string : string, a string value to reference
mark(benchmark, number, string) Marks the end of one recorded interval and the start of the next
Parameters:
benchmark : int , the benchmark array
number : float, a numeric value to reference
string : string, a string value to reference
stop(benchmark, number, string) Stop the benchmark, ending the final interval
Parameters:
benchmark : int , the benchmark array
number : float, a numeric value to reference
string : string, a string value to reference
report(Prints, benchmark, title, text_size, position)
Parameters:
Prints : the benchmarks results to the screen
benchmark : int , the benchmark array
title : string, add a custom title to the report
text_size : string, the text size of the log console (global size vars)
position : string, the position of the log console (global position vars)
unittest_bench(case) Cache module unit tests, for inclusion in parent script test suite. Usage: bench.unittest_bench(__ASSERTS)
Parameters:
case : string , the current test case and array of previous unit tests (__ASSERTS)
unittest(verbose) Run the bench module unit tests as a stand alone. Usage: bench.unittest()
Parameters:
verbose : bool, optionally disable the full report to only display failures
Does your trading pass the seasonality test?Are you consistently beating the standard "Buy and Hold" benchmark?
Check your performance against the next most common strategy:
Buy at the start of the holiday season and close in the new year.
By default, the strategy starts with $100,000 and risks 25% of the account on each swing trade.
Commission is set to be 0.5% of each trade.
You can tweak the direction of trades by adjusting the first setting.
Tweak the holding period by changing the Entry and Exit months.
Red plot: Balance of account
Orange plot: Equity of account
BETA (against any benchmark index - defaulted to NSE:NIFTY)Beta value of a stock relative to benchmark index. Thanks to Ricardo Santos for the original script. This script is adapted from it.
To understand beta, refer Investopedia link: www.investopedia.com
A beta value of 1 means the stock is directly correlated to benchmark index - volatility would be same as overall market.
Beta value less than 1 and greater than 0 means the stock is less volatile than the market.
Beta value more than 1 would mean the stock is more volatile than the market.
A beta value of 1.2 would roughly translate to the stock being 20% more volatile than the overall market.
A negative beta value indicates the stock is inversely correlated to market.
In the example chart, you can see the Beta value change in NSE:RELIANCE with respect to NSE:NIFTY.
Godmode 4.0.2 [Supply/Demand]First off, a huge thank you to the following people:
LEGION:
LazyBear: www.tradingview.com
xSilas: www.tradingview.com
Ni6HTH4awK: www.tradingview.com
sco77m4r7and:
SNOW_CITY: www.tradingview.com
oh92: www.tradingview.com
alexgrover: www.tradingview.com
cI8DH: www.tradingview.com
DonovanWall: www.tradingview.com
shtcoinr: www.tradingview.com
This is the third iteration of Godmode. This time I borrowed the method used by shtcoinr to render supply/demand, resistance and support zones. The idea here is to input the appropriate benchmark tickerid to the asset class you're trading and to paint zones according to the price activity of the selected tickerid. This works very well trying to paint meaningful zones against noisy stocks, currencies, commodities etc. Use a correlation coefficient to determine the best benchmark for your asset class.
Want to Learn?
If you'd like the opportunity to learn Pine but you have difficulty finding resources to guide you, take a look at this rudimentary list: docs.google.com
The list will be updated in the future as more people share the resources that have helped, or continue to help, them. Follow me on Twitter to keep up-to-date with the growing list of resources.
Suggestions or Questions?
Don't even kinda hesitate to forward them to me. My (metaphorical) door is always open.
Godmode 4.0.1 [Correlator]First off, a huge thank you to the following people:
@LEGION:
@LazyBear: www.tradingview.com
@xSilas: www.tradingview.com
@Ni6HTH4awK: www.tradingview.com
@sco77m4r7and:
@SNOW_CITY: www.tradingview.com
@oh92: www.tradingview.com
@alexgrover: www.tradingview.com
@cI8DH: www.tradingview.com
@DonovanWall: www.tradingview.com
This is my second iteration of Godmode. This time I allowed the possibility to correlate two benchmarks against one another, thereby giving you twice the signals (once there's a strong correlation between the two, inverse or otherwise). That aside, there are no changes to this indicator that the first iteration doesn't have:
There are still more iterations planned, but if you guys have any ideas or wishes regarding what direction I go, then please let me know.
Want to Learn?
If you'd like the opportunity to learn Pine but you have difficulty finding resources to guide you, take a look at this rudimentary list: docs.google.com
The list will be updated in the future as more people share the resources that have helped, or continue to help, them. Follow me on Twitter to keep up-to-date with the growing list of resources as well as any other scripts I publish.
Suggestions or Questions?
Don't even kinda hesitate to forward them to me. My (metaphorical) door is always open.
Godmode 4.0.0 [Oscillator]First off, a huge thank you to the following people:
LEGION:
LazyBear: www.tradingview.com
xSilas: www.tradingview.com
Ni6HTH4awK: www.tradingview.com
sco77m4r7and:
SNOW_CITY: www.tradingview.com
oh92: www.tradingview.com
alexgrover: www.tradingview.com
cI8DH: www.tradingview.com
DonovanWall: www.tradingview.com
Since I've been on TradingView I've become somewhat enthralled by Godmode and the collective work that goes in to it, so I decided to publish my own iteration, building off the ideas already present. (This is a great way to get familiar with Pine by the way, just in case there are any beginners reading this)
Changes
The first change I made was to allow the user to select whatever tickerid they wanted as a benchmark. If trading XBTUSD on BitMEX for example, the indicator will react to exchange-specific activity, which means it will respond to all the little whipsaws, whipsaws that can be especially present on a futures exchange. By typing CRYPTOCAP:BTC or CRYPTOCAP:TOTAL we endeavor to remove noise. It can also signal earlier. Less noise and less lag. Another idea would be to choose a benchmark that has a strong inverse relationship with the asset you're trading: try CRYPTOCAP:USDT as the benchmark against BTC to see what I mean.
I also added the ability to smooth the plot, yet again removing noise but adding considerable lag.
The linear regression of the wave-trend is calculated in place of the EMA. This is plotted as columns with the midline (50) as the base. This is just calculating the slope of the wave-trend and can signal a weakening trend before a reversal takes place.
Using cI8DH's True RSI script () as inspiration, I added a function for calculating the True TSI in an attempt to remove any bullish bias. Funnily enough, when I tried to do the same with the RSI I had some problems. I'll try to resolve this in the coming weeks.
Made slight changes to the aesthetics. Tried to bring the two main plots alive by making their bold, opaque colors stand off the subtle tones in the background.
To Do List
1. I would like to sort out the issue with the True RSI.
2. When the plots are smoothed, there's an issue with the green 'Caution!' dots appearing in the lower half of the indicator.
3. I'd like to adjust the code so that if the 'Benchmark' box is empty, that it will automatically register the current tickerid as the 'Benchmark'.
If anyone has any suggestions on other fixes or how to apply the fixes mentioned by me, please don't hesitate to reach out to me here or through other media platforms.
Want to Learn?
If you'd like the opportunity to learn Pine but you have difficulty finding resources to guide you, take a look at this rudimentary list: docs.google.com
The list will be updated in the future as more people share the resources that have helped, or continue to help, them. Follow me on Twitter to keep up-to-date with the growing list of resources.
Suggestions or Questions?
Don't even kinda hesitate to forward them to me. My (metaphorical) door is always open.
BITMEX:XBTUSD
CRYPTOCAP:BTC
CRYPTOCAP:TOTAL
CRYPTOCAP:USDT.D