Buongiorno a tutti!
Ho bisogno del vostro aiuto per creare una strategia di swing trading basata sull’indicatore RSI e che dovrebbe funzionare così :
- Il primo ordine e solo il primo , ad esempio “buy 1 contract” , deve partire quando “RSI crosses over 31.5″ . Il valore del RSI raggiunto in quel momento, va a diventare il valore di chiusura della posizione attraverso questa formula (70-(valore iniziale-30)) . Quindi quando ” RSI crosses over valore di chiusura” , la posizione si chiude, e il valore del RSI in quel momento diventa il valore di apertura del secondo ordine “sellshort 1 contract”.
- Il secondo ordine verrà aperto quando “RSI crosses under valore di apertura” , e il valore del RSI in quel momento, va a diventare il valore di chiusura della seconda posizione attraverso la formula (30+(70-valore iniziale)) .
- E così via. Il valore di apertura genera un valore di chiusura, e il valore effettivo nella chiusura diventa il valore di apertura della posizione successiva
Ecco:
// RSI apertura & chiusura
//
DEFPARAM CumulateOrders = false
DEFPARAM PreLoadBars = 0
ONCE RSIapertura = 31.5
ONCE RSIchiusura = 0
ONCE LastTrade = 0
MyRSI = rsi[14](close)
IF MyRSI CROSSES OVER RSIapertura AND LastTrade = 0 AND Not OnMarket THEN
LastTrade = 1
RSIchiusura = 70 - (RSIapertura - 30)
BUY 1 CONTRACT AT MARKET
ENDIF
IF MyRSI CROSSES OVER RSIchiusura AND LongOnMarket AND LastTrade = 1 THEN
SELL AT MARKET
RSIapertura = MyRSI
ENDIF
IF MyRSI CROSSES UNDER RSIapertura AND LastTrade = 1 AND Not OnMarket THEN
RSIchiusura = 30 + (70 - RSIapertura)
SELLSHORT 1 CONTRACT AT MARKET
ENDIF
IF MyRSI CROSSES UNDER RSIchiusura AND ShortOnMarket AND LastTrade = 1 THEN
EXITSHORT AT MARKET
RSIapertura = MyRSI
LastTrade = 0
ENDIF
/* multiline comments are now available
SET TARGET pPROFIT 400
SET STOP pLOSS 100
graph MyRsi AS "Rsi"
graph RSIapertura
graph RSIchiusura
*/
Grazie Roberto ! Sempre gentilissimo. Ora provo…