DEFPARAM FlatBefore=080000
DEFPARAM FlatAfter=220000
DEFPARAM CumulateOrders = false
D = ExponentialAverage[21](close)
ncontratti=50
MyBorder=(TICKSIZE*1)
MySpread=(TICKSIZE*2)
var1=1
var2=3
filterL1 = Low[1]>D[1] and Low<=D and High>=D
filterL2 = Low[2]>D[2] and Low[1]<=D[1] and High[1]>=D[1] and High>=D and High<=High[1]+MyBorder
filterL3 = Low[3]>D[3] and Low[2]<=D[2] and High[2]>=D[2] and High[1]>=D[1] and High>=D and High<=High[1]+MyBorder
sup=high+MySpread
inf=low-MySpread
inf2=MIN(low[1],low)-myspread
inf3=MIN(low[2],low)-myspread
IF filterL1 and NOT ONMARKET THEN
ampiezza=((sup-inf)/(1*Ticksize))*var1
ampiezzaP=((sup-inf)/(1*Ticksize))*var2
BUY ncontratti CONTRACTS AT sup STOP
SET STOP pLOSS ampiezza
ENDIF
IF filterL2 and NOT ONMARKET THEN
ampiezza=((sup-inf2)/(1*Ticksize))*var1
ampiezzaP=((sup-inf2)/(1*Ticksize))*var2
BUY ncontratti CONTRACTS AT sup STOP
SET STOP pLOSS ampiezza
ENDIF
IF filterL3 and NOT ONMARKET THEN
ampiezza=((sup-inf3)/(1*Ticksize))*var1
ampiezzaP=((sup-inf3)/(1*Ticksize))*var2
BUY ncontratti CONTRACTS AT sup STOP
SET STOP pLOSS ampiezza
ENDIF
IF LONGONMARKET THEN
SET STOP PLOSS 0
SELLSHORT ncontratti CONTRACTS AT TRADEPRICE - ampiezza*pointsize STOP
SHORTSTOP=HIGH[1]+1*POINTSIZE
EXITSHORT AT SHORTSTOP STOP
ENDIF
IF SHORTONMARKET THEN
EXITSHORT AT SHORTSTOP STOP
ENDIF
SET TARGET pPROFIT ampiezzaP