Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Bot Swing Trend Trailing Riot Period 1 10-09-2025 ETHUSDT.P BYBIT 4H LONG E SHORT //
- // Datafeed Cambiato / Periodi Backtest Cambiati / Inputs Cambiati / Stop Loss Limit Tolto //
- // Condizione Long Tolta: and ((close[1] < (media_ema_1 + apertura_minima)) or (low[1] < (media_ema_1 + apertura_minima))) and close > open
- // Condizione Short Tolta: and ((close[1] > (media_ema_1 - apertura_minima)) or (high[1] > (media_ema_1 - apertura_minima))) and close < open
- // *** Attezione aclune operazioni potrebbero essere diverse da tradestation perchè tradingview
- // se esce in trailng stop e allo stesso tempo c'è la condizione di ingresso sulla stessa candela
- // non effettua uscite ed entrate nella stessa candela in questo caso specifico mentre tradestation si *** !!!
- // RIOTTIMIZZAZIONE PERIODICA 1 DELLA ORIGINALE SWING TREND TRAILING
- // IL DATAFEED COMPLETO = (18/08/2017 10/08/2025)
- // NUOVI DATI DI SVILUPPO DATAFEED ETH/USDT BINANCE + ETH/USDT.P BYBIT 4H STORICO INIZIALE BINANCE PER POI PROSEGUIRE CON BYBIT
- // (Sviluppo Dati Exchange = BINANCE + BYBIT) (BINANCE Dal=18/08/2017 Al 10/10/2020) (BYBIT Dal=21/10/2020 Al 10/08/2025)
- // SU TRADINGVIEW ORARIO BORSA GMT
- // BARSBACK TRADESTATION: 500
- // NUOVE DATE IN SAMPLE E OUT OF SAMPLE
- //Il data feed completo: 18/08/2017 10/08/2025
- //In Sample: Inizio 18/08/2017 Fine 12/06/2023
- //Out Of Sample: Inizio 13/06/2023 Fine 10/08/2025
- // Il trading system completo - Bot Swing Trend Trailing Riot Period 1 10-09-2025 ETHUSDT.P BYBIT 4H LONG E SHORT
- // (Exchange= BYBIT) (Sottostante ETH-USDT.P) (Timeframe= 4H) (Direzione= LONG E SHORT) (Swing Posizione= SI) (Esclusione Ore=NO) (Esclusione Giorni=NO) (Esclusione Mesi=NO)
- // (Take Profit Long/Short Market = Trailing) (Take Profit Limit Long/Short= NO)
- // (Stop Loss Limit Long/Short= NO) (Stop Loss Market=SI) (Trailing Stop=SI) (Stop Emergenza: NO)
- // (Max DD Concesso = 15% Media Max Drawdown 2°nda Deviazione Standard Simulazione Montecalo Python
- // (Money Management = 25% Del Capitale Tradestation)
- // (Money Management = 12,00% Del Capitale Tradingview) Preso Dal 15% Media Max Drawdown 2°nda Deviazione Standard Simulazione Montecarlo Python
- // (In Sample Dal=17/08/2017 12/06/2023) (Out Of Sample Dal13/06/2023 Al 10-08-2025)
- // (Progettatta Il=10/09/25)
- input:
- InitialCapital(100000),
- percent_risk(25),
- lunghezza_ema(130), //lunghezza_ema(90), "vecchio parametro" 130 va anche bene ma è meno adatta a questo periodo attuale "vedi anche 120"
- //lunghezza_ema_chiusura_veloce(90), // CANCELLARE !!! SOLO PROVA PER USCIRE PIU' VELOCE, **** ATTENZIONE NON METTERE UNA MEDIA INFERIORE DI TROPPO AL 90 ALTRIMENTI INVECE DI CHIUDERE SOLO PIU' VELOCE LE GRANDI OPERAZIONI IN PROFITTO, APPENA SUPERO IL TRIGGER CHIUDO TROPPO VELOCE CON LA MEDIA ROVINANDO LA STRATEGIA !!!
- perc_apertura_minima(2), // perc_apertura_minima(2), "vecchio parametro"
- perc_apertura_massima(3.7),// perc_apertura_massima(4,) "vecchio parametro"
- perc_chiusura_minima(0), // ERA DISATTIVATO E RIMANE CON LA VECCHIA STRATEGIA E RIMANE DISATTIVATO !!!
- input_trailing_stop_trigger(10), // input_trailing_stop_trigger(12), "vecchio parametro"
- input_trailing_stop_close(6), // Ottimizzato ma rimane uguale
- input_stop_loss_percent(10), // Unico Long E Short ma ho deciso di non usarlo in questa versione
- //skipday(saturday),
- //skipmonth1(10),
- //skipmonth2(9),
- solo_long(false),
- solo_short(false);
- Vars:
- media_ema(0),
- //ema_chiusura_veloce(0), // CANCELLARE !!! SOLO PROVA PER USCIRE PIU' VELOCE, **** ATTENZIONE NON METTERE UNA MEDIA INFERIORE DI TROPPO AL 90 ALTRIMENTI INVECE DI CHIUSERE SOLO PIU' VELOCE LE GRANDI OPERAZIONI IN PROFITTO, APPENA SUPERO IL TRIGGER CHIUDO TROPPO VELOCE CON LA MEDIA ROVINANDO LA STRATEGIA !!!
- apertura_minima(0),
- apertura_massima(0),
- chiusura_minima(0),
- stop_loss(0),
- media_ema_1(0),
- trailing_stop_trigger(0),
- trailing_stop_close(0),
- trailing_stop_trigger_long(0),
- trailing_stop_close_long(0),
- trailing_stop_trigger_short(0),
- trailing_stop_close_short(0),
- trailing_long(false),
- trailing_short(false),
- highesthigh(0),
- lowestlow(0),
- ATR(0),
- risk(0),
- posit(0),
- nr_share(0);
- // Calcololo degli indicatori
- //ema_chiusura_veloce = XAverage(Close, lunghezza_ema_chiusura_veloce); // CANCELLARE !!! SOLO PROVA PER USCIRE PIU' VELOCE, **** ATEENZIONE NON METTERE UNA MEDIA INFERIORE DI TROPPO AL 90 ALTRIMENTI INVECE DI CHIUSERE SOLO PIU' VELOCE LE GRANDI OPERAZIONI IN PROFITTO, APPENA SUPERO IL TRIGGER CHIUDO TROPPO VELOCE CON LA MEDIA ROVINANDO LA STRATEGIA !!!
- media_ema = XAverage(Close, lunghezza_ema);
- apertura_minima = (media_ema / 100) * perc_apertura_minima;
- apertura_massima = (media_ema / 100) * perc_apertura_massima;
- media_ema_1 = XAverage(Close[1], lunghezza_ema);
- // Calcolo Trailing Stop Long E Short
- trailing_stop_trigger_long = Entryprice + (entryprice * input_trailing_stop_trigger)/100;
- trailing_stop_close_long = entryprice + (entryprice * input_trailing_stop_close)/100;
- trailing_stop_trigger_short = Entryprice - (entryprice * input_trailing_stop_trigger)/100;
- trailing_stop_close_short = entryprice - (entryprice * input_trailing_stop_close)/100;
- // Condizione Trailing Stop Long E Short
- highesthigh = highest(high, Barssinceentry);
- trailing_long = (highesthigh >= trailing_stop_trigger_long and close <= trailing_stop_close_long);
- lowestlow = lowest(low, Barssinceentry);
- trailing_short = (lowestlow <= trailing_stop_trigger_short and close >= trailing_stop_close_short);
- // Money menagment
- risk = percent_risk/100;
- nr_share = floor((InitialCapital + NetProfit) * risk) / close ;
- stop_loss=((((InitialCapital + NetProfit) * risk)/100) * input_stop_loss_percent);
- //#################################
- // LONG
- //#################################
- // Entrata Long
- // *** ORIGINALE *** //
- //if close > (media_ema + apertura_minima) and close < (media_ema + apertura_massima) and ((close[1] < (media_ema_1 + apertura_minima)) or (low[1] < (media_ema_1 + apertura_minima))) and close > open and not solo_short then
- // *** CONDIZIONE GREZZA CON SOLO MEDIA SEMPRE A MERCATO SENZA FASCE *** //
- //if close > media_ema and not solo_short then// and close > open then
- // *** RIOTTIMIZZATA RIOT P1 *** //
- if close > (media_ema + apertura_minima) and close < (media_ema + apertura_massima) and not solo_short then// and close > open then
- Buy ("Long") nr_share contracts Next Bar at market;
- // Uscita Long
- if close < media_ema - chiusura_minima then
- Sell("Chiusura Long") from entry("Long") Next Bar at market;
- // *************** SOTTO PROVA *************** //
- // Uscita Long 2 "PROVA CHIUSURA CON MEDIA PIù VELOCE DELLA 130 SOLO SE HIGHESTHIGH >= TRAILING_STOP_TRIGGER_LONG "SE HO TOCCATO IL TRIGGER ENTRA IN AZIONE UNA MEDIA PIù VELOCE PER CHIUDERE IN PROFITTO PRIMA"
- { if (MarketPosition =1 and (highesthigh >= trailing_stop_trigger_long) and (close < ema_chiusura_veloce - chiusura_minima)) then // PROVA CHIUSURA MEDIA PIù VELOCE SE SE INNESCATO IL TRIGGER
- Sell("Chiusura Long 2") from entry("Long") Next Bar at market; }
- // Uscita Trailing Long
- If (MarketPosition =1 and trailing_long) then
- Sell("Trailing Long") from entry("Long") Next Bar at market;
- //#################################
- // SHORT
- //#################################
- // Entrata Short
- // *** ORIGINALE *** //
- //if close < (media_ema - apertura_minima) and close > (media_ema - apertura_massima) and ((close[1] > (media_ema_1 - apertura_minima)) or (high[1] > (media_ema_1 - apertura_minima))) and close < open and not solo_long {and Dayofweek(date) <> skipday and month(date) <> skipmonth1 and Dayofmonth > 5} then
- // *** CONDIZIONE GREZZA CON SOLO MEDIA SEMPRE A MERCATO SENZA FASCE *** //
- //if close < media_ema and not solo_long then// and close < open then
- // *** RIOTTIMIZZATA RIOT P1 *** //
- if close < (media_ema - apertura_minima) and close > (media_ema - apertura_massima) and not solo_long then// and close < open then
- Sellshort ("Short") nr_share contracts Next Bar at market;
- // Uscita Short
- if close > (media_ema + chiusura_minima) then
- Buytocover("Chiusura Short") from entry("Short") Next Bar at market;
- // *************** SOTTO PROVA *************** //
- // Uscita Long 2 "PROVA CHIUSURA CON MEDIA PIù VELOCE DELLA 130 SOLO SE LOWESTLOW <= TRAILING_STOP_TRIGGER_SHORT "SE HO TOCCATO IL TRIGGER ENTRA IN AZIONE UNA MEDIA PIù VELOCE PER CHIUDERE IN PROFITTO PRIMA"
- { if (MarketPosition =-1 and (lowestlow <= trailing_stop_trigger_short) and (close > ema_chiusura_veloce + chiusura_minima)) then // PROVA CHIUSURA MEDIA PIù VELOCE SE SE INNESCATO IL TRIGGER
- Buytocover("Chiusura Short 2") from entry("Short") Next Bar at market; }
- // Uscita Trailing Short
- If (MarketPosition =-1 and trailing_short) then
- Buytocover("Trailing Short") from entry("Short") Next Bar at market;
- // Stop Loss Non Usato In Questa Versione Di Strategia !!!
- //Setstopposition;
- //SetStopLoss(stop_loss);
Advertisement
Add Comment
Please, Sign In to add comment