x-Period ROI by USCG_Vet
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Written by USCG_Vet; All credit to Trace Mayer.  Notice, this indicator is for educational purposes only and is not financial advice.

//@version=5
indicator(title='x-Day ROI by USCG_Vet', overlay=false)

HiOrLow = input(title='high vs low vs avg', defval='high')

nPeriods = input(title='Number of Periods', defval=365)

n1 = high[1]  // this is end period
n365 = high[nPeriods]  // this is begin period

if HiOrLow == 'high'
    n1 := high[1]
    n1
else if HiOrLow == 'low'
    n1 := low[1]
    n1
else
    n1 := high[1] + low[1] / 2
    n1

if HiOrLow == 'high'
    n365 := high[nPeriods]
    n365
else if HiOrLow == 'low'
    n365 := low[nPeriods]
    n365
else
    n365 := high[nPeriods] + low[nPeriods] / 2
    n365



ROI = (n1 - n365) / n1  // calculate the ROI between end period and begin period


topCol = color.orange
plot(ROI, color=color.new(topCol, 0), linewidth=1)


