Maurizio-Ciullo

Bot Swing-Trend-Trailing-Riot-P1 ETHUSDT.P BYBIT 4H LONG E SHORT

Sep 13th, 2025 (edited)
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.                                                                 // Bot Swing Trend Trailing Riot Period 1 10-09-2025 ETHUSDT.P BYBIT 4H LONG E SHORT //
  2.                                             // Datafeed Cambiato / Periodi Backtest Cambiati / Inputs Cambiati / Stop Loss Limit Tolto //
  3.                                             // Condizione Long Tolta: and ((close[1] < (media_ema_1 + apertura_minima)) or (low[1] < (media_ema_1 + apertura_minima))) and close > open
  4.                                             // Condizione Short Tolta: and ((close[1] > (media_ema_1 - apertura_minima)) or (high[1] > (media_ema_1 - apertura_minima))) and close < open
  5.  
  6.                     // *** Attezione aclune operazioni potrebbero essere diverse da tradestation perchè tradingview
  7.                     // se esce in trailng stop e allo stesso tempo c'è la condizione di ingresso sulla stessa candela
  8.                     // non effettua uscite ed entrate nella stessa candela in questo caso specifico mentre tradestation si *** !!!
  9.  
  10. // RIOTTIMIZZAZIONE PERIODICA 1 DELLA ORIGINALE SWING TREND TRAILING   
  11. // IL DATAFEED COMPLETO = (18/08/2017 10/08/2025)                                              
  12. // NUOVI DATI DI SVILUPPO DATAFEED ETH/USDT BINANCE + ETH/USDT.P BYBIT 4H  STORICO INIZIALE BINANCE PER POI PROSEGUIRE CON BYBIT                                                                                                                       
  13. // (Sviluppo Dati Exchange = BINANCE + BYBIT) (BINANCE Dal=18/08/2017 Al 10/10/2020) (BYBIT Dal=21/10/2020 Al 10/08/2025)
  14. // SU TRADINGVIEW ORARIO BORSA GMT
  15. // BARSBACK TRADESTATION: 500
  16.  
  17. // NUOVE DATE IN SAMPLE E OUT OF SAMPLE
  18. //Il data feed completo: 18/08/2017 10/08/2025
  19. //In Sample: Inizio 18/08/2017 Fine 12/06/2023
  20. //Out Of Sample: Inizio 13/06/2023 Fine 10/08/2025
  21.  
  22.  
  23. // Il trading system completo - Bot Swing Trend Trailing Riot Period 1 10-09-2025 ETHUSDT.P BYBIT 4H LONG E SHORT
  24. // (Exchange= BYBIT) (Sottostante ETH-USDT.P) (Timeframe= 4H) (Direzione= LONG E SHORT) (Swing Posizione= SI) (Esclusione Ore=NO) (Esclusione Giorni=NO) (Esclusione Mesi=NO)
  25. // (Take Profit Long/Short Market = Trailing) (Take Profit Limit Long/Short= NO)
  26. // (Stop Loss Limit Long/Short= NO) (Stop Loss Market=SI) (Trailing Stop=SI) (Stop Emergenza: NO)
  27. // (Max DD Concesso = 15% Media Max Drawdown 2°nda Deviazione Standard Simulazione Montecalo Python
  28. // (Money Management = 25% Del Capitale Tradestation)  
  29. // (Money Management = 12,00% Del Capitale Tradingview) Preso Dal 15% Media Max Drawdown 2°nda Deviazione Standard Simulazione Montecarlo Python
  30.  
  31. // (In Sample Dal=17/08/2017 12/06/2023) (Out Of Sample Dal13/06/2023 Al 10-08-2025)
  32. // (Progettatta Il=10/09/25)
  33.  
  34.  
  35. input:
  36.   InitialCapital(100000),
  37.   percent_risk(25),
  38.   lunghezza_ema(130), //lunghezza_ema(90), "vecchio parametro"      130 va anche bene ma è meno adatta a questo periodo attuale     "vedi anche 120"          
  39.   //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 !!!
  40.   perc_apertura_minima(2), // perc_apertura_minima(2), "vecchio parametro"
  41.   perc_apertura_massima(3.7),// perc_apertura_massima(4,) "vecchio parametro"
  42.   perc_chiusura_minima(0),  // ERA DISATTIVATO E RIMANE CON LA VECCHIA STRATEGIA E RIMANE DISATTIVATO !!!
  43.   input_trailing_stop_trigger(10),  //  input_trailing_stop_trigger(12),  "vecchio parametro"
  44.   input_trailing_stop_close(6),      // Ottimizzato ma rimane uguale
  45.   input_stop_loss_percent(10),  // Unico Long E Short ma ho deciso di non usarlo in questa versione
  46.   //skipday(saturday),
  47.   //skipmonth1(10),
  48.   //skipmonth2(9),
  49.   solo_long(false),
  50.   solo_short(false);
  51.  
  52. Vars:
  53.  
  54.    media_ema(0),
  55.    //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 !!!
  56.    apertura_minima(0),
  57.    apertura_massima(0),
  58.    chiusura_minima(0),
  59.    stop_loss(0),
  60.    media_ema_1(0),
  61.    trailing_stop_trigger(0),
  62.    trailing_stop_close(0),
  63.    trailing_stop_trigger_long(0),
  64.    trailing_stop_close_long(0),
  65.    trailing_stop_trigger_short(0),
  66.    trailing_stop_close_short(0),
  67.    trailing_long(false),
  68.    trailing_short(false),
  69.    highesthigh(0),
  70.    lowestlow(0),
  71.    ATR(0),
  72.    risk(0),
  73.    posit(0),
  74.    nr_share(0);
  75.    
  76.      
  77.      
  78. // Calcololo degli indicatori
  79.  
  80.   //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 !!!
  81.   media_ema = XAverage(Close, lunghezza_ema);
  82.   apertura_minima   = (media_ema / 100) * perc_apertura_minima;
  83.   apertura_massima  = (media_ema / 100) * perc_apertura_massima;
  84.   media_ema_1 = XAverage(Close[1], lunghezza_ema);
  85.  
  86. // Calcolo Trailing Stop Long E Short
  87.  
  88.   trailing_stop_trigger_long = Entryprice + (entryprice * input_trailing_stop_trigger)/100;
  89.   trailing_stop_close_long = entryprice + (entryprice * input_trailing_stop_close)/100;
  90.   trailing_stop_trigger_short = Entryprice - (entryprice * input_trailing_stop_trigger)/100;
  91.   trailing_stop_close_short = entryprice - (entryprice * input_trailing_stop_close)/100;
  92.  
  93. // Condizione  Trailing Stop Long E Short
  94.   highesthigh = highest(high, Barssinceentry);
  95.   trailing_long = (highesthigh >= trailing_stop_trigger_long and close <= trailing_stop_close_long);
  96.  
  97.   lowestlow = lowest(low, Barssinceentry); 
  98.   trailing_short = (lowestlow <= trailing_stop_trigger_short and close >= trailing_stop_close_short);    
  99.  
  100.  
  101. // Money menagment
  102.  
  103.   risk = percent_risk/100;
  104.   nr_share = floor((InitialCapital + NetProfit) * risk) / close ;
  105.   stop_loss=((((InitialCapital + NetProfit) * risk)/100) * input_stop_loss_percent);
  106.  
  107.  
  108.  //#################################
  109.  // LONG
  110.  //#################################
  111.              
  112. // Entrata Long
  113.  
  114.       // *** ORIGINALE *** //
  115.       //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                                                                                                                                                                  
  116.      
  117.       // *** CONDIZIONE GREZZA CON SOLO MEDIA SEMPRE A MERCATO SENZA FASCE *** //
  118.       //if close > media_ema and not solo_short then// and close > open then
  119.      
  120.       // *** RIOTTIMIZZATA RIOT P1 *** //
  121.       if close > (media_ema + apertura_minima) and close < (media_ema + apertura_massima) and not solo_short then// and close > open then
  122.         Buy ("Long") nr_share contracts Next Bar at market;
  123.      
  124. // Uscita Long
  125.      
  126.      if close < media_ema - chiusura_minima then                                          
  127.        Sell("Chiusura Long") from entry("Long") Next Bar at market;    
  128.      
  129.      // *************** SOTTO PROVA *************** //  
  130.     // 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"
  131.     { 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
  132.         Sell("Chiusura Long 2") from entry("Long") Next Bar at market; }
  133.    
  134.        
  135.   // Uscita Trailing Long
  136.      
  137.     If (MarketPosition =1 and trailing_long) then
  138.         Sell("Trailing Long") from entry("Long") Next Bar at market;
  139.      
  140.      
  141.  //#################################
  142.  // SHORT
  143.  //#################################      
  144.        
  145. // Entrata Short
  146.     // *** ORIGINALE *** //
  147.     //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                                                                                  
  148.    
  149.     // *** CONDIZIONE GREZZA CON SOLO MEDIA SEMPRE A MERCATO SENZA FASCE *** //
  150.     //if close < media_ema and not solo_long then// and close < open then
  151.    
  152.     // *** RIOTTIMIZZATA RIOT P1 *** //
  153.       if close < (media_ema - apertura_minima) and close > (media_ema - apertura_massima) and not solo_long then// and close < open then
  154.         Sellshort ("Short") nr_share contracts Next Bar at market;  
  155.        
  156.        
  157. // Uscita Short
  158.  
  159.      if close > (media_ema + chiusura_minima) then                              
  160.         Buytocover("Chiusura Short") from entry("Short") Next Bar at market;  
  161.        
  162.      // *************** SOTTO PROVA *************** //
  163. // 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"        
  164.    {  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
  165.         Buytocover("Chiusura Short 2") from entry("Short") Next Bar at market; }
  166.      
  167.      
  168.   // Uscita Trailing Short    
  169.      
  170.      If (MarketPosition =-1 and trailing_short) then
  171.         Buytocover("Trailing Short") from entry("Short") Next Bar at market;      
  172.    
  173.       // Stop Loss Non Usato In Questa Versione Di Strategia !!!
  174. //Setstopposition;
  175. //SetStopLoss(stop_loss);
  176.  
  177.  
Advertisement
Add Comment
Please, Sign In to add comment