//-------------------------------------------------------------------------
// Main code : US500 Multiple entry multiple exit
//-------------------------------------------------------------------------
DEFPARAM CumulateOrders = true // Cumulating positions activated
defparam preloadbars = 5000
// Conditions to enter long positions
i1 = SmoothedStochastic[509,80](close)//505,80
c1 = i1 crosses over 28//37
c5 = countoflongshares < 2
c6 = longonmarket = 0
IF c1 and c5 and c6 then
BUY 1 CONTRACT AT MARKET
ENDIF
c7 = (positionprice - close) > 1
if c1 and c5 and c7 then
buy 1 contract at market
endif
//Trailing Stop
if barindex > 30 then
i10 = close - positionprice
if i10 > 68 then
llowest = 228//228
else
llowest = 352
endif
i11 = (llowest - (i10 * 3))//409,3 - 4700,30
i12 = round(i11)
i16 = max(1,i12)
i17 = lowest[1](i16)//6
i18 = lowest[i17](low)
C19 = i10 > 17//20
c18 = close crosses under i18[2]//10
IF c18 and c19 THEN
SELL AT MARKET
endif
endif
//tp = a * AverageTrueRange[b](close)
set target pprofit 93