Vector Magnitude
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © peacefulLizard50262

//@version=5
indicator("Vector Magnitude")
// Define the getVectorDirection() function
getVectorDirection(src, len) =>
    // Calculate the average of the vector
    avg = ta.sma(src, len)

    // Determine the direction of the vector
    direction = src[0] > avg[0] ? 1 : (src[0] < avg[0] ? -1 : 0)

    // Calculate the magnitude of the vector
    magnitude = math.sqrt((src[0] - avg[0]) * (src[0] - avg[0]) + (src[1] - avg[1]) * (src[1] - avg[1]) + (src[2] - avg[2]) * (src[2] - avg[2]))

    // Return the direction and magnitude of the vector
    out = direction == 1 ? magnitude : direction == -1 ? -magnitude : 0
    out

len = input.int(30, "Length", 1)
plot(getVectorDirection(close, len))
