DEFPARAM CumulateOrders = FALSE
BBVal = 20 //20 periodi
BBdev = 0.382 //0.382 deviazione
Media = average[BBval,0](close) //Linea Mediana
BandaAlta = Media + ((std[BBval](close)) * BBdev) //Banda Superiore
BandaBassa = Media - ((std[BBval](close)) * BBdev) //Banda Inferiore
IF close CROSSES UNDER Media THEN
CondL = 0
ELSIF close CROSSES OVER Media THEN
CondS = 0
ENDIF
IncrocioSopra = close CROSSES OVER BandaAlta
IncrocioSotto = close CROSSES UNDER BandaBassa
L1 = (summation[4](close > BandaAlta) = 4)
S1 = (summation[4](close < BandaBassa) = 4)
L2 = IncrocioSopra[4]
S2 = IncrocioSotto[4]
IF CondL = 0 THEN
CondL = L1 AND L2
Massimo = highest[5](high)
ENDIF
IF CondS = 0 THEN
CondS = S1 AND S2
Minimo = lowest[5](low)
ENDIF
IF OnMarket THEN
CondL = 0
CondS = 0
ENDIF
IF CondL AND close CROSSES OVER Massimo AND Not OnMarket THEN
BUY 1 CONTRACT AT MARKET
ENDIF
IF CondS AND close CROSSES Under Minimo AND Not OnMarket THEN
SELLSHORT 1 CONTRACT AT MARKET
ENDIF
SET STOP pLOSS 100
SET TARGET pPROFIT 700
graphonprice Massimo coloured(0,255,0,255)
graphonprice Minimo coloured(255,0,0,255)