Perte=50 //in the currency of the stock
EMAbreve = Average[21](close)
EMAlunga = Average[90](close)
Long = (EMAbreve Crosses Over EMAlunga)
Short = (EMAbreve Crosses Under EMAlunga)
// Condizioni per entrare su posizioni long
IF NOT LongOnMarket AND Long THEN
BUY 1 CONTRACTS AT MARKET
maxlong=strategyprofit
ENDIF
// Condizioni per entrare su posizioni short
IF NOT ShortOnMarket AND Short THEN
SELLSHORT 1 CONTRACTS AT MARKET
maxshort=strategyprofit
ENDIF
if longonmarket then
maxlong=max(maxlong,strategyprofit+((close -tradeprice)*COUNTOFLONGSHARES/POINTSIZE))
if strategyprofit+((close -tradeprice)*COUNTOFLONGSHARES/POINTSIZE) < maxlong-perte then
sell at market
endif
elsif shortonmarket then
maxshort=max(maxshort,strategyprofit+((tradeprice -close)*COUNTOFSHORTSHARES/POINTSIZE))
if strategyprofit+((tradeprice -close)*COUNTOFSHORTSHARES/POINTSIZE) <maxshort - perte then
exitshort at market
endif
endif