Based on this question regarding existance of closest function in Schwarz class, where answer was negative. What if we add a new constraint. Not only infinitely differentiable compact support but with simultaneously bounded moments: $$\left\| \frac{\partial^n}{\partial x^n}\left\{f\right\}(x) \right\|\leq A ,\forall n ,x$$ for some $A\in \mathbb R^+$. Would it now be possible to find some unique minimizer?
EDIT of course we need to edit triangle wave to have compact support. Say it has compact support on $$x \in [-1-2N,1+2N], N\in \mathbb Z_+$$ In other words, $2N+1$ whole periods and it goes down to $0$ just at both ends of support.
Let $ \lVert f\rVert_{\alpha,\beta} = \sup_{x} \lvert x^\alpha D^\beta f(x) \rvert $ be the seminorms defining the Schwartz space $\mathcal{S}(\mathbb{R})$.
For fixed positive numbers $A_{\alpha,\beta}$, the set of functions $$ K = \{f\in\mathcal{S}(\mathbb{R}) : \lVert f\rVert_{\alpha,\beta} \leq A_{\alpha,\beta}\} $$ is sequentially compact. In fact, given a sequence $(f_k)_k\subset K$, the functions $(D^\beta f_k)_k$ are equi-continuous (they are equi-Lipschitz), therefore by Ascoli-Arzelà and a diagonalization argument we can find a subsequence (which I will not rename) and a function $f\in C^\infty(\mathbb{R})$ such that for every compact set $E\subset\mathbb{R}$ we have $D^\beta f_k \to D^\beta f$ uniformly on $E$. This convergence is enough to guarantee that $f\in K$.
Given $g\in L^2(\mathbb{R})$, the functional $J_g(f) = \lVert f-g\rVert_{L^2(\mathbb{R})}$ is continuous with respect to the Schwartz topology, therefore it has a minimizer in $K$.
I suspect that the conditions you consider (constraining only the norms with $\alpha=0$) are not sufficient. For instance, the functions $f_k=e^{-(x/k)^2}$ satisfy your hypothesis, but they converge to $1$, which is not a Schwartz function.