// Strategia EURUSD contro trend 30 minuti Bollinger
// Definizione dei parametri del codice
DEFPARAM CumulateOrders = true
//defparam flatbefore = 090000
//defparam flatafter = 233000
a=21
b=1.6
c=0.9
c1=1.2
d1=9
e=6
f=15
g=145
//Indicatori
BollLow = Average[a](close)-b*std[a](close) //Bollinger low entry
BollHigh = Average[a](close)+b*std[a](close) //Bollinger high entry
BollLowExitloss = Average[a](close)-c*std[a](close) //Bollinger low exit
BollHighExitloss = Average[a](close)+c*std[a](close) //Bollinger high exit
BollLowExitwin = Average[a](close)-c1*std[a](close) //Bollinger low exit
BollHighExitwin = Average[a](close)+c1*std[a](close) //Bollinger high exit
myatr = averagetruerange[d1]
MediaAtr = average[e](myatr)
myStoc=smoothedstochastic[f,3]
MyAverage=ExponentialAverage[g](close)
If MyAverage[0] > MyAverage[1] then
Fatt=1
elsif MyAverage[0]<=MyAverage[1] then
Fatt=0.5
endif
//Condizioni entrata e uscita contro trend
CondInglongCT = (close[1] crosses under BollLow) and close crosses over BollLow and (myatr>mediaatr) and mystoc<20 //and time>110000
CondIngshortCT = (close[1] crosses over BollHigh) and close crosses under BollHigh and (myatr>mediaatr) and mystoc>80 //and time>110000
g1=3 //2
h1=4 //1
i1=2 //4
l1=2 //3
g2=1 //1
h2=4 //3
i2=4 //2
l2=2 //3
//entrata long contro trend
if CondIngLongCT then
if countoflongshares = 0 then
buy g1*fatt shares at market
elsif countoflongshares = g1 then
buy h1*fatt shares at market
elsif countoflongshares = g1+h1 then
buy i1*fatt shares at market
elsif countoflongshares = g1+h1+i1 then
buy l1*fatt shares at market
endif
endif
//entrata short in trend
if CondIngShortCT then
if countofshortshares = 0 then
sellshort g2*fatt shares at market
elsif countofshortshares = g2 then
sellshort h2*fatt shares at market
elsif countofshortshares = g2+h2 then
sellshort i2*fatt shares at market
elsif countofshortshares = g2+h2+i2 then
sellshort l2*fatt shares at market
endif
endif
if longonmarket and close crosses over BollHighexitloss then
if positionperf<0 then
sell at market
else
sell at bollhighexitwin limit
endif
endif
if shortonmarket and close crosses under BollLowexitloss then
if positionperf<0 then
exitshort at market
else
exitshort at bolllowexitwin limit
endif
endif