DEFPARAM CumulateOrders = false
ONCE EntryLong = 0
ONCE EntryShort = 0
ONCE Distanza = 2 * pipsize //2 pips oltre i minimi/massimi per lo Stop Loss
IF OnMarket THEN
EntryLong = 0
EntryShort = 0
ENDIF
Rialzista = close > open
Ribassista = open > close
BarreDiverse = (Rialzista AND Ribassista[1]) OR (Rialzista[1] AND Ribassista)
InsideBAR = high[1] >= max(open,close) AND low[1] <= min(open,close) AND BarreDiverse
IF InsideBAR AND Not OnMarket THEN
EntryLong = high[1]
EntryShort = low[1]
Sl = (Range[1] + Distanza) / pipsize//Stop Loss = range della candela Madre + N pips
Tp = range / pipsize //Target Profit = range della candela inside
ENDIF
// Ordine pendente LONG
IF Not OnMarket AND EntryLong THEN
IF close > EntryLong THEN
BUY 1 CONTRACT AT EntryLong LIMIT //ordine LIMIT se ad un prezzo migliore
ELSIF close < EntryLong THEN
BUY 1 CONTRACT AT EntryLong STOP //ordine STOP se ad un prezzo peggiore
ELSE
BUY 1 CONTRACT AT MARKET //ordine a mercato se identici
ENDIF
ENDIF
// Ordine pendente SHORT
IF Not OnMarket AND EntryShort THEN
IF close < EntryShort THEN
SELLSHORT 1 CONTRACT AT EntryShort LIMIT //ordine LIMIT se ad un prezzo migliore
ELSIF close > EntryShort THEN
SELLSHORT 1 CONTRACT AT EntryShort STOP //ordine STOP se ad un prezzo peggiore
ELSE
SELLSHORT 1 CONTRACT AT MARKET //ordine a mercato se identici
ENDIF
ENDIF
SET TARGET pPROFIT Tp
SET STOP pLOSS Sl