// Definizione dei parametri del codice
DEFPARAM CumulateOrders = False // Posizioni cumulate disattivate
DEFPARAM PRELOADBARS = 2000
once positionsize=1
timeframe (1 hour, updateonclose)
// Condizioni per entrare su posizioni long
indicator1 = SuperTrend[3,14] //3,10
c1 = (close[1] CROSSES OVER indicator1[1])
// Condizioni per entrare su posizioni short
indicator3 = SuperTrend[3,13]
c3 = (close[1] CROSSES UNDER indicator3[1])
timeframe(default, updateonclose) //1minuto
add = adx[10]>=24.4
period = 7
Num = abs(close-close[Period])
Den = summation[Period](abs(close-close[1]))
ER = Num / Den
Ratio = Er>= 0.9
IF c1 and ratio and add THEN
BUY positionsize CONTRACT AT MARKET
ENDIF
IF c3 and ratio and add THEN
SELLSHORT positionsize CONTRACT AT MARKET
ENDIF
//trailing stop
trailingstop = 60
//resetting variables when no trades are on market
if not onmarket then
MAXPRICE = 0
MINPRICE = close
priceexit = 0
endif
//case SHORT order
if shortonmarket then
MINPRICE = MIN(MINPRICE,close) //saving the MFE of the current trade
if tradeprice(1)-MINPRICE>=trailingstop*pointsize then //if the MFE is higher than the trailingstop then
priceexit = MINPRICE+trailingstop*pointsize //set the exit price at the MFE + trailing stop price level
endif
endif
//case LONG order
if longonmarket then
MAXPRICE = MAX(MAXPRICE,close) //saving the MFE of the current trade
if MAXPRICE-tradeprice(1)>=trailingstop*pointsize then //if the MFE is higher than the trailingstop then
priceexit = MAXPRICE-trailingstop*pointsize //set the exit price at the MFE - trailing stop price level
endif
endif
//exit on trailing stop price levels
if onmarket and priceexit>0 then
EXITSHORT AT priceexit STOP
SELL AT priceexit STOP
priceexit = 0
endif
// Stop e target
SET STOP pLOSS 28