Advertisement
Maurizio-Ciullo

Bot Break-in-New-Trailing-Gabriele Ver-5 ETH/PERP FTX 4H LONG E SHORT

May 7th, 2022 (edited)
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  2.  
  3. //Il trading system completo - Bot Break-in-New-Trailing-Gabriele Ver-5 (Strategia Breakout) Parte 1
  4. // (Exchange= FTX) (Sottostante ETH-PERP) (Timeframe= 4H) (Direzione= LONG E SHORT) (Swing Posizione= SI) (Esclusione Ore=NO) (Esclusione Giorni=NO') (Esclusione Mesi=NO)
  5. // (Take Profit Long/Short Market = Trailing) (Take Profit Limit Long/Short= +18%) (Stop Loss Limit Long/Short= -12%) (Stop Loss Market Long/Short= NO) (Trailing Stop=SI) (Stop Emergenza= NO)
  6. // (Rischio Operazione 2% Perdita Media)
  7. // (In Sample Dal=17/08/2017 Al 17/10/2020) (Out Of Sample Dal=18/10/2020 Al 15/03/2021)
  8.  
  9. // Auentare il Max Bars Back Su Tradestation Altrimenti Non Funziona Il Conteggio Barssinceentry 500
  10. // Abilitare Anche Enable Strategy Da Stadies Per Ricaricarla Altrimenti Non Funziona
  11.  
  12. //Fase iniziale parametri di input
  13. input:
  14.     InitialCapital(100000),
  15.     percent_risk(8.8), 
  16.     input_stop_loss_percent_long(12),
  17.     input_target_percent_long(18),
  18.     input_stop_loss_percent_short(12),
  19.     input_target_percent_short(18),
  20.     input_trailing_trigger_long(60),
  21.     input_trailing_close_long (54),
  22.     input_trailing_trigger_short (60),
  23.     input_trailing_close_short (54),
  24.     lunghezza_ema_long (240),
  25.     lunghezza_ema_short (240), 
  26.     input_atr_perdiod_long(11),
  27.     input_atr_perdiod_short(11),
  28.     input_atr_mult_long(1),
  29.     input_atr_mult_short(1),
  30.     //skipday(thursday),
  31.     //skipmonth1(9),
  32.     //skipmonth2(8),
  33.     //skipday(monday),
  34.     solo_long(false),
  35.     solo_short(false);
  36.  
  37. Vars:
  38.      
  39.      stop_loss_long(0),
  40.      stop_loss_short(0),
  41.      target_long(0),
  42.      target_short(0),
  43.      ema_long(0),
  44.      ema_short(0),
  45.      valore_atr_long(0),
  46.      valore_atr_short(0),
  47.      trailing_stop_trigger_long(0),
  48.      trailing_stop_close_long(0),
  49.      trailing_stop_trigger_short(0),
  50.      trailing_stop_close_short(0),
  51.      trailing_long(false),
  52.      trailing_short(false),
  53.      highesthigh(0),
  54.      lowestlow(0),
  55.      account_equity(0),
  56.      risk(0),
  57.      nr_share(0);
  58.      
  59. // Calcololo degli indicatori long
  60.    
  61.  
  62. valore_atr_long      =   AvgTrueRange(input_atr_perdiod_long);
  63. valore_atr_short     =   AvgTrueRange(input_atr_perdiod_short);
  64. ema_long             =   XAverage(close, lunghezza_ema_long);
  65. ema_short            =   XAverage(close, lunghezza_ema_short);
  66.    
  67. // Money menagment
  68.      
  69.    
  70. risk = percent_risk/100;
  71. nr_share = floor((InitialCapital + NetProfit) * risk) / close;
  72. stop_loss_long=((((InitialCapital + NetProfit) * risk)/100) * input_stop_loss_percent_long);
  73. stop_loss_short=((((InitialCapital + NetProfit) * risk)/100) * input_stop_loss_percent_short);
  74. target_long=((((InitialCapital + NetProfit) * risk)/100) * input_target_percent_long);
  75. target_short=((((InitialCapital + NetProfit) * risk)/100) * input_target_percent_short);
  76.    
  77. // Calcolo Trailing Stop Long E Short
  78.  
  79. trailing_stop_trigger_long = Entryprice + (entryprice * input_target_percent_long /100) * (input_trailing_trigger_long/100);
  80. trailing_stop_close_long = entryprice + (entryprice * input_target_percent_long /100) * (input_trailing_close_long/100);
  81. trailing_stop_trigger_short = Entryprice - (entryprice * input_target_percent_short /100) * (input_trailing_trigger_short/100);
  82. trailing_stop_close_short = entryprice - (entryprice * input_target_percent_short /100) * (input_trailing_close_short/100);
  83.  
  84. highesthigh = highest(high, Barssinceentry);
  85. trailing_long = (highesthigh >= trailing_stop_trigger_long and close <= trailing_stop_close_long);
  86.  
  87. lowestlow = lowest(low, Barssinceentry);   
  88. trailing_short = (lowestlow <= trailing_stop_trigger_short and close >= trailing_stop_close_short);
  89.    
  90.    
  91. // Entrata Long
  92.  
  93. if Absvalue(open-close) > (valore_atr_long * input_atr_mult_long) and close > open and close > ema_long  and not solo_short  then // and month(date) <> skipmonth1 and Dayofweek(date) <> skipday  
  94.            
  95.     Buy("Long") nr_share contracts Next Bar at market; 
  96.        
  97.    
  98. If MarketPosition =1 then
  99.     Begin;
  100.     Setstopposition;
  101.     SetStopLoss(stop_loss_long);
  102.     Setprofittarget(target_long);
  103.     End;
  104.        
  105.    
  106.    
  107. // Uscita Long     
  108.       // Trailing Stop Long
  109.        
  110. If  MarketPosition =1 and trailing_long then
  111.      
  112.     Sell("Trailing Long") from entry("Long") Next Bar at market;    
  113.            
  114.  
  115.  
  116. // Entrata Short
  117.  
  118.        
  119. if Absvalue(open-close) > (valore_atr_short * input_atr_mult_short) and close < open and close < ema_short and not solo_long  then //
  120.    
  121.  
  122.     Sellshort("Short") nr_share Contracts Next Bar at market;
  123.        
  124. If MarketPosition =-1 then
  125.     Begin;
  126.     Setstopposition;
  127.     SetStopLoss(stop_loss_short);
  128.     Setprofittarget(target_short);     
  129.     End;   
  130.    
  131.  
  132. // Uscita Short
  133.         // Trailing Stop Short
  134.    
  135. If  MarketPosition = -1 and trailing_short then
  136.  
  137.     buytocover("Trailing Short") from entry("Short") Next Bar at market;    
  138.    
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement