According to the source code you gave.
There is no future function.
That's why what you said happened, which is what I said: because the closing price of the cycle has not been determined when the signal is given, there will be a moment when the condition is met and a moment when the condition is met, which will lead to repeated signals.
Only by pushing the closing cycle forward one cycle and adopting a certain closing price can there be a stable result.
As for how to modify it, it is very simple if you know the function of the software you use.
But I only know the function of writing analysts and flying foxes, hehe.
According to the analyst's writing is
CROSS(ref(DIFF, 1), ref(DEA, 1)) and ref(CLOSE, 1)>MA 13, bk;
CROSS(ref(DEA, 1),ref(DIFF, 1)),SP;
CROSS(ref(DEA, 1), ref(DIFF, 1)) and ref(CLOSE,1) < MA 13,SK;
CROSS(ref(DIFF, 1),ref(DEA, 1)),BP;
The trading system is a very simple thing, and some people do profit from it.
But most importantly, you must follow the signal of the system mechanically, otherwise it is meaningless.