Buon giorno, ho un problema grazie per chi mi vuole aiutare.
ho settato il sistema che deve aprire posizioni solo di lunedì, fin qui tutto bene,
vorrei anche che il sistema incrementa la posizione su nuovo segnale al lunedì successivo
// Definizione dei parametri del codice
DEFPARAM CumulateOrders = False
// IL SISTEMA SI ATTIVA ALLE 02:00 . NON IMMETTE ORDINI DOPO LE 20:00.
cTime = Time >= 020000 And Time < 200000
// 1 SOLA TRADE AL DIORNO
Otd = (Barindex - TradeIndex(1) > IntradayBarIndex)
// GIORNO TRADABILE: LUNEDI'
daysForbiddenEntry = OpenDayOfWeek = 2 OR OpenDayOfWeek = 3 OR OpenDayOfWeek = 4 OR OpenDayOfWeek = 5 OR OpenDayOfWeek = 6 OR OpenDayOfWeek = 0
// CONDIZIONI
indicator1 = SuperTrend[3,10]
c1 = (close[1] CROSSES OVER indicator1)
//COMANDI
IF c1 AND not daysForbiddenEntry AND Otd AND cTime AND Not OnMarket THEN
BUY 1 CONTRACT AT MARKET
ENDIF
//************************************************************************
//trailing stop function
trailingstart =100//trailing will start @trailinstart points profit
trailingstep = 10//trailing step to move the "stoploss"
//reset the stoploss value
IF NOT ONMARKET THEN
newSL=0
ENDIF
//manage long positions
IF LONGONMARKET THEN
//first move (breakeven)
IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THEN
newSL = tradeprice(1)+trailingstep*pipsize
ENDIF
//next moves
IF newSL>0 AND close-newSL>=trailingstep*pipsize THEN
newSL = newSL+trailingstep*pipsize
ENDIF
ENDIF
//stop order to exit the positions
IF newSL>0 THEN
SELL AT newSL STOP
EXITSHORT AT newSL STOP
ENDIF
//************************************************************************
Eccolo, ogni lunedì incrementa una posizione (devi dirgli te la condizione per terminare l’increnentoi:
// Definizione dei parametri del codice
DEFPARAM CumulateOrders = False
ONCE Lotti = 0
// IL SISTEMA SI ATTIVA ALLE 02:00 . NON IMMETTE ORDINI DOPO LE 20:00.
cTime = Time >= 020000 And Time < 200000
// 1 SOLA TRADE AL DIORNO
Otd = (Barindex - TradeIndex(1) > IntradayBarIndex)
// GIORNO TRADABILE: LUNEDI'
daysForbiddenEntry = OpenDayOfWeek = 2 OR OpenDayOfWeek = 3 OR OpenDayOfWeek = 4 OR OpenDayOfWeek = 5 OR OpenDayOfWeek = 6 OR OpenDayOfWeek = 0
// CONDIZIONI
indicator1 = SuperTrend[3,10]
c1 = (close[1] CROSSES OVER indicator1)
//COMANDI
IF c1 AND not daysForbiddenEntry AND Otd AND cTime AND Not OnMarket THEN
Lotti = Lotti + 1
BUY Lotti CONTRACT AT MARKET
ENDIF
//************************************************************************
//trailing stop function
trailingstart =100//trailing will start @trailinstart points profit
trailingstep = 10//trailing step to move the "stoploss"
//reset the stoploss value
IF NOT ONMARKET THEN
newSL=0
ENDIF
//manage long positions
IF LONGONMARKET THEN
//first move (breakeven)
IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THEN
newSL = tradeprice(1)+trailingstep*pipsize
ENDIF
//next moves
IF newSL>0 AND close-newSL>=trailingstep*pipsize THEN
newSL = newSL+trailingstep*pipsize
ENDIF
ENDIF
//stop order to exit the positions
IF newSL>0 THEN
SELL AT newSL STOP
EXITSHORT AT newSL STOP
ENDIF
Grazie Roberto della disponibilità e sempre gentilissimo.
ho provato in tutti i modi ma non riesco a creare la condizione di uscita.
la condizione per terminare l’incremento deve essere la stessa modalità che si esegue per una condizione, cioè al raggiungimento del trailingstart, trailingstep.
Basta che sostituisci la riga 16 con:
IF NewSL = 0 THEN
Lotti = Lotti + 1
ENDIF
Se vuoi fare ripartire da 1 il numero di lotti quando non sei a mercato, basta che aggiungi, subito dopo (o immediatamente prima) la riga 26:
Lotti = 0
// Definizione dei parametri del codice
DEFPARAM CumulateOrders = False
ONCE Lotti = 0
// IL SISTEMA SI ATTIVA ALLE 07:00 . NON IMMETTE ORDINI DOPO LE 20:00.
cTime = Time >= 070000 And Time < 200000
// 1 SOLA TRADE AL DIORNO
Otd = (Barindex - TradeIndex(1) > IntradayBarIndex)
// GIORNO TRADABILE: LUNEDI'
daysForbiddenEntry = OpenDayOfWeek = 2 OR OpenDayOfWeek = 3 OR OpenDayOfWeek = 4 OR OpenDayOfWeek = 5 OR OpenDayOfWeek = 6 OR OpenDayOfWeek = 0
// CONDIZIONI
indicator1 = SuperTrend[2,10]
c1 = (close[1] CROSSES OVER indicator1)
indicator2 = ExponentialAverage[200](close)
c2 = (close[1] > indicator2)
c3 = (high[1] > open [30])
//COMANDI
IF c1 AND c2 and c3 AND not daysForbiddenEntry AND Otd AND cTime AND Not OnMarket THEN
IF NewSL = 0 THEN
Lotti = Lotti + 1
ENDIF
BUY Lotti CONTRACT AT MARKET
ENDIF
//STOP LOSS
SET STOP PLOSS 280
//************************************************************************
//trailing stop function
trailingstart =130//trailing will start @trailinstart points profit
trailingstep = 20//trailing step to move the "stoploss"
//reset the stoploss value
IF NOT ONMARKET THEN
Lotti = 0
newSL=0
ENDIF
//manage long positions
IF LONGONMARKET THEN
//first move (breakeven)
IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THEN
newSL = tradeprice(1)+trailingstep*pipsize
ENDIF
//next moves
IF newSL>0 AND close-newSL>=trailingstep*pipsize THEN
newSL = newSL+trailingstep*pipsize
ENDIF
ENDIF
//stop order to exit the positions
IF newSL>0 THEN
SELL AT newSL STOP
EXITSHORT AT newSL STOP
ENDIF
//************************************************************************
Buon giorno Roberto, ho inserito il codice ma non funziona. Sto sbagliando sicuramente qualcosa. Grazie
In pratica acquista 1 lotto, appena l’operazione termina riazzera LOTTI, per cui ripartirà sempre da 1 lotto.
Cosa non funziona esattamente? Cosa vuoi che faccia (che adesso non fa)? oppure cosa sta facendo che, invece, tu non vuoi che faccia?
io voglio dire al sistema di aprire nuove posizioni ogni volta che si attiva un nuovo segnale.
faccio un esempio: c’e’ 1 posizione aperta e vorrei che al lunedi’ successivo se si verifica un nuovo segnale di aprire un altra posizione, di chiudere le posizione al raggiungimento del target o stop loss.
Grazie
Capito. In tal caso va abilitato con TRUE l’accumulo di posizioni. LOTTI è sempre 1, sono le posizioni che incrementano, non il loro taglio.
Ho aggiunto anche un target, visto che ne hai parlato:
// Definizione dei parametri del codice
DEFPARAM CumulateOrders = true
ONCE Lotti = 1
// IL SISTEMA SI ATTIVA ALLE 07:00 . NON IMMETTE ORDINI DOPO LE 20:00.
cTime = Time >= 070000 And Time < 200000
// 1 SOLA TRADE AL DIORNO
Otd = (Barindex - TradeIndex(1) > IntradayBarIndex)
// GIORNO TRADABILE: LUNEDI'
daysForbiddenEntry = OpenDayOfWeek = 2 OR OpenDayOfWeek = 3 OR OpenDayOfWeek = 4 OR OpenDayOfWeek = 5 OR OpenDayOfWeek = 6 OR OpenDayOfWeek = 0
// CONDIZIONI
indicator1 = SuperTrend[2,10]
c1 = (close[1] CROSSES OVER indicator1)
indicator2 = ExponentialAverage[200](close)
c2 = (close[1] > indicator2)
c3 = (high[1] > open [30])
//COMANDI
IF c1 AND c2 and c3 AND not daysForbiddenEntry AND Otd AND cTime THEN
BUY Lotti CONTRACT AT MARKET
ENDIF
//STOP LOSS
SET STOP PLOSS 280
SET TARGET PPROFIT 840
//************************************************************************
//trailing stop function
trailingstart = 130//trailing will start @trailinstart points profit
trailingstep = 20//trailing step to move the "stoploss"
//reset the stoploss value
IF NOT ONMARKET THEN
newSL=0
ENDIF
//manage long positions
IF LONGONMARKET THEN
//first move (breakeven)
IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THEN
newSL = tradeprice(1)+trailingstep*pipsize
ENDIF
//next moves
IF newSL>0 AND close-newSL>=trailingstep*pipsize THEN
newSL = newSL+trailingstep*pipsize
ENDIF
ENDIF
//stop order to exit the positions
IF newSL>0 THEN
SELL AT newSL STOP
EXITSHORT AT newSL STOP
ENDIF
//************************************************************************
Roberto grazie e gentilissimo come sempre preciso per le risposte,
scusami come target intendevo al raggiungimento del trailingstart, trailingstep.