Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Scalping exponetial bot tendenza data da due medie, close sopra la terza media, trailing stop doppio,
- //Periodo in sample 1/5/21 - 1/10/21
- //Periodo out of sample 1/10/21 - 28/04/22
- //Scalping exponetial bot Easy Language
- //tendenza data da due medie, close sopra la terza media, trailing stop doppio,
- // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
- //Il trading system completo - Scalping-Exponential-Bot Ver-5 (Strategia Breakout) - parte 1
- // (Exchange= FTX) (Sottostante ETH-PERP) (Timeframe= 5M) (Direzione= LONG E SHORT) (Swing Posizione= NO) (Esclusione Ore=NO) (Esclusione Giorni=NO') (Esclusione Mesi=NO)
- // (Take Profit Long/Short Market = NO) (Take Profit Limit Long/Short= 5% Tradingview-Hub)
- // (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)
- // (Rischio Operazione 2% Perdita Media)
- // (In Sample Dal=01/5/21 Al 1/10/21) (Out Of Sample Dal=01/10/21 Al 28/04/22)
- // (Progettatta Il=06/05/2022)
- // Auentare il Max Bars Back Su Tradestation Altrimenti Non Funziona Il Conteggio Barssinceentry 650 E Cliccare Su Enable Strategy Altrimenti Non Parte
- inputs:
- input_target_long(5),
- input_stop_loss_long(1),
- input_target_short(5),
- input_stop_loss_short(2),
- percent_risk(100),
- InitialCapital(100000),
- lunghezza_media_long(140),
- lunghezza_media_tendenza_veloce_long(60),
- lunghezza_media_tendenza_lenta_long(180),
- lunghezza_media_short(100),
- lunghezza_media_tendenza_veloce_short(60),
- lunghezza_media_tendenza_lenta_short(180),
- input_trailing_stop_trigger_long1(45),
- input_trailing_stop_close_long1(40),
- input_trailing_stop_trigger_short1(50),
- input_trailing_stop_close_short1(20),
- input_trailing_stop_trigger_long2(80),
- input_trailing_stop_close_long2(60),
- input_trailing_stop_trigger_short2(80),
- input_trailing_stop_close_short2(55),
- input_lunghezza_adx_long(9),
- input_lunghezza_adx_short(9),
- input_differenziale_adx_long_alto(25),
- input_differenziale_adx_long_basso(5),
- input_differenziale_adx_short_alto(60),
- input_differenziale_adx_short_basso(30),
- input_differenziale_rsi_long(65),
- input_differenziale_rsi_short(35),
- perc_apertura_minima_long(0.09),
- perc_apertura_minima_short(0.08),
- only_long(false),
- only_short(false);
- vars:
- stop_loss_long(0),
- take_profit_long(0),
- stop_loss_short(0),
- take_profit_short(0),
- risk(0),
- nr_share(0),
- media_long(0),
- media_tendenza_veloce_long(0),
- media_tendenza_lenta_long(0),
- media_short(0),
- media_tendenza_veloce_short(0),
- media_tendenza_lenta_short(0),
- trailing_stop_trigger_long1(0),
- trailing_stop_close_long1(0),
- trailing_stop_trigger_short1(0),
- trailing_stop_close_short1(0),
- trailing_stop_trigger_long2(0),
- trailing_stop_close_long2(0),
- trailing_stop_trigger_short2(0),
- trailing_stop_close_short2(0),
- trailing_long(false),
- trailing_short(false),
- highesthigh(0),
- lowestlow(0),
- valore_adx_long(0),
- valore_adx_short(0),
- valore_rsi(0),
- apertura_minima_long(0),
- apertura_minima_short(0);
- //medie esponenziali
- media_long = XAverage( Close, lunghezza_media_long );
- media_tendenza_lenta_long = XAverage( Close, lunghezza_media_tendenza_lenta_long );
- media_tendenza_veloce_long = XAverage( Close, lunghezza_media_tendenza_veloce_long );
- media_short = XAverage( Close, lunghezza_media_short );
- media_tendenza_lenta_short = XAverage( Close, lunghezza_media_tendenza_lenta_short );
- media_tendenza_veloce_short = XAverage( Close, lunghezza_media_tendenza_veloce_short );
- valore_adx_long = adx(input_lunghezza_adx_long);
- valore_adx_short = adx(input_lunghezza_adx_short);
- valore_rsi = RSI(close, 9);
- apertura_minima_long = (media_long / 100) * perc_apertura_minima_long;
- apertura_minima_short = (media_short / 100) * perc_apertura_minima_short;
- //Money menagment
- risk = percent_risk/100;
- nr_share = floor((InitialCapital + NetProfit) * risk) / close;
- stop_loss_long=((((InitialCapital + NetProfit) * risk)/100) * input_stop_loss_long);
- take_profit_long=((((InitialCapital + NetProfit) * risk)/100) * input_target_long);
- stop_loss_short=((((InitialCapital + NetProfit) * risk)/100) * input_stop_loss_short);
- take_profit_short=((((InitialCapital + NetProfit) * risk)/100) * input_target_short);
- // Calcolo 2 Trailing Stop Long E Short
- trailing_stop_trigger_long1 = Entryprice + (entryprice * input_target_long /100) * (input_trailing_stop_trigger_long1/100);
- trailing_stop_close_long1 = entryprice + (entryprice * input_target_long /100) * (input_trailing_stop_close_long1/100);
- trailing_stop_trigger_short1 = Entryprice - (entryprice * input_target_short /100) * (input_trailing_stop_trigger_short1/100);
- trailing_stop_close_short1 = entryprice - (entryprice * input_target_short /100) * (input_trailing_stop_close_short1/100);
- trailing_stop_trigger_long2 = Entryprice + (entryprice * input_target_long /100) * (input_trailing_stop_trigger_long2/100);
- trailing_stop_close_long2 = entryprice + (entryprice * input_target_long /100) * (input_trailing_stop_close_long2/100);
- trailing_stop_trigger_short2 = Entryprice - (entryprice * input_target_short /100) * (input_trailing_stop_trigger_short2/100);
- trailing_stop_close_short2 = entryprice - (entryprice * input_target_short /100) * (input_trailing_stop_close_short2/100);
- {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))
- 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))
- 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))
- 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)));
- 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))
- 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))
- 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))
- 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)));}
- highesthigh = highest(high, Barssinceentry);
- 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);
- lowestlow = lowest(low, Barssinceentry);
- 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);
- 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
- begin;
- Buy("Long") nr_share contracts Next Bar at market;
- end;
- if marketposition = 1 Then
- begin;
- Setstopposition;
- SetStopLoss(stop_loss_long);
- Setprofittarget(take_profit_long);
- end;
- If MarketPosition =1 and trailing_long then
- Sell("Trailing Long") from entry("Long") Next Bar at market;
- 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
- begin;
- sellshort("Short") nr_share contracts Next Bar at market;
- end;
- if marketposition = -1 Then
- begin;
- Setstopposition;
- SetStopLoss(stop_loss_short);
- Setprofittarget(take_profit_short);
- end;
- If MarketPosition = -1 and trailing_short then
- buytocover("Trailing Short") from entry("Short") Next Bar at market;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement