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 Break-in-New-Trailing-Gabriele Ver-5 (Strategia Breakout) Parte 1
- // (Exchange= FTX) (Sottostante ETH-PERP) (Timeframe= 4H) (Direzione= LONG E SHORT) (Swing Posizione= SI) (Esclusione Ore=NO) (Esclusione Giorni=NO') (Esclusione Mesi=NO)
- // (Take Profit Long/Short Market = Trailing) (Take Profit Limit Long/Short= +18%) (Stop Loss Limit Long/Short= -12%) (Stop Loss Market Long/Short= NO) (Trailing Stop=SI) (Stop Emergenza= NO)
- // (Rischio Operazione 2% Perdita Media)
- // (In Sample Dal=17/08/2017 Al 17/10/2020) (Out Of Sample Dal=18/10/2020 Al 15/03/2021)
- // Auentare il Max Bars Back Su Tradestation Altrimenti Non Funziona Il Conteggio Barssinceentry 500
- // Abilitare Anche Enable Strategy Da Stadies Per Ricaricarla Altrimenti Non Funziona
- //Fase iniziale parametri di input
- input:
- InitialCapital(100000),
- percent_risk(8.8),
- input_stop_loss_percent_long(12),
- input_target_percent_long(18),
- input_stop_loss_percent_short(12),
- input_target_percent_short(18),
- input_trailing_trigger_long(60),
- input_trailing_close_long (54),
- input_trailing_trigger_short (60),
- input_trailing_close_short (54),
- lunghezza_ema_long (240),
- lunghezza_ema_short (240),
- input_atr_perdiod_long(11),
- input_atr_perdiod_short(11),
- input_atr_mult_long(1),
- input_atr_mult_short(1),
- //skipday(thursday),
- //skipmonth1(9),
- //skipmonth2(8),
- //skipday(monday),
- solo_long(false),
- solo_short(false);
- Vars:
- stop_loss_long(0),
- stop_loss_short(0),
- target_long(0),
- target_short(0),
- ema_long(0),
- ema_short(0),
- valore_atr_long(0),
- valore_atr_short(0),
- trailing_stop_trigger_long(0),
- trailing_stop_close_long(0),
- trailing_stop_trigger_short(0),
- trailing_stop_close_short(0),
- trailing_long(false),
- trailing_short(false),
- highesthigh(0),
- lowestlow(0),
- account_equity(0),
- risk(0),
- nr_share(0);
- // Calcololo degli indicatori long
- valore_atr_long = AvgTrueRange(input_atr_perdiod_long);
- valore_atr_short = AvgTrueRange(input_atr_perdiod_short);
- ema_long = XAverage(close, lunghezza_ema_long);
- ema_short = XAverage(close, lunghezza_ema_short);
- // Money menagment
- risk = percent_risk/100;
- nr_share = floor((InitialCapital + NetProfit) * risk) / close;
- stop_loss_long=((((InitialCapital + NetProfit) * risk)/100) * input_stop_loss_percent_long);
- stop_loss_short=((((InitialCapital + NetProfit) * risk)/100) * input_stop_loss_percent_short);
- target_long=((((InitialCapital + NetProfit) * risk)/100) * input_target_percent_long);
- target_short=((((InitialCapital + NetProfit) * risk)/100) * input_target_percent_short);
- // Calcolo Trailing Stop Long E Short
- trailing_stop_trigger_long = Entryprice + (entryprice * input_target_percent_long /100) * (input_trailing_trigger_long/100);
- trailing_stop_close_long = entryprice + (entryprice * input_target_percent_long /100) * (input_trailing_close_long/100);
- trailing_stop_trigger_short = Entryprice - (entryprice * input_target_percent_short /100) * (input_trailing_trigger_short/100);
- trailing_stop_close_short = entryprice - (entryprice * input_target_percent_short /100) * (input_trailing_close_short/100);
- highesthigh = highest(high, Barssinceentry);
- trailing_long = (highesthigh >= trailing_stop_trigger_long and close <= trailing_stop_close_long);
- lowestlow = lowest(low, Barssinceentry);
- trailing_short = (lowestlow <= trailing_stop_trigger_short and close >= trailing_stop_close_short);
- // Entrata Long
- 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
- Buy("Long") nr_share contracts Next Bar at market;
- If MarketPosition =1 then
- Begin;
- Setstopposition;
- SetStopLoss(stop_loss_long);
- Setprofittarget(target_long);
- End;
- // Uscita Long
- // Trailing Stop Long
- If MarketPosition =1 and trailing_long then
- Sell("Trailing Long") from entry("Long") Next Bar at market;
- // Entrata Short
- if Absvalue(open-close) > (valore_atr_short * input_atr_mult_short) and close < open and close < ema_short and not solo_long then //
- Sellshort("Short") nr_share Contracts Next Bar at market;
- If MarketPosition =-1 then
- Begin;
- Setstopposition;
- SetStopLoss(stop_loss_short);
- Setprofittarget(target_short);
- End;
- // Uscita Short
- // Trailing Stop Short
- 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