defparam preloadbars =4000
// Conditions to enter long positions
indicator1 = close
indicator2 = TriangularAverage[4000](close)
c1 = (indicator1 > indicator2)
c2 = (indicator1 < indicator2)
IF c1 THEN
BUY 1 CONTRACT AT MARKET
ENDIF
IF c2 THEN
sellshort 1 CONTRACT AT MARKET
ENDIF
// Counts the number of open shares or lots.
MAXSHARES = COUNTOFPOSITION <= 3
//let's add another order while price continue to get higher (more than 10 points)than the last order taken with a condition of 5 bars elapsed since then
IF TRADEINDEX(1)>n AND Close-TRADEPRICE(1)>10 AND LongOnMarket AND MAXSHARES THEN
BUY 1 SHARES AT MARKET
ENDIF
//let's add another order while price continue to get lower (more than 10 points) than the last order taken with a condition of 5 bars elapsed since then
IF TRADEINDEX(1)>n AND TRADEPRICE(1)-Close>10 AND ShortOnMarket AND MAXSHARES THEN
SELLSHORT 1 SHARES AT MARKET
ENDIF
//trailing stop for the whole orders
SET STOP pTRAILING 15