Anchored SMA
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © downwithfate

//@version=5
//This indicator is to keep a constant anchor point to the SMA across different timeframes from 1 minute to 1 week
//For example, if you set this to the 5 day SMA, when you go in to the 30 minute timeframe, it will scale to 65 tick SMA 
indicator("Anchored SMA", overlay = true)
int anchor = input.int(5, title = "Anchor Ticks", minval = 1)
string anchorTF = input.timeframe(defval = 'D', title = "Anchored Timeframe")
int aMin = timeframe.in_seconds(anchorTF)/60
int pMin = timeframe.in_seconds()/60

//1 hour = 60 mins, 1 day = 390 mins, 1 week = 1950 mins       
if aMin == 1440
    aMin := 390
else if aMin == 10080
    aMin := 1950
//period minutes
if pMin == 1440
    pMin := 390
else if pMin == 10080
    pMin := 1950
//convert TFs to mins

//get the number of ticks for the timeframe and find the anchored SMA
int ticks = anchor * aMin/pMin
aSMA = ta.sma(close, ticks)

plot(aSMA, title="aSMA", color=color.blue)