Advertisement
Maurizio-Ciullo

Bot Scalping-Exponential-Bot ETH/PERP Ver-5 FTX 5M LONG E SHORT

May 10th, 2022 (edited)
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Scalping exponetial bot tendenza data da due medie, close sopra la terza media, trailing stop doppio,
  2. //Periodo in sample 1/5/21 - 1/10/21
  3. //Periodo out of sample 1/10/21 - 28/04/22
  4.  
  5.  
  6.  
  7.  
  8.  
  9.                                                  //Scalping exponetial bot Easy Language
  10.  
  11. //tendenza data da due medie, close sopra la terza media, trailing stop doppio,
  12.  
  13.  
  14. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  15.  
  16. //Il trading system completo - Scalping-Exponential-Bot Ver-5 (Strategia Breakout) - parte 1
  17. // (Exchange= FTX) (Sottostante ETH-PERP) (Timeframe= 5M) (Direzione= LONG E SHORT) (Swing Posizione= NO) (Esclusione Ore=NO) (Esclusione Giorni=NO') (Esclusione Mesi=NO)
  18. // (Take Profit Long/Short Market = NO) (Take Profit Limit Long/Short= 5% Tradingview-Hub)
  19. // (Stop Loss Limit Long= -1% Tradingview-Hub) (Stop Loss Limit Short= -2% Tradingview-Hub) (Stop Loss Market Long/Short= NO) (Trailing Stop=NO) (Stop Emergenza= NO)
  20. // (Rischio Operazione 2% Perdita Media)
  21. // (In Sample Dal=01/5/21 Al 1/10/21) (Out Of Sample Dal=01/10/21 Al 28/04/22)
  22. // (Progettatta Il=06/05/2022)
  23.  
  24. // Auentare il Max Bars Back Su Tradestation Altrimenti Non Funziona Il Conteggio Barssinceentry 650 E Cliccare Su Enable Strategy Altrimenti Non Parte
  25.  
  26. inputs:
  27.     input_target_long(5),
  28.     input_stop_loss_long(1),
  29.     input_target_short(5),
  30.     input_stop_loss_short(2),
  31.     percent_risk(100),
  32.     InitialCapital(100000),
  33.     lunghezza_media_long(140),
  34.     lunghezza_media_tendenza_veloce_long(60),
  35.     lunghezza_media_tendenza_lenta_long(180),
  36.     lunghezza_media_short(100),
  37.     lunghezza_media_tendenza_veloce_short(60),
  38.     lunghezza_media_tendenza_lenta_short(180),
  39.     input_trailing_stop_trigger_long1(45),
  40.     input_trailing_stop_close_long1(40),
  41.     input_trailing_stop_trigger_short1(50),
  42.     input_trailing_stop_close_short1(20),
  43.     input_trailing_stop_trigger_long2(80),
  44.     input_trailing_stop_close_long2(60),
  45.     input_trailing_stop_trigger_short2(80),
  46.     input_trailing_stop_close_short2(55),  
  47.     input_lunghezza_adx_long(9),
  48.     input_lunghezza_adx_short(9),
  49.     input_differenziale_adx_long_alto(25),
  50.     input_differenziale_adx_long_basso(5),
  51.     input_differenziale_adx_short_alto(60),
  52.     input_differenziale_adx_short_basso(30),
  53.     input_differenziale_rsi_long(65),
  54.     input_differenziale_rsi_short(35),
  55.     perc_apertura_minima_long(0.09),
  56.     perc_apertura_minima_short(0.08),
  57.     only_long(false),
  58.     only_short(false);
  59.    
  60.    
  61. vars:
  62.         stop_loss_long(0),
  63.         take_profit_long(0),
  64.         stop_loss_short(0),
  65.         take_profit_short(0),
  66.         risk(0),
  67.         nr_share(0),
  68.         media_long(0),
  69.         media_tendenza_veloce_long(0),
  70.         media_tendenza_lenta_long(0),
  71.         media_short(0),
  72.         media_tendenza_veloce_short(0),
  73.         media_tendenza_lenta_short(0),
  74.         trailing_stop_trigger_long1(0),
  75.         trailing_stop_close_long1(0),
  76.         trailing_stop_trigger_short1(0),
  77.         trailing_stop_close_short1(0),
  78.         trailing_stop_trigger_long2(0),
  79.         trailing_stop_close_long2(0),
  80.         trailing_stop_trigger_short2(0),
  81.         trailing_stop_close_short2(0),
  82.         trailing_long(false),
  83.         trailing_short(false),
  84.         highesthigh(0),
  85.         lowestlow(0),
  86.         valore_adx_long(0),
  87.         valore_adx_short(0),
  88.         valore_rsi(0),
  89.         apertura_minima_long(0),
  90.         apertura_minima_short(0);
  91.          
  92.        
  93. //medie esponenziali
  94.  
  95. media_long = XAverage( Close, lunghezza_media_long );
  96. media_tendenza_lenta_long = XAverage( Close, lunghezza_media_tendenza_lenta_long );
  97. media_tendenza_veloce_long = XAverage( Close, lunghezza_media_tendenza_veloce_long );
  98. media_short = XAverage( Close, lunghezza_media_short );
  99. media_tendenza_lenta_short = XAverage( Close, lunghezza_media_tendenza_lenta_short );
  100. media_tendenza_veloce_short = XAverage( Close, lunghezza_media_tendenza_veloce_short );
  101. valore_adx_long = adx(input_lunghezza_adx_long);
  102. valore_adx_short = adx(input_lunghezza_adx_short);
  103. valore_rsi = RSI(close, 9);
  104. apertura_minima_long   = (media_long / 100) * perc_apertura_minima_long;
  105. apertura_minima_short   = (media_short / 100) * perc_apertura_minima_short;
  106.  
  107.  
  108.  //Money menagment
  109.    
  110.    
  111.     risk = percent_risk/100;
  112.     nr_share = floor((InitialCapital + NetProfit) * risk) / close;
  113.     stop_loss_long=((((InitialCapital + NetProfit) * risk)/100) * input_stop_loss_long);
  114.     take_profit_long=((((InitialCapital + NetProfit) * risk)/100) * input_target_long);
  115.     stop_loss_short=((((InitialCapital + NetProfit) * risk)/100) * input_stop_loss_short);
  116.     take_profit_short=((((InitialCapital + NetProfit) * risk)/100) * input_target_short);
  117.    
  118. // Calcolo 2 Trailing Stop Long E Short
  119.    
  120.     trailing_stop_trigger_long1 = Entryprice + (entryprice * input_target_long /100) * (input_trailing_stop_trigger_long1/100);
  121.     trailing_stop_close_long1 = entryprice + (entryprice * input_target_long /100) * (input_trailing_stop_close_long1/100);
  122.     trailing_stop_trigger_short1 = Entryprice - (entryprice * input_target_short /100) * (input_trailing_stop_trigger_short1/100);
  123.     trailing_stop_close_short1 = entryprice - (entryprice * input_target_short /100) * (input_trailing_stop_close_short1/100);
  124.     trailing_stop_trigger_long2 = Entryprice + (entryprice * input_target_long /100) * (input_trailing_stop_trigger_long2/100);
  125.     trailing_stop_close_long2 = entryprice + (entryprice * input_target_long /100) * (input_trailing_stop_close_long2/100);
  126.     trailing_stop_trigger_short2 = Entryprice - (entryprice * input_target_short /100) * (input_trailing_stop_trigger_short2/100);
  127.     trailing_stop_close_short2 = entryprice - (entryprice * input_target_short /100) * (input_trailing_stop_close_short2/100);
  128.    
  129.     {trailing_long =  ( ((high >= trailing_stop_trigger_long1 and close <= trailing_stop_close_long1 and bardatetime > entrydatetime) or (high >= trailing_stop_trigger_long2 and close <= trailing_stop_close_long2 and bardatetime > entrydatetime)) or ((high[1] >= trailing_stop_trigger_long1 and close <= trailing_stop_close_long1 and bardatetime[1] > entrydatetime) or (high[1] >= trailing_stop_trigger_long2 and close <= trailing_stop_close_long2 and bardatetime[1] > entrydatetime)) or ((high[2] >= trailing_stop_trigger_long1 and close <= trailing_stop_close_long1 and bardatetime[2] > entrydatetime) or (high[2] >= trailing_stop_trigger_long2 and close <= trailing_stop_close_long2 and bardatetime[2] > entrydatetime)) or ((high[3] >= trailing_stop_trigger_long1 and close <= trailing_stop_close_long1 and bardatetime[3] > entrydatetime) or (high[3] >= trailing_stop_trigger_long2 and close <= trailing_stop_close_long2 and bardatetime[3] > entrydatetime)) or ((high[4] >= trailing_stop_trigger_long1 and close <= trailing_stop_close_long1 and bardatetime[4] > entrydatetime) or (high[4] >= trailing_stop_trigger_long2 and close <= trailing_stop_close_long2 and bardatetime[4] > entrydatetime))
  130.      or ((high[5] >= trailing_stop_trigger_long1 and close <= trailing_stop_close_long1 and bardatetime[5] > entrydatetime) or (high[5] >= trailing_stop_trigger_long2 and close <= trailing_stop_close_long2 and bardatetime[5] > entrydatetime)) or ((high[6] >= trailing_stop_trigger_long1 and close <= trailing_stop_close_long1 and bardatetime[6] > entrydatetime) or (high[6] >= trailing_stop_trigger_long2 and close <= trailing_stop_close_long2 and bardatetime[6] > entrydatetime)) or ((high[7] >= trailing_stop_trigger_long1 and close <= trailing_stop_close_long1 and bardatetime[7] > entrydatetime) or (high[7] >= trailing_stop_trigger_long2 and close <= trailing_stop_close_long2 and bardatetime[7] > entrydatetime)) or ((high[8] >= trailing_stop_trigger_long1 and close <= trailing_stop_close_long1 and bardatetime[8] > entrydatetime) or (high[8] >= trailing_stop_trigger_long2 and close <= trailing_stop_close_long2 and bardatetime[8] > entrydatetime)) or ((high[9] >= trailing_stop_trigger_long1 and close <= trailing_stop_close_long1 and bardatetime[9] > entrydatetime) or (high[9] >= trailing_stop_trigger_long2 and close <= trailing_stop_close_long2 and bardatetime[9] > entrydatetime))
  131.      or ((high[10] >= trailing_stop_trigger_long1 and close <= trailing_stop_close_long1 and bardatetime[10] > entrydatetime) or (high[10] >= trailing_stop_trigger_long2 and close <= trailing_stop_close_long2 and bardatetime[10] > entrydatetime)) or ((high[11] >= trailing_stop_trigger_long1 and close <= trailing_stop_close_long1 and bardatetime[11] > entrydatetime) or (high[11] >= trailing_stop_trigger_long2 and close <= trailing_stop_close_long2 and bardatetime[11] > entrydatetime)) or ((high[12] >= trailing_stop_trigger_long1 and close <= trailing_stop_close_long1 and bardatetime[12] > entrydatetime) or (high[12] >= trailing_stop_trigger_long2 and close <= trailing_stop_close_long2 and bardatetime[12] > entrydatetime)) or ((high[13] >= trailing_stop_trigger_long1 and close <= trailing_stop_close_long1 and bardatetime[13] > entrydatetime) or (high[13] >= trailing_stop_trigger_long2 and close <= trailing_stop_close_long2 and bardatetime[13] > entrydatetime)) or ((high[14] >= trailing_stop_trigger_long1 and close <= trailing_stop_close_long1 and bardatetime[14] > entrydatetime) or (high[14] >= trailing_stop_trigger_long2 and close <= trailing_stop_close_long2 and bardatetime[14] > entrydatetime))
  132.      or ((high[15] >= trailing_stop_trigger_long1 and close <= trailing_stop_close_long1 and bardatetime[15] > entrydatetime) or (high[15] >= trailing_stop_trigger_long2 and close <= trailing_stop_close_long2 and bardatetime[15] > entrydatetime)) or ((high[16] >= trailing_stop_trigger_long1 and close <= trailing_stop_close_long1 and bardatetime[16] > entrydatetime) or (high[16] >= trailing_stop_trigger_long2 and close <= trailing_stop_close_long2 and bardatetime[16] > entrydatetime)) or ((high[17] >= trailing_stop_trigger_long1 and close <= trailing_stop_close_long1 and bardatetime[17] > entrydatetime) or (high[17] >= trailing_stop_trigger_long2 and close <= trailing_stop_close_long2 and bardatetime[17] > entrydatetime)) or ((high[18] >= trailing_stop_trigger_long1 and close <= trailing_stop_close_long1 and bardatetime[18] > entrydatetime) or (high[18] >= trailing_stop_trigger_long2 and close <= trailing_stop_close_long2 and bardatetime[18] > entrydatetime)) or ((high[19] >= trailing_stop_trigger_long1 and close <= trailing_stop_close_long1 and bardatetime[19] > entrydatetime) or (high[19] >= trailing_stop_trigger_long2 and close <= trailing_stop_close_long2 and bardatetime[19] > entrydatetime)));
  133.      
  134.     trailing_short =  ( ((low <= trailing_stop_trigger_short1 and close >= trailing_stop_close_short1 and bardatetime > entrydatetime) or (low <= trailing_stop_trigger_short2 and close >= trailing_stop_close_short2 and bardatetime > entrydatetime)) or ((low[1] <= trailing_stop_trigger_short1 and close >= trailing_stop_close_short1 and bardatetime[1] > entrydatetime) or (low[1] <= trailing_stop_trigger_short2 and close >= trailing_stop_close_short2 and bardatetime[1] > entrydatetime)) or ((low[2] <= trailing_stop_trigger_short1 and close >= trailing_stop_close_short1 and bardatetime[2] > entrydatetime) or (low[2] <= trailing_stop_trigger_short2 and close >= trailing_stop_close_short2 and bardatetime[2] > entrydatetime)) or ((low[3] <= trailing_stop_trigger_short1 and close >= trailing_stop_close_short1 and bardatetime[3] > entrydatetime) or (low[3] <= trailing_stop_trigger_short2 and close >= trailing_stop_close_short2 and bardatetime[3] > entrydatetime)) or ((low[4] <= trailing_stop_trigger_short1 and close >= trailing_stop_close_short1 and bardatetime[4] > entrydatetime) or (low[4] <= trailing_stop_trigger_short2 and close >= trailing_stop_close_short2 and bardatetime[4] > entrydatetime))
  135.      or ((low[5] <= trailing_stop_trigger_short1 and close >= trailing_stop_close_short1 and bardatetime[5] > entrydatetime) or (low[5] <= trailing_stop_trigger_short2 and close >= trailing_stop_close_short2 and bardatetime[5] > entrydatetime)) or ((low[6] <= trailing_stop_trigger_short1 and close >= trailing_stop_close_short1 and bardatetime[6] > entrydatetime) or (low[6] <= trailing_stop_trigger_short2 and close >= trailing_stop_close_short2 and bardatetime[6] > entrydatetime)) or ((low[7] <= trailing_stop_trigger_short1 and close >= trailing_stop_close_short1 and bardatetime[7] > entrydatetime) or (low[7] <= trailing_stop_trigger_short2 and close >= trailing_stop_close_short2 and bardatetime[7] > entrydatetime)) or ((low[8] <= trailing_stop_trigger_short1 and close >= trailing_stop_close_short1 and bardatetime[8] > entrydatetime) or (low[8] <= trailing_stop_trigger_short2 and close >= trailing_stop_close_short2 and bardatetime[8] > entrydatetime)) or ((low[9] <= trailing_stop_trigger_short1 and close >= trailing_stop_close_short1 and bardatetime[9] > entrydatetime) or (low[9] <= trailing_stop_trigger_short2 and close >= trailing_stop_close_short2 and bardatetime[9] > entrydatetime))
  136.      or ((low[10] <= trailing_stop_trigger_short1 and close >= trailing_stop_close_short1 and bardatetime[10] > entrydatetime) or (low[10] <= trailing_stop_trigger_short2 and close >= trailing_stop_close_short2 and bardatetime[10] > entrydatetime)) or ((low[11] <= trailing_stop_trigger_short1 and close >= trailing_stop_close_short1 and bardatetime[11] > entrydatetime) or (low[11] <= trailing_stop_trigger_short2 and close >= trailing_stop_close_short2 and bardatetime[11] > entrydatetime)) or ((low[12] <= trailing_stop_trigger_short1 and close >= trailing_stop_close_short1 and bardatetime[12] > entrydatetime) or (low[12] <= trailing_stop_trigger_short2 and close >= trailing_stop_close_short2 and bardatetime[12] > entrydatetime)) or ((low[13] <= trailing_stop_trigger_short1 and close >= trailing_stop_close_short1 and bardatetime[13] > entrydatetime) or (low[13] <= trailing_stop_trigger_short2 and close >= trailing_stop_close_short2 and bardatetime[13] > entrydatetime)) or ((low[14] <= trailing_stop_trigger_short1 and close >= trailing_stop_close_short1 and bardatetime[14] > entrydatetime) or (low[14] <= trailing_stop_trigger_short2 and close >= trailing_stop_close_short2 and bardatetime[14] > entrydatetime))
  137.      or ((low[15] <= trailing_stop_trigger_short1 and close >= trailing_stop_close_short1 and bardatetime[15] > entrydatetime) or (low[15] <= trailing_stop_trigger_short2 and close >= trailing_stop_close_short2 and bardatetime[15] > entrydatetime)) or ((low[16] <= trailing_stop_trigger_short1 and close >= trailing_stop_close_short1 and bardatetime[16] > entrydatetime) or (low[16] <= trailing_stop_trigger_short2 and close >= trailing_stop_close_short2 and bardatetime[16] > entrydatetime)) or ((low[17] <= trailing_stop_trigger_short1 and close >= trailing_stop_close_short1 and bardatetime[17] > entrydatetime) or (low[17] <= trailing_stop_trigger_short2 and close >= trailing_stop_close_short2 and bardatetime[17] > entrydatetime)) or ((low[18] <= trailing_stop_trigger_short1 and close >= trailing_stop_close_short1 and bardatetime[18] > entrydatetime) or (low[18] <= trailing_stop_trigger_short2 and close >= trailing_stop_close_short2 and bardatetime[18] > entrydatetime)) or ((low[19] <= trailing_stop_trigger_short1 and close >= trailing_stop_close_short1 and bardatetime[19] > entrydatetime) or (low[19] <= trailing_stop_trigger_short2 and close >= trailing_stop_close_short2 and bardatetime[19] > entrydatetime)));}
  138.      
  139.      highesthigh = highest(high, Barssinceentry);
  140.      trailing_long = (highesthigh >= trailing_stop_trigger_long1 and close <= trailing_stop_close_long1) or (highesthigh >= trailing_stop_trigger_long2 and close <= trailing_stop_close_long2);
  141.  
  142.      lowestlow = lowest(low, Barssinceentry);  
  143.      trailing_short = (lowestlow <= trailing_stop_trigger_short1 and close >= trailing_stop_close_short1) or (lowestlow <= trailing_stop_trigger_short2 and close >= trailing_stop_close_short2);
  144.      
  145.  
  146.  
  147. if marketposition = 0 and close cross over media_long and close > (media_long + apertura_minima_long)  and valore_adx_long > input_differenziale_adx_long_basso and valore_adx_long < input_differenziale_adx_long_alto and media_tendenza_veloce_long > media_tendenza_lenta_long and valore_rsi < input_differenziale_rsi_long and not only_short    Then
  148.  
  149.  
  150.    begin;
  151.    
  152.       Buy("Long") nr_share contracts Next Bar at market;
  153.      
  154.    end;
  155.    
  156. if marketposition = 1 Then
  157.     begin;
  158.         Setstopposition;
  159.         SetStopLoss(stop_loss_long);
  160.         Setprofittarget(take_profit_long);     
  161.     end;
  162.    
  163.  
  164. If  MarketPosition =1 and trailing_long then
  165.      
  166.  
  167. Sell("Trailing Long") from entry("Long") Next Bar at market;  
  168.  
  169.  
  170.  
  171. if marketposition = 0 and close cross under media_short and close < (media_short - apertura_minima_short)  and media_tendenza_lenta_short > media_tendenza_veloce_short and valore_adx_short > input_differenziale_adx_short_basso and valore_adx_short < input_differenziale_adx_short_alto and valore_rsi > input_differenziale_rsi_short  and not only_long    Then
  172.  
  173.    begin;
  174.    
  175.       sellshort("Short") nr_share contracts Next Bar at market;
  176.        
  177.    end;
  178.    
  179. if marketposition = -1 Then
  180.     begin;
  181.         Setstopposition;
  182.         SetStopLoss(stop_loss_short);
  183.         Setprofittarget(take_profit_short);    
  184.     end;
  185.    
  186.  
  187. If  MarketPosition = -1 and trailing_short then
  188.      
  189.  
  190. buytocover("Trailing Short") from entry("Short") Next Bar at market;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement