Here is a simple and educational trading system based on moving averages logically mean reverting on the mini S&P500 US index.
// tren=filtro lungo periodo , mml media di corto periodo per le operazioni long , mms media di corto periodo per le operazioni short
tren=average[125](close)
mml=average[14](close)
mms=average[4](close)
// Condizioni per entrare su posizioni long
IF NOT LongOnMarket and close >tren and tren>tren[1] and close<mml THEN
BUY 1 CONTRACTS AT MARKET
ENDIF
// Condizioni per uscire da posizioni long
If LongOnMarket AND close>mml and close>close[1] THEN
SELL AT MARKET
ENDIF
// Stop e target: Inserisci qui i tuoi stop di protezione e profit target
if not shortonmarket and close<tren and tren<tren[1] and close>mms then
sellshort 1 contracts at market
endif
if shortonmarket and close<mms and close<close[1]then
exitshort at market
endif