ONCE BBtouchL = 0
ONCE BBtouchS = 0
ONCE Count = 0
ONCE MaxBars = 3
//
// setup Bollinger Bands
BBVal = 20 //20 periods BB
BBdev = 2.0 //2.0 deviation BB
BBavg = average[BBval,0](close) //BB mean (middle line)
BollUP = BBavg + ((std[BBval](close)) * BBdev) //BB Upper Band
BollDN = BBavg - ((std[BBval](close)) * BBdev) //BB Lower Band
//
IF count = MaxBars THEN
BBtouchL = 0
BBtouchS = 0
Count = 0
ENDIF
//
// setup Stocastico
StocK = Stochastic[10,3](close) //Linea K
StocD = Average[3,0](StocK) //Linea D
//
// setup consizione LONG
//
BBtouchL = (low <= BollDN)
IF BBtouchL THEN
BBtouchS = 0
IF BBtouchL[1] = 0 THEN
Count = 0
ENDIF
ENDIF
IF BBtouchL THEN
Count = Count + 1
InversioneLONG = StocK > StocD AND StocK > 20
ENDIF
//
// setup condizione SHORT
//
BBtouchS = (high >= BollUP)
IF BBtouchS THEN
BBtouchL = 0
IF BBtouchS[1] = 0 THEN
Count = 0
ENDIF
ENDIF
IF BBtouchS THEN
Count = Count + 1
InversioneSHORT = StocK < StocD AND StocK < 80
ENDIF
//
IF OnMarket THEN
BBtouchL = 0
BBtouchS = 0
Count = 0
ENDIF
//
// Apertura posizione LONG
IF BBtouchL AND InversioneLONG AND Not OnMarket THEN
BUY 1 CONTRACT AT MARKET
ENDIF
//
// Apertura posizione SHORT
IF BBtouchS AND InversioneSHORT AND Not OnMarket THEN
SELLSHORT 1 CONTRACT AT MARKET
ENDIF
SET TARGET pPROFIT 100
SET STOP pLOSS 50