Maurizio-Ciullo

Bot Swing-Trend ETH/PERP FTX 4H LONG E SHORT

Jun 19th, 2022 (edited)
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Codice su cross del prezzo sulla media
  2. // Il trading system completo - Swing-Trend (Strategia Trend Following Con Swing Di Posizione) - parte 1
  3. // (Exchange= FTX) (Sottostante ETH-PERP) (Timeframe= 4H) (Direzione= LONG E SHORT) (Swing Posizione= SI) (Esclusione Giorni=Sabato) (Esclusione Mesi=Ottobre)
  4. //Fase iniziale parametri di input
  5.  
  6. input:
  7.     InitialCapital(100000),
  8.     percent_risk(25),
  9.     input_stop_loss_percent(2.5),
  10.     lunghezza_ema_long(45),
  11.     lunghezza_ema_long_chiusura(35),
  12.     lunghezza_ema_short(40),
  13.     lunghezza_ema_short_chiusura(30),
  14.     perc_apertura_minima_long(0),
  15.     perc_apertura_massima_long(2),
  16.     perc_chiusura_minima_long(1.5),
  17.     perc_apertura_minima_short(0.75),
  18.     perc_apertura_massima_short(2),
  19.     perc_chiusura_minima_short(1),
  20.     skipday(saturday),
  21.     skipmonth1(10),
  22.     //skipmonth2(9),
  23.     solo_long(false),
  24.     solo_short(false);
  25.    
  26. Vars:
  27.      ema_long(0),
  28.      ema_long_chiusura(0),
  29.      ema_short(0),
  30.      ema_short_chiusura(0),
  31.      apertura_minima_long(0),
  32.      apertura_massima_long(0),
  33.      chiusura_minima_long(0),
  34.      apertura_minima_short(0),
  35.      apertura_massima_short(0),
  36.      chiusura_minima_short(0),
  37.      stop_loss(0),
  38.      ATR(0),
  39.      account_equity(0),
  40.      risk(0),
  41.      nr_share(0),
  42.      SharesByPercentRisk(0),
  43.      market_price(0);    
  44.      
  45.    
  46.  
  47. // Calcololo degli indicatori
  48.      
  49.      ema_long = XAverage(Close, lunghezza_ema_long);
  50.      ema_short = XAverage(Close, lunghezza_ema_short); 
  51.      ema_long_chiusura = XAverage(Close, lunghezza_ema_long_chiusura);
  52.      ema_short_chiusura = XAverage(Close, lunghezza_ema_short_chiusura);
  53.    
  54.      
  55.    
  56.  
  57. // calcolo dei filtri in percentuale
  58.  
  59.     apertura_minima_long   = (ema_long / 100) * perc_apertura_minima_long;
  60.     apertura_massima_long  = (ema_long / 100) * perc_apertura_massima_long;
  61.    
  62.     chiusura_minima_long   = (ema_long_chiusura / 100) * perc_chiusura_minima_long;
  63.    
  64.     apertura_minima_short   = (ema_short / 100) * perc_apertura_minima_short;
  65.     apertura_massima_short  = (ema_short / 100) * perc_apertura_massima_short;
  66.    
  67.     chiusura_minima_short   = (ema_short_chiusura / 100) * perc_chiusura_minima_short;
  68.    
  69.    
  70.  
  71.    
  72.    
  73.    
  74.     risk = percent_risk/100;
  75.     nr_share = floor((InitialCapital + NetProfit) * risk) / close;
  76.     stop_loss=((((InitialCapital + NetProfit) * risk)/100) * input_stop_loss_percent);
  77.    
  78.    
  79.    
  80. // Entrata Long
  81.    
  82.         if close > (ema_long+apertura_minima_long) and close < (ema_long + apertura_massima_long) and close > open and not solo_short {and Dayofweek(date) <> skipday and month(date) <> skipmonth1 and Dayofmonth(date) > 5} then
  83.             Buy("Long") nr_share contracts Next Bar at market;
  84.        
  85.        
  86. // Uscita Long
  87.          
  88.         if close < (ema_long_chiusura - chiusura_minima_long) then
  89.             Sell("Chiusura Long") from entry("Long") Next Bar at market;
  90.        
  91.            
  92. // Entrata Short
  93.    
  94.    
  95.         if  close < (ema_short - apertura_minima_short) and close > (ema_short - apertura_massima_short) and close < open and not solo_long {and Dayofweek(date) <> skipday and month(date) <> skipmonth1 and Dayofmonth > 5} then
  96.             Sellshort("Short") nr_share Contracts Next Bar at market;
  97.                
  98.        
  99. // Uscita Short
  100.  
  101.         if close > (ema_short_chiusura + chiusura_minima_short) then
  102.             Buytocover("Chiusura Short") from entry("Short") Next Bar at market;
  103.          
  104.                
  105.     Setstopposition;
  106.     SetStopLoss(stop_loss);
Add Comment
Please, Sign In to add comment