//@version=5
indicator("Geometric MA cross", shorttitle="GMA", overlay=true)

// Toggle for fixed values
useFixedValue = input.bool(false, title="Use Fixed Value?")

// Input for asset type and timeframe selection
assetType = input.string("forex", title="Asset Type", options=["forex", "crypto", "metals", "stocks"])
timeFrame = input.string("1d", title="Time Frame", options=["4h", "1d"])

// Default inputs for custom settings
Length = input.int(title="Length", defval=10)
priceOption = input.string(title="Price Option", defval="Close", options=["Close", "Open", "High", "Low", "Median", "Typical"])

// Apply fixed values if useFixedValue is enabled
if useFixedValue
    if assetType == "forex" and timeFrame == "1d"
        Length := 43
        priceOption := "Median"
    else if assetType == "forex" and timeFrame == "4h"
        Length := 32
        priceOption := "High"
    else if assetType == "crypto" and timeFrame == "1d"
        Length := 55
        priceOption := "Open"
    else if assetType == "crypto" and timeFrame == "4h"
        Length := 24
        priceOption := "Low"
    else if assetType == "metals" and timeFrame == "1d"
        Length := 51
        priceOption := "Typical"
    else if assetType == "metals" and timeFrame == "4h"
        Length := 10
        priceOption := "Close"
    else if assetType == "stocks" and timeFrame == "1d"
        Length := 67
        priceOption := "Low"
    else if assetType == "stocks" and timeFrame == "4h"
        Length := 16
        priceOption := "High"

// Set price source based on selected option
price = switch priceOption
    "Close" => close
    "Open" => open
    "High" => high
    "Low" => low
    "Median" => hl2
    "Typical" => (high + low + close) / 3

// GMA Calculation
lmean = math.log(price)
smean = 0.0
for i = 0 to Length - 1
    smean := smean + lmean[i]
gma = math.exp(smean / Length)

// Plot the GMA
plot(gma, title="GMA", color=color.yellow, linewidth=2)

// Crossover/Crossunder conditions for close price and GMA
priceCrossAbove = ta.crossover(close, gma)
priceCrossBelow = ta.crossunder(close, gma)

// Plot shapes on the bottom based on close price crossing the GMA
plotshape(priceCrossAbove, title="Price Cross Above GMA", location=location.bottom, color=color.green, style=shape.triangleup, size=size.tiny)
plotshape(priceCrossBelow, title="Price Cross Below GMA", location=location.bottom, color=color.red, style=shape.triangledown, size=size.tiny)
