Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 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 - Bot Scalping 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= +3%) (Stop Loss Limit Long/Short= -3% Tradingview-Hub) (Stop Loss Market Long/Short= NO) (Trailing Stop=NO) (Stop Emergenza= NO)
- // (Rischio Operazione 2% Perdita Media)
- // (In Sample Dal=01/02/2021 Al 01/10/2021) (Out Of Sample Dal=01/10/2021 Al 28/04/2022)
- // (Progettatta Il=25/04/2022)
- // 'Bot Scalping-Bot Ver-5 ETH/PERP FTX 5M LONG E SHORT'
- {*****************************************************************************
- Description : HeikinAshiSyn - This Paintbar is a Variation of the Heikin Ashi Candlestick to assist in reading the trend.
- ******************************************************************************}
- // Inputs ///////////////////////////////////////////////////////
- inputs: UpColor(RGB(0,192,255)),
- DnColor(RGB(255,128,64)),
- HiLoColor(DarkGray),
- CompBars(0),
- SmoothHA(False),
- SmoothAvgType(1 {1 JTHull, 2 SMA, 3 EMA, 4 wAverage} ),
- SmoothLength(6),
- ReverseColor(false),
- input_target_long(3),
- input_stop_loss_long(3),
- input_target_short(3),
- input_stop_loss_short(3),
- input_trailing_trigger_long (60),
- input_trailing_close_long (54),
- input_trailing_trigger_short (60),
- input_trailing_close_short (54),
- percent_risk(100),
- InitialCapital(100000),
- input_boombar_3_long(0.44),
- input_boombar_doji_long(0.44),
- input_boombar_3_short(0.34),
- input_boombar_doji_short(0.34),
- input_distanza_long(1.8), // distanza tra la haClose e la slowema
- input_distanza_short(2.4),
- mult_doji_long(0.2),
- mult_doji_short(0.26),
- lunghezza_adx_long(5),
- lunghezza_adx_short(7),
- differenziale_adx_basso_long(25),
- differenziale_adx_alto_long(75),
- differenziale_adx_basso_short(20),
- differenziale_adx_alto_short(80),
- lunghezza_rsi_long(15),
- lunghezza_rsi_short(6),
- differenziale_rsi_long(90),
- differenziale_rsi_short(24),
- solo_short(false),
- solo_long(false),
- {adx_neutrale_diff_input(0),
- dmi_min_diff_input_long(26.1),
- dmi_min_diff_input_short(32.6),}
- // Start Initializing Heiken Ashi ///////////////////////////////////////////////////////
- double FastPrice( Close ) [
- DisplayName = "FastPrice",
- ToolTip = "Enter an EasyLanguage expression to use in calculation of shorter length moving average."],
- double SlowPrice( Close ) [
- DisplayName = "SlowPrice",
- ToolTip = "Enter an EasyLanguage expression to use in calculation of longer length moving average."],
- double FastLength_long( 52 ) [
- DisplayName = "FastLength",
- ToolTip = "Enter number of bars to use in calculation of shorter length moving average."],
- double FastLength_short( 42 ) [
- DisplayName = "FastLength",
- ToolTip = "Enter number of bars to use in calculation of shorter length moving average."],
- double SlowLength_long( 82 ) [
- DisplayName = "SlowLength",
- ToolTip = "Enter number of bars to use in calculation of longer length moving average."],
- double SlowLength_short( 170 ) [
- DisplayName = "SlowLength",
- ToolTip = "Enter number of bars to use in calculation of longer length moving average."],
- int Displace( 0 ) [
- DisplayName = "Displace",
- ToolTip = "Displacement. Enter the number of bars by which plots will be displaced. Displacement may be positive (left) or negative (right)."];
- // End Initializing Heiken Ashi ///////////////////////////////////////////////////////
- // Initializing Variables ///////////////////////////////////////////////////////
- vars: haClose(0),haOpen(0),haHigh(0),haLow(0),
- color(0), newHi(0), newLo(0),
- iOpen(0), iClose(0), iHi(0), iLo(0),
- double FastEMA_long( 0 ),
- double FastEMA_short( 0 ),
- double SlowEMA_long( 0 ),
- double SlowEMA_short( 0 ),
- stop_loss_long(0),
- stop_loss_short(0),
- take_profit_long(0),
- take_profit_short(0),
- trailing_trigger_long(0),
- trailing_close_long(0),
- trailing_trigger_short(0),
- trailing_close_short(0),
- trailing_stop_trigger_long(0),
- trailing_stop_close_long(0),
- trailing_stop_trigger_short(0),
- trailing_stop_close_short(0),
- Trailing_Stop_Long(False),
- Trailing_Stop_Short(False),
- {trailing_long(false),
- trailing_short(false),
- trailing_long2(false),
- trailing_short2(false),}
- Cond_Entry_Long1(False),
- Cond_Entry_Long2(False),
- Cond_Entry_Short1(False),
- Cond_Entry_Short2(False),
- risk(0),
- nr_share(0),
- boombar_3_long(0),
- boombar_doji_long(0),
- boombar_3_short(0),
- boombar_doji_short(0),
- valore_adx_long(0),
- valore_adx_short(0),
- valore_rsi_long(0),
- valore_rsi_short(0),
- distanza_long(0),
- distanza_short(0),
- diffenziale_adx_long(0),
- diffenziale_adx_short(0);
- {di_pos(0),
- di_neg(0),
- adx_neutrale(0);}
- // Start Detecting Heiken Ashi ///////////////////////////////////////////////////////
- begin;
- if SmoothHA = False then begin;
- iOpen = Open;
- iClose = Close;
- iHi = High;
- iLo = Low;
- end else begin;
- if SmoothAvgType = 1 then begin;
- iOpen = jthma(Open, SmoothLength);
- iClose = jthma(Close, SmoothLength);
- iHi = jthma(High, SmoothLength);
- iLo = jthma(Low, SmoothLength);
- end;
- if SmoothAvgType = 2 then begin;
- iOpen = average(Open, SmoothLength);
- iClose = average(Close, SmoothLength);
- iHi = average(High, SmoothLength);
- iLo = average(Low, SmoothLength);
- end;
- if SmoothAvgType = 3 then begin;
- iOpen = xAverage(Open, SmoothLength);
- iClose = xAverage(Close, SmoothLength);
- iHi = xAverage(High, SmoothLength);
- iLo = xAverage(Low, SmoothLength);
- end;
- if SmoothAvgType = 4 then begin;
- iOpen = wAverage(Open, SmoothLength);
- iClose = wAverage(Close, SmoothLength);
- iHi = wAverage(High, SmoothLength);
- iLo = wAverage(Low, SmoothLength);
- end;
- end;
- if BarNumber > 1 then begin
- haClose = (iOpen+iHi+iLo+iClose)/4;
- haOpen = (haOpen [1] + haClose [1])/2 ;
- haHigh = MaxList(iHi, haOpen, haClose) ;
- haLow = MinList(iLo, haOpen, haClose) ;
- if haClose > haOpen then
- color = UpColor
- else
- color = DnColor;
- if CompBars > 0 then begin;
- for value1 = 1 to CompBars begin
- if haOpen <= MaxList(haOpen[value1],haClose[value1]) and
- haOpen >= MinList(haOpen[value1],haClose[value1]) and
- haClose <= MaxList(haOpen[value1],haClose[value1]) and
- haClose >= MinList(haOpen[value1],haClose[value1]) then
- color = color[value1];
- end;
- end;
- if ReverseColor then begin;
- if color = UpColor then
- color = DnColor
- else
- color = UpColor;
- end;
- {Plot1( haOpen, "Open", color ) ;
- Plot2( haClose, "Close", color ) ;
- Plot3( haHigh, "High", HiLoColor ) ;
- Plot4( haLow, "Low", HiLoColor ) ; }
- end else begin;
- haOpen = iOpen;
- haClose = (iOpen+iHi+iLo+iClose)/4;
- haHigh = MaxList( iHi, haOpen, haClose);
- haLow = MinList( iLo, haOpen,haClose);
- end;
- // End Detecting Heiken Ashi ///////////////////////////////////////////////////////
- // Calculating Variables ///////////////////////////////////////////////////////
- FastEMA_long = XAverage( haClose, FastLength_long );
- FastEMA_short = XAverage( haClose, FastLength_short );
- SlowEMA_long = XAverage( haClose, SlowLength_long );
- SlowEMA_short = XAverage( haClose, SlowLength_short );
- valore_adx_long = adx(lunghezza_adx_long);
- valore_adx_short = adx(lunghezza_adx_short);
- valore_rsi_long = rsi(close, lunghezza_rsi_long);
- valore_rsi_short = rsi(close, lunghezza_rsi_short);
- boombar_3_long = haClose[1] / 100 * input_boombar_3_long;
- boombar_3_short = haClose[1] / 100 *input_boombar_3_short;
- boombar_doji_long = haClose[1] / 100 * input_boombar_doji_long;
- boombar_doji_short = haClose[1] / 100 * input_boombar_doji_short;
- distanza_long = SlowEma_long / 100 * input_distanza_long;
- distanza_short = SlowEma_short / 100 * input_distanza_short;
- {adx_neutrale = adx(14);
- diffenziale_adx = adx_neutrale + (adx_neutrale/100*adx_neutrale_diff_input);
- di_pos = (dmiPlus(14));
- di_neg = (dmiMinus(14));}
- // Money menagment ///////////////////////////////////////////////////////
- risk = percent_risk/100;
- nr_share = floor((InitialCapital + NetProfit) * risk) / close;
- stop_loss_long=((((InitialCapital + NetProfit) * risk)/100) * input_stop_loss_long);
- stop_loss_short=((((InitialCapital + NetProfit) * risk)/100) * input_stop_loss_short);
- take_profit_long=((((InitialCapital + NetProfit) * risk)/100) * input_target_long);
- take_profit_short=((((InitialCapital + NetProfit) * risk)/100) * input_target_short);
- //Variabili Trailing Stop Long e Short
- trailing_stop_trigger_long = Entryprice + (entryprice * input_target_long /100) * (input_trailing_trigger_long / 100);
- trailing_stop_close_long = entryprice + (entryprice * input_target_long /100) * (input_trailing_close_long / 100);
- trailing_stop_trigger_short = Entryprice - (entryprice * input_target_short /100) * (input_trailing_trigger_short / 100);
- trailing_stop_close_short = entryprice - (entryprice * input_target_short /100) * (input_trailing_close_short / 100);
- //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
- //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
- // Definizione Entrate Long 1 e 2
- 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;
- 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;
- // Definizione Entrate Short 1 e 2
- 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;
- 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;
- // Cond Entry Long 1 E 2
- // Stop Loss E Take Profit Limit Sono In Fine Al Codice
- if marketposition = 0 and (Cond_Entry_Long1 or Cond_Entry_Long2) 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;
- // Exit Traling Stop Long
- If MarketPosition =1 and Trailing_Stop_Long then
- Sell("Trailing Long") from entry("Long") Next Bar at market;
- // Cond Entry Short 1 E 2
- // Stop Loss E Take Profit Limit Sono In Fine Al Codice
- if marketposition = 0 and (Cond_Entry_Short1 or Cond_Entry_Short2) 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;
- // Exit Traling Stop Short
- If MarketPosition = -1 and Trailing_Stop_Short then
- Buytocover("Trailing Short") from entry("Short") Next Bar at market;
- end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement