Advertisement
Maurizio-Ciullo

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

May 28th, 2022
311
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 Scalping Bot Ver-5 (Strategia Breakout) Parte 1
  4. // (Exchange= FTX) (Sottostante ETH-PERP) (Timeframe= 5M) (Direzione= LONG E SHORT) (Swing Posizione= NO) (Esclusione Ore=NO) (Esclusione Giorni=NO') (Esclusione Mesi=NO)
  5. // (Take Profit Long/Short Market = NO) (Take Profit Limit Long/Short= +3%) (Stop Loss Limit Long/Short= -3% Tradingview-Hub) (Stop Loss Market Long/Short= NO) (Trailing Stop=NO) (Stop Emergenza= NO)
  6. // (Rischio Operazione 2% Perdita Media)
  7. // (In Sample Dal=01/02/2021 Al 01/10/2021) (Out Of Sample Dal=01/10/2021 Al 28/04/2022)
  8. // (Progettatta Il=25/04/2022)
  9.  
  10. // 'Bot Scalping-Bot Ver-5 ETH/PERP FTX 5M LONG E SHORT'
  11.  
  12. {*****************************************************************************
  13. Description : HeikinAshiSyn - This Paintbar is a Variation of the Heikin Ashi Candlestick to assist in reading the trend.
  14. ******************************************************************************}
  15. // Inputs ///////////////////////////////////////////////////////
  16.  
  17. inputs: UpColor(RGB(0,192,255)),  
  18.         DnColor(RGB(255,128,64)),  
  19.         HiLoColor(DarkGray),
  20.         CompBars(0),
  21.         SmoothHA(False),
  22.         SmoothAvgType(1 {1 JTHull, 2 SMA, 3 EMA, 4 wAverage} ),
  23.         SmoothLength(6),
  24.         ReverseColor(false),
  25.         input_target_long(3),
  26.         input_stop_loss_long(3),
  27.         input_target_short(3),
  28.         input_stop_loss_short(3),
  29.         input_trailing_trigger_long (60),
  30.         input_trailing_close_long (54),
  31.         input_trailing_trigger_short (60),
  32.         input_trailing_close_short (54),
  33.         percent_risk(100),
  34.         InitialCapital(100000),
  35.         input_boombar_3_long(0.44),
  36.         input_boombar_doji_long(0.44),
  37.         input_boombar_3_short(0.34),
  38.         input_boombar_doji_short(0.34),
  39.         input_distanza_long(1.8), // distanza tra la haClose e la slowema
  40.         input_distanza_short(2.4),
  41.         mult_doji_long(0.2),
  42.         mult_doji_short(0.26),
  43.         lunghezza_adx_long(5),
  44.         lunghezza_adx_short(7),
  45.         differenziale_adx_basso_long(25),
  46.         differenziale_adx_alto_long(75),
  47.         differenziale_adx_basso_short(20),
  48.         differenziale_adx_alto_short(80),
  49.         lunghezza_rsi_long(15),
  50.         lunghezza_rsi_short(6),
  51.         differenziale_rsi_long(90),
  52.         differenziale_rsi_short(24),
  53.         solo_short(false),
  54.         solo_long(false),
  55.         {adx_neutrale_diff_input(0),    
  56.         dmi_min_diff_input_long(26.1),  
  57.         dmi_min_diff_input_short(32.6),}
  58.        
  59.        
  60. // Start Initializing Heiken Ashi ///////////////////////////////////////////////////////
  61.  
  62.     double FastPrice( Close ) [
  63.         DisplayName = "FastPrice",
  64.         ToolTip = "Enter an EasyLanguage expression to use in calculation of shorter length moving average."],
  65.    
  66.     double SlowPrice( Close ) [
  67.         DisplayName = "SlowPrice",
  68.         ToolTip = "Enter an EasyLanguage expression to use in calculation of longer length moving average."],
  69.    
  70.     double FastLength_long( 52 ) [
  71.         DisplayName = "FastLength",
  72.         ToolTip = "Enter number of bars to use in calculation of shorter length moving average."],
  73.        
  74.     double FastLength_short( 42 ) [
  75.         DisplayName = "FastLength",
  76.         ToolTip = "Enter number of bars to use in calculation of shorter length moving average."],
  77.    
  78.     double SlowLength_long( 82 ) [
  79.         DisplayName = "SlowLength",
  80.         ToolTip = "Enter number of bars to use in calculation of longer length moving average."],
  81.        
  82.     double SlowLength_short( 170 ) [
  83.         DisplayName = "SlowLength",
  84.         ToolTip = "Enter number of bars to use in calculation of longer length moving average."],
  85.    
  86.     int Displace( 0 ) [
  87.         DisplayName = "Displace",
  88.         ToolTip = "Displacement.  Enter the number of bars by which plots will be displaced.  Displacement may be positive (left) or negative (right)."];
  89.  
  90. // End Initializing Heiken Ashi ///////////////////////////////////////////////////////
  91.  
  92.  
  93. // Initializing Variables ///////////////////////////////////////////////////////
  94.  
  95. vars: haClose(0),haOpen(0),haHigh(0),haLow(0),
  96.         color(0), newHi(0), newLo(0),
  97.         iOpen(0), iClose(0), iHi(0), iLo(0),
  98.         double FastEMA_long( 0 ),
  99.         double FastEMA_short( 0 ),
  100.         double SlowEMA_long( 0 ),
  101.         double SlowEMA_short( 0 ),
  102.         stop_loss_long(0),
  103.         stop_loss_short(0),
  104.         take_profit_long(0),
  105.         take_profit_short(0),
  106.         trailing_trigger_long(0),
  107.         trailing_close_long(0),
  108.         trailing_trigger_short(0),
  109.         trailing_close_short(0),
  110.         trailing_stop_trigger_long(0),
  111.         trailing_stop_close_long(0),
  112.         trailing_stop_trigger_short(0),
  113.         trailing_stop_close_short(0),
  114.         Trailing_Stop_Long(False),
  115.         Trailing_Stop_Short(False),
  116.         {trailing_long(false),
  117.         trailing_short(false),
  118.         trailing_long2(false),
  119.         trailing_short2(false),}
  120.         Cond_Entry_Long1(False),
  121.         Cond_Entry_Long2(False),
  122.         Cond_Entry_Short1(False),
  123.         Cond_Entry_Short2(False),
  124.         risk(0),
  125.         nr_share(0),
  126.         boombar_3_long(0),
  127.         boombar_doji_long(0),
  128.         boombar_3_short(0),
  129.         boombar_doji_short(0),
  130.         valore_adx_long(0),
  131.         valore_adx_short(0),
  132.         valore_rsi_long(0),
  133.         valore_rsi_short(0),
  134.         distanza_long(0),
  135.         distanza_short(0),
  136.         diffenziale_adx_long(0),
  137.         diffenziale_adx_short(0);
  138.         {di_pos(0),
  139.         di_neg(0),
  140.         adx_neutrale(0);}
  141.        
  142.  
  143. // Start Detecting Heiken Ashi ///////////////////////////////////////////////////////
  144.  
  145. begin;
  146.  if SmoothHA = False then begin;
  147.     iOpen = Open;
  148.     iClose = Close;
  149.     iHi = High;
  150.     iLo = Low;
  151.  end else begin;
  152.     if SmoothAvgType = 1 then begin;
  153.         iOpen = jthma(Open, SmoothLength);
  154.         iClose = jthma(Close, SmoothLength);
  155.         iHi = jthma(High, SmoothLength);
  156.         iLo = jthma(Low, SmoothLength);
  157.     end;   
  158.     if SmoothAvgType = 2 then begin;
  159.         iOpen = average(Open, SmoothLength);
  160.         iClose = average(Close, SmoothLength);
  161.         iHi = average(High, SmoothLength);
  162.         iLo = average(Low, SmoothLength);
  163.     end;   
  164.     if SmoothAvgType = 3 then begin;
  165.         iOpen = xAverage(Open, SmoothLength);
  166.         iClose = xAverage(Close, SmoothLength);
  167.         iHi = xAverage(High, SmoothLength);
  168.         iLo = xAverage(Low, SmoothLength);
  169.     end;   
  170.     if SmoothAvgType = 4 then begin;
  171.         iOpen = wAverage(Open, SmoothLength);
  172.         iClose = wAverage(Close, SmoothLength);
  173.         iHi = wAverage(High, SmoothLength);
  174.         iLo = wAverage(Low, SmoothLength);
  175.     end;   
  176.  end;  
  177.  
  178.  if BarNumber > 1 then begin
  179.     haClose = (iOpen+iHi+iLo+iClose)/4;
  180.     haOpen = (haOpen [1] + haClose [1])/2 ;
  181.     haHigh = MaxList(iHi, haOpen, haClose) ;
  182.     haLow = MinList(iLo, haOpen, haClose) ;
  183.      
  184.     if haClose > haOpen then
  185.         color = UpColor
  186.     else
  187.         color = DnColor;
  188.    
  189.     if CompBars > 0 then begin;
  190.         for value1 = 1 to CompBars begin
  191.             if haOpen <= MaxList(haOpen[value1],haClose[value1]) and
  192.                 haOpen >= MinList(haOpen[value1],haClose[value1]) and
  193.             haClose <= MaxList(haOpen[value1],haClose[value1]) and
  194.             haClose >= MinList(haOpen[value1],haClose[value1]) then
  195.                 color = color[value1];
  196.         end;
  197.     end;
  198.      
  199.     if ReverseColor then begin;
  200.         if color = UpColor then
  201.             color = DnColor
  202.         else
  203.             color = UpColor;
  204.     end;
  205.    
  206.     {Plot1( haOpen,  "Open",  color ) ;    
  207.     Plot2( haClose, "Close", color ) ;    
  208.     Plot3( haHigh,  "High",  HiLoColor ) ;    
  209.     Plot4( haLow,   "Low",   HiLoColor ) ; }
  210.      
  211. end else begin;
  212.  
  213.     haOpen = iOpen;
  214.     haClose = (iOpen+iHi+iLo+iClose)/4;
  215.     haHigh = MaxList( iHi, haOpen, haClose);
  216.     haLow = MinList( iLo, haOpen,haClose);
  217.    
  218.  end;
  219.  
  220. // End Detecting Heiken Ashi ///////////////////////////////////////////////////////
  221.  
  222.  
  223. // Calculating Variables ///////////////////////////////////////////////////////
  224.  
  225. FastEMA_long = XAverage( haClose, FastLength_long );
  226. FastEMA_short = XAverage( haClose, FastLength_short );
  227. SlowEMA_long = XAverage( haClose, SlowLength_long );
  228. SlowEMA_short = XAverage( haClose, SlowLength_short );
  229. valore_adx_long = adx(lunghezza_adx_long);
  230. valore_adx_short = adx(lunghezza_adx_short);
  231. valore_rsi_long = rsi(close, lunghezza_rsi_long);
  232. valore_rsi_short = rsi(close, lunghezza_rsi_short);
  233. boombar_3_long = haClose[1] / 100 * input_boombar_3_long;
  234. boombar_3_short = haClose[1] / 100 *input_boombar_3_short;
  235. boombar_doji_long = haClose[1] / 100 * input_boombar_doji_long;
  236. boombar_doji_short = haClose[1] / 100 * input_boombar_doji_short;
  237. distanza_long = SlowEma_long / 100 * input_distanza_long;
  238. distanza_short = SlowEma_short / 100 * input_distanza_short;
  239. {adx_neutrale = adx(14);
  240. diffenziale_adx = adx_neutrale + (adx_neutrale/100*adx_neutrale_diff_input);
  241. di_pos = (dmiPlus(14));
  242. di_neg = (dmiMinus(14));}
  243.  
  244.  
  245. // Money menagment ///////////////////////////////////////////////////////
  246.        
  247. risk = percent_risk/100;
  248. nr_share = floor((InitialCapital + NetProfit) * risk) / close;
  249. stop_loss_long=((((InitialCapital + NetProfit) * risk)/100) * input_stop_loss_long);
  250. stop_loss_short=((((InitialCapital + NetProfit) * risk)/100) * input_stop_loss_short);
  251. take_profit_long=((((InitialCapital + NetProfit) * risk)/100) * input_target_long);
  252. take_profit_short=((((InitialCapital + NetProfit) * risk)/100) * input_target_short);
  253.    
  254.  
  255. //Variabili Trailing Stop Long e Short
  256.  
  257. trailing_stop_trigger_long = Entryprice + (entryprice * input_target_long /100) * (input_trailing_trigger_long / 100);
  258. trailing_stop_close_long = entryprice + (entryprice * input_target_long /100) * (input_trailing_close_long / 100);
  259. trailing_stop_trigger_short = Entryprice - (entryprice * input_target_short /100) * (input_trailing_trigger_short / 100);
  260. trailing_stop_close_short = entryprice - (entryprice * input_target_short /100) * (input_trailing_close_short / 100);
  261.  
  262.            
  263. //Trailing Stop Long: Quando la posizione è aperta, contando indietro dall'ultima chiusura fino a max 65 candele indietro fino ad arrivare all'ingresso della posizione, se gli high sono >= dei trailing_stop_trigger e le close sono <= dei trailing_stop_close la condizione è valida
  264. //Trailing Stop Short: Quando la posizione è aperta, contando indietro dall'ultima chiusura fino a max 65 candele indietro fino ad arrivare all'ingresso della posizione, se gli high sono >= dei trailing_stop_trigger e le close sono <= dei trailing_stop_close la condizione è valida
  265. // Definizione Entrate Long 1 e 2          
  266. Cond_Entry_Long1 = valore_rsi_long < differenziale_rsi_long and (haClose - SlowEma_long) < distanza_long and valore_adx_long < differenziale_adx_alto_long and valore_adx_long > differenziale_adx_basso_long and (FastEMA_long[1] - SlowEMA_long[1]) < (FastEMA_long - SlowEMA_long) and Absvalue(haOpen-haClose) > boombar_3_long and FastEMA_long > SlowEMA_long  and haOpen < haClose and haOpen[1] > haClose[1] and haOpen[2] > haClose[2] and haOpen[3] > haClose[3] and not solo_short;
  267. Cond_Entry_Long2 = valore_rsi_long < differenziale_rsi_long and (haClose - SlowEma_long) < distanza_long and valore_adx_long < differenziale_adx_alto_long and valore_adx_long > differenziale_adx_basso_long and (FastEMA_long[1] - SlowEMA_long[1]) < (FastEMA_long - SlowEMA_long) and Absvalue(haOpen-haClose) > boombar_doji_long and FastEMA_long > SlowEMA_long  and haOpen < haClose and Absvalue(haClose[1] - haOpen[1]) < (haClose / 100 *mult_doji_long) and not solo_short;  
  268.  
  269. // Definizione Entrate Short 1 e 2
  270. Cond_Entry_Short1 = valore_rsi_short > differenziale_rsi_short and (SlowEMA_short - haClose) < distanza_short and valore_adx_short < differenziale_adx_alto_short and valore_adx_short > differenziale_adx_basso_short and (SlowEMA_short[1] - FastEMA_short[1]) <= (SlowEMA_short - FastEMA_short) and absvalue(haOpen - haClose) > boombar_3_short and (FastEMA_short < SlowEMA_short) and (haOpen > haClose) and (haOpen[1] < haClose[1] and haOpen[2] < haClose[2] and haOpen[3] < haClose[3]) and not solo_long;
  271. Cond_Entry_Short2 = valore_rsi_short > differenziale_rsi_short and (SlowEMA_short - haClose) < distanza_short and valore_adx_short < differenziale_adx_alto_short and valore_adx_short > differenziale_adx_basso_short and (SlowEMA_short[1] - FastEMA_short[1]) <= (SlowEMA_short - FastEMA_short) and FastEMA_short < SlowEMA_short and absvalue(haOpen[1] - haClose[1]) < (haClose / 100 * mult_doji_short) and absvalue(haOpen - haClose) > boombar_doji_short and (haOpen > haClose) and not solo_long;  
  272.                        
  273. // Cond Entry Long 1 E 2
  274. // Stop Loss E Take Profit Limit Sono In Fine Al Codice
  275.  
  276. if marketposition = 0 and (Cond_Entry_Long1 or Cond_Entry_Long2) then
  277.    begin;
  278.    
  279.       Buy("Long") nr_share  contracts Next Bar at market;
  280.      
  281.    end;      
  282.  
  283. if marketposition = 1 Then
  284.     begin;
  285.         Setstopposition;
  286.         SetStopLoss(stop_loss_long);
  287.         Setprofittarget(take_profit_long);     
  288.     end;
  289.    
  290. // Exit Traling Stop Long
  291.  
  292. If  MarketPosition =1 and Trailing_Stop_Long then
  293.    
  294. Sell("Trailing Long") from entry("Long") Next Bar at market;
  295.  
  296.  
  297. // Cond Entry Short 1 E 2
  298. // Stop Loss E Take Profit Limit Sono In Fine Al Codice
  299.  
  300. if marketposition = 0 and (Cond_Entry_Short1 or Cond_Entry_Short2) then
  301.    begin;
  302.    
  303.       Sellshort("Short") nr_share  contracts Next Bar at market;
  304.      
  305.    end;      
  306.  
  307. if marketposition = -1 Then
  308.     begin;
  309.         Setstopposition;
  310.         SetStopLoss(stop_loss_short);
  311.         Setprofittarget(take_profit_short);    
  312.     end;
  313.    
  314. // Exit Traling Stop Short
  315.  
  316. If  MarketPosition = -1 and Trailing_Stop_Short then
  317.    
  318. Buytocover("Trailing Short") from entry("Short") Next Bar at market;
  319.  
  320. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement