//-------------------------------------------------------------------------
// Codice principale : frattali Williams
//-------------------------------------------------------------------------
DEFPARAM CumulateOrders = true
once cp = 2
// trend di "fondo"
TIMEFRAME (4 hour, updateonclose)
st=Supertrend[3,10]
em=ExponentialAverage[21](close)
if close > st and close > em then
longok = 1
shortok = 0
endif
if close < st and close < em then
shortok = 1
longok = 0
endif
TIMEFRAME (default)
//
ONCE HIL1 = 0
ONCE HIL2 = 0
ONCE LOL1 = 0
ONCE LOL2 = 0
if high[cp] >= highest[2*cp+1](high) then
//uscita da LONG
IF LongOnMarket THEN
IF high[cp] < HIL2 THEN
SELL AT Market
cumul = 0
ENDIF
ENDIF
//
HIL2 = HIL1
HIL1 = high[cp]
endif
if low[cp] <= lowest[2*cp+1](low) then
//uscita da SHORT
IF ShortOnMarket THEN
IF low[cp] > LOL2 THEN
EXITSHORT AT Market
cumul = 0
ENDIF
ENDIF
//
LOL2 = LOL1
LOL1 = low[cp]
endif
//
IF Not OnMarket THEN
cumul = 0
ENDIF
// condizioni entrata long
if longok AND (not onmarket or cumul) AND (HIL1 > HIL2) AND (LOL1 > LOL2) then
buy at market
set stop price LOL1 - 15*pointsize
endif
// condizioni entrata short
if shortok AND (not onmarket or cumul) AND (HIL1 < HIL2) AND (LOL1 < LOL2) then
sellshort at market
set stop price HIL1 - 15*pointsize
endif
// posizione a breakeven dopo zz di guadagno; se a breakeven consentire apertura altre posizioni (cumul=1)
if longonmarket then
if close - TRADEPRICE >= 40 then
set stop BreakEven
cumul = 1
endif
endif
if shortonmarket then
if TRADEPRICE - close>= 40 then
set stop BreakEven
cumul = 1
endif
endif