如何确定事件的开始

How to identify beginning of an event

我有 2 条移动平均线,我想确定此事件:

begin = close > ma(close,50)
ending = close < ma(close,500)

所以我的活动在收盘价超过 MA50 时开始,活动在收盘价低于 MA500 时结束。有没有一种简单的方法可以做到这一点?我对文档有点迷茫

//@version=4
study("Event", "EV", true)

source                      = input(close, "Source",       type=input.source)
var int     sma_len_1       = input(13,    "SMA Length 1", minval=1)
var int     sma_len_2       = input(30,    "SMA Length 2", minval=1)
var bool    event_active    = na

sma1 = sma(source, sma_len_1)
sma2 = sma(source, sma_len_2)

if crossover(source, sma1)
    event_active := true

if crossunder(source, sma2)
    event_active := false

plot(sma1, "SMA1", color.red)
plot(sma2, "SMA2", color.blue)

bgcolor(event_active ? color.lime : na)