Maurizio-Ciullo

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

May 7th, 2022 (edited)
197
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-Maurizio 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= +16%) (Stop Loss Limit Long/Short= -13%) (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 E Cliccare Su Enable Strategy Altrimenti Non Parte
  10.  
  11. //Fase iniziale parametri di input
  12. input:
  13.     InitialCapital(100000),
  14.     percent_risk(8.8), 
  15.     input_stop_loss_percent_long(13),
  16.     input_target_percent_long(16),
  17.     input_stop_loss_percent_short(13),
  18.     input_target_percent_short(16),
  19.     input_trailing_trigger_long(75),
  20.     input_trailing_close_long (50),
  21.     input_trailing_trigger_short (75),
  22.     input_trailing_close_short (50),
  23.     lunghezza_ema_long (240),
  24.     lunghezza_ema_short (240), 
  25.     input_atr_perdiod_long(10),
  26.     input_atr_perdiod_short(10),
  27.     input_atr_mult_long(1),
  28.     input_atr_mult_short(1),
  29.     //skipday(thursday),
  30.     //skipmonth1(9),
  31.     //skipmonth2(8),
  32.     //skipday(monday),
  33.     solo_long(false),
  34.     solo_short(false);
  35.  
  36. Vars:
  37.      
  38.      stop_loss_long(0),
  39.      stop_loss_short(0),
  40.      target_long(0),
  41.      target_short(0),
  42.      ema_long(0),
  43.      ema_short(0),
  44.      valore_atr_long(0),
  45.      valore_atr_short(0),
  46.      trailing_stop_trigger_long(0),
  47.      trailing_stop_close_long(0),
  48.      trailing_stop_trigger_short(0),
  49.      trailing_stop_close_short(0),
  50.      trailing_long(false),
  51.      trailing_short(false),
  52.      highesthigh(0),
  53.      lowestlow(0),
  54.      account_equity(0),
  55.      risk(0),
  56.      nr_share(0);
  57.      
  58. // Calcololo degli indicatori long
  59.    
  60.  
  61. valore_atr_long      =   AvgTrueRange(input_atr_perdiod_long);
  62. valore_atr_short     =   AvgTrueRange(input_atr_perdiod_short);
  63. ema_long             =   XAverage(close, lunghezza_ema_long);
  64. ema_short            =   XAverage(close, lunghezza_ema_short);
  65.    
  66. // Money menagment
  67.      
  68.    
  69. risk = percent_risk/100;
  70. nr_share = floor((InitialCapital + NetProfit) * risk) / close;
  71. stop_loss_long=((((InitialCapital + NetProfit) * risk)/100) * input_stop_loss_percent_long);
  72. stop_loss_short=((((InitialCapital + NetProfit) * risk)/100) * input_stop_loss_percent_short);
  73. target_long=((((InitialCapital + NetProfit) * risk)/100) * input_target_percent_long);
  74. target_short=((((InitialCapital + NetProfit) * risk)/100) * input_target_percent_short);
  75.    
  76. // Calcolo Trailing Stop Long E Short
  77.  
  78. trailing_stop_trigger_long = Entryprice + (entryprice * input_target_percent_long /100) * (input_trailing_trigger_long/100);
  79. trailing_stop_close_long = entryprice + (entryprice * input_target_percent_long /100) * (input_trailing_close_long/100);
  80. trailing_stop_trigger_short = Entryprice - (entryprice * input_target_percent_short /100) * (input_trailing_trigger_short/100);
  81. trailing_stop_close_short = entryprice - (entryprice * input_target_percent_short /100) * (input_trailing_close_short/100);
  82.  
  83. highesthigh = highest(high, Barssinceentry);
  84. trailing_long = (highesthigh >= trailing_stop_trigger_long and close <= trailing_stop_close_long);
  85.  
  86. lowestlow = lowest(low, Barssinceentry);   
  87. trailing_short = (lowestlow <= trailing_stop_trigger_short and close >= trailing_stop_close_short);
  88.  
  89.  
  90. // Entrata Long
  91.  
  92. 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  
  93.            
  94.     Buy("Long") nr_share contracts Next Bar at market; 
  95.        
  96.    
  97. If MarketPosition =1 then
  98.     Begin;
  99.     Setstopposition;
  100.     SetStopLoss(stop_loss_long);
  101.     Setprofittarget(target_long);
  102.     End;
  103.        
  104.    
  105.    
  106. // Uscita Long     
  107.       // Trailing Stop Long
  108.        
  109. If  MarketPosition =1 and trailing_long then
  110.      
  111.     Sell("Trailing Long") from entry("Long") Next Bar at market;    
  112.            
  113.  
  114.  
  115. // Entrata Short
  116.  
  117.        
  118. if Absvalue(open-close) > (valore_atr_short * input_atr_mult_short) and close < open and close < ema_short and not solo_long  then //
  119.    
  120.  
  121.     Sellshort("Short") nr_share Contracts Next Bar at market;
  122.        
  123. If MarketPosition =-1 then
  124.     Begin;
  125.     Setstopposition;
  126.     SetStopLoss(stop_loss_short);
  127.     Setprofittarget(target_short);     
  128.     End;   
  129.    
  130.  
  131. // Uscita Short
  132.         // Trailing Stop Short
  133.    
  134. If  MarketPosition = -1 and trailing_short then
  135.  
  136.     buytocover("Trailing Short") from entry("Short") Next Bar at market;    
Add Comment
Please, Sign In to add comment