DEFPARAM CumulateOrders = False
// ---------------------------------------------------------------------
// Swing points long
// ---------------------------------------------------------------------
// --- calcola Lotti
Once Lotti = 1
// ---------------------------------------------------------------------
// Swing points long type 1
c1 = (close>close[1] and close[1]<close[2])
c2 = (close[2]>close[3] and close[3]<close[4])
c3 = (close>close[2] and close[1]>close[3])
EntryLongType1 = c1 AND c2 AND c3
// Swing points long type 2
c4=(close>close[1] and close[1]<close[2])
c5=(close[2]>close[3] and close[3]<close[4])
c6=(close>close[2] and close[1]<close[3])
EntryLongType2 = c4 AND c5 AND c6
// ---------------------------------------------------------------------
// --- Strategia
Long = EntryLongType1 OR EntryLongType2
// ---------------------------------------------------------------------
// Condizioni per entrare su posizioni long
IF NOT LongOnMarket AND Long THEN
BUY Lotti CONTRACTS AT MARKET NEXTBAROPEN
ENDIF
// ---------------------------------------------------------------------
// Stop e target:
//trailing stop function
trailingstart = 20 //trailing stop iniziale
trailingstep = 5 //passo per spostare lo "stoploss"
//reset StopLoss
IF NOT ONMARKET THEN
newSL=0
ENDIF
//gestione posizione Long
IF LONGONMARKET THEN
IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THEN
newSL = tradeprice(1)+trailingstep*pipsize
ENDIF
IF newSL>0 AND close-newSL>=trailingstep*pipsize THEN
newSL = newSL+trailingstep*pipsize
ENDIF
ENDIF
IF newSL>0 THEN
SELL AT newSL STOP
ENDIF
// ---------------------------------------------------------------------