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)
- //@version=5
- //1. Strategia
- strategy(title='Bot Break-in-New-Trailing-Gabriele Ver-5 ETH/PERP FTX 4H LONG E SHORT', overlay=true,
- max_bars_back=5000, // Serve Per Caricare Più Storico Per Il Trailing Stop
- pyramiding=0,
- initial_capital=150,
- commission_type=strategy.commission.percent,
- commission_value=0.1,
- slippage=3,
- default_qty_type=strategy.percent_of_equity,
- default_qty_value=8.8)
- // Input
- input_stop_loss_long = input.float(title='stop_loss_long', defval=12, minval=0, maxval=100, step=0.1, group='Stop Loss')
- input_take_profit_long = input.float(title='take_profit_long', defval=18, minval=0, maxval=100, step=0.1, group='Take Profit')
- input_stop_loss_short = input.float(title='stop_loss_short', defval=12, minval=0, maxval=100, step=0.1, group='Stop Loss')
- input_take_profit_short = input.float(title='take_profit_short', defval=18, minval=0, maxval=100, step=0.1, group='Take Profit')
- input_trailing_trigger_long = input.float(title='trailing_trigger_long', defval=60, minval=0, maxval=100, step=1, group='Traling Stop')
- input_trailing_close_long = input.float(title='trailing_close_long', defval=54, minval=0, maxval=100, step=1, group='Traling Stop')
- input_trailing_trigger_short = input.float(title='trailing_trigger_short', defval=60, minval=0, maxval=100, step=1, group='Traling Stop')
- input_trailing_close_short = input.float(title='trailing_close_short', defval=54, minval=0, maxval=100, step=1, group='Traling Stop')
- input_lunghezza_ema_long = input.int(title='lunghezza_ema_long', defval=240, minval=0, maxval=300, step=5, group='Medie')
- input_lunghezza_ema_short = input.int(title='lunghezza_ema_short', defval=240, minval=0, maxval=300, step=5, group='Medie')
- in_solo_long = input.bool(title='Solo long', defval=false, inline='1', group='Direzione')
- in_solo_short = input.bool(title='Solo short', defval=false, inline='1', group='Direzione')
- riskPerTrade = input.float(title='Risk Per Trade %', minval=0.1, maxval=100, defval=8.8, step=0.5)
- // Calcolo del range del backtest
- startDate = input.int(title="Start Date",
- defval=17, minval=1, maxval=31, group="Periodo")
- startMonth = input.int(title="Start Month",
- defval=08, minval=1, maxval=12, group="Periodo")
- startYear = input.int(title="Start Year",
- defval=2016, minval=1800, maxval=2150, group="Periodo")
- endDate = input.int(title="End Date",
- defval=01, minval=1, maxval=31, group="Periodo")
- endMonth = input.int(title="End Month",
- defval=01, minval=1, maxval=12, group="Periodo")
- endYear = input.int(title="End Year",
- defval=2121, minval=1800, maxval=2150, group="Periodo")
- inDateRange = (time >= timestamp(syminfo.timezone, startYear,
- startMonth, startDate, 0, 0)) and
- (time < timestamp(syminfo.timezone, endYear, endMonth, endDate, 0, 0))
- // Start Hour Range Trading Non Attivo /////////////////////
- //hourTrading = input(title='sessione valida di trading', defval='0600-2300:23456')
- //hourRangeTrading = time(timeframe.period, hourTrading)
- // Start Detecting ATR Long ///////////////////////////////////////////////////////
- length_long = input.int(title="Atr Length_long", defval=11, minval=0)
- smoothing_long = input.string(title="Smoothing_long", defval="SMA", options=["RMA", "SMA", "EMA", "WMA"])
- ma_function_long(source, length_long) =>
- switch smoothing_long
- "RMA" => ta.rma(source, length_long)
- "SMA" => ta.sma(source, length_long)
- "EMA" => ta.ema(source, length_long)
- => ta.wma(source, length_long)
- plot(ma_function_long(ta.tr(true), length_long), title = "ATR_long", color=color.new(#B71C1C, 0))
- // End Detecting ATR Long ///////////////////////////////////////////////////////
- // Start Detecting ATR Short ///////////////////////////////////////////////////////
- length_short = input.int(title="Atr Length_short", defval=11, minval=0)
- smoothing_short = input.string(title="Smoothing_short", defval="SMA", options=["RMA", "SMA", "EMA", "WMA"])
- ma_function_short(source, length_short) =>
- switch smoothing_short
- "RMA" => ta.rma(source, length_short)
- "SMA" => ta.sma(source, length_short)
- "EMA" => ta.ema(source, length_short)
- => ta.wma(source, length_short)
- plot(ma_function_short(ta.tr(true), length_short), title = "ATR_short", color=color.new(#B71C1C, 0))
- // End Detecting ATR Short ///////////////////////////////////////////////////////
- // Variabili ATR Long e Short e Variabili Multiplier Long e Short
- in_atr_Mult_long = input.float(title='atr_Mult_long', minval=0, maxval=5, defval=1, step=0.5)
- in_atr_Mult_short = input.float(title='atr_Mult_short', minval=0, maxval=5, defval=1, step=0.5)
- atr_long = ma_function_long(ta.tr(true), length_long)
- atr_short = ma_function_short(ta.tr(true), length_short)
- //Variabili Medie Long e Short
- media_long = ta.ema(close, input_lunghezza_ema_long)
- media_short = ta.ema(close, input_lunghezza_ema_short)
- plot(media_long, title = "media_long", color=color.blue)
- plot(media_short, title = "media_short", color=color.purple)
- // Variabili Stop Loss Long
- stop_loss_long_price = strategy.opentrades.entry_price(0) - (strategy.opentrades.entry_price(0) * input_stop_loss_long) / 100
- stop_loss_long = (strategy.opentrades.entry_price(0) - stop_loss_long_price) / syminfo.mintick
- take_profit_long_price = (strategy.opentrades.entry_price(0) + ((strategy.opentrades.entry_price(0) * input_take_profit_long) / 100))
- take_profit_long = (take_profit_long_price - strategy.opentrades.entry_price(0)) / syminfo.mintick
- //plot(stop_loss_long, title = "sl_long_ticks", color=color.purple)
- // Variabili Stop Loss Short
- stop_loss_short_price = strategy.opentrades.entry_price(0) + (strategy.opentrades.entry_price(0) * input_stop_loss_short) / 100
- stop_loss_short = (stop_loss_short_price - strategy.opentrades.entry_price(0)) / syminfo.mintick
- take_profit_short_price = (strategy.opentrades.entry_price(0) - ((strategy.opentrades.entry_price(0) * input_take_profit_short) / 100))
- take_profit_short =(strategy.opentrades.entry_price(0) - take_profit_short_price) / syminfo.mintick
- //plot(stop_loss_short, title = "sl_short_ticks", color=color.purple)
- // Variabili Stop Loss Long
- // stop_loss_long_price = strategy.position_avg_price - (strategy.position_avg_price * input_stop_loss_long) / 100
- // stop_loss_long = (strategy.position_avg_price - stop_loss_long_price) / syminfo.mintick
- // take_profit_long_price = strategy.position_avg_price + (strategy.position_avg_price * input_take_profit_long) / 100
- // take_profit_long = (take_profit_long_price - strategy.position_avg_price) / syminfo.mintick
- // plot(stop_loss_long, title = "sl_long_ticks", color=color.purple)
- // Variabili Stop Loss Short
- // stop_loss_short_price = strategy.position_avg_price + (strategy.position_avg_price * input_stop_loss_short) / 100
- // stop_loss_short = (stop_loss_short_price - strategy.position_avg_price) / 0.1
- // take_profit_short_price = (strategy.position_avg_price - ((strategy.position_avg_price * input_take_profit_short) / 100))
- // take_profit_short =(strategy.position_avg_price - take_profit_short_price) / 0.1
- // plot(stop_loss_short, title = "sl_short_ticks", color=color.purple)
- // Calcolo Trailing Stop Long e Short
- trailing_stop_trigger_long = strategy.opentrades.entry_price(0) + ( strategy.opentrades.entry_price(0) * input_take_profit_long / 100) * (input_trailing_trigger_long / 100)
- trailing_stop_close_long = strategy.opentrades.entry_price(0) + ( strategy.opentrades.entry_price(0) * input_take_profit_long / 100) * (input_trailing_close_long / 100)
- trailing_stop_trigger_short = strategy.opentrades.entry_price(0) - ( strategy.opentrades.entry_price(0) * input_take_profit_short / 100) * (input_trailing_trigger_short / 100)
- trailing_stop_close_short = strategy.opentrades.entry_price(0) - ( strategy.opentrades.entry_price(0) * input_take_profit_short / 100) * (input_trailing_close_short / 100)
- // Condizione Uscita Cross Trailing Stop Long E Short
- //cond_exit_long = high >= trailing_stop_long_trigger_high and ta.crossunder(close, trailing_stop_close_long_low) or high[1] >= trailing_stop_long_trigger_high and ta.crossunder(close, trailing_stop_close_long_low) or high[2] >= trailing_stop_long_trigger_high and ta.crossunder(close, trailing_stop_close_long_low) or high[3] >= trailing_stop_long_trigger_high and ta.crossunder(close, trailing_stop_close_long_low) or
- // high[4] >= trailing_stop_long_trigger_high and ta.crossunder(close, trailing_stop_close_long_low) or high[5] >= trailing_stop_long_trigger_high and ta.crossunder(close, trailing_stop_close_long_low) or high[6] >= trailing_stop_long_trigger_high and ta.crossunder(close, trailing_stop_close_long_low) or high[7] >= trailing_stop_long_trigger_high and ta.crossunder(close, trailing_stop_close_long_low) or
- // high[8] >= trailing_stop_long_trigger_high and ta.crossunder(close, trailing_stop_close_long_low) or high[9] >= trailing_stop_long_trigger_high and ta.crossunder(close, trailing_stop_close_long_low) or high[10] >= trailing_stop_long_trigger_high and ta.crossunder(close, trailing_stop_close_long_low) or high[11] >= trailing_stop_long_trigger_high and ta.crossunder(close, trailing_stop_close_long_low) or
- // high[12] >= trailing_stop_long_trigger_high and ta.crossunder(close, trailing_stop_close_long_low) or high[13] >= trailing_stop_long_trigger_high and ta.crossunder(close, trailing_stop_close_long_low) or high[14] >= trailing_stop_long_trigger_high and ta.crossunder(close, trailing_stop_close_long_low) or high[15] >= trailing_stop_long_trigger_high and ta.crossunder(close, trailing_stop_close_long_low) or
- // high[16] >= trailing_stop_long_trigger_high and ta.crossunder(close, trailing_stop_close_long_low)
- //cond_exit_short = low <= trailing_stop_short_trigger_low and ta.crossover(close, trailing_stop_close_short_high) or low[1] <= trailing_stop_short_trigger_low and ta.crossover(close, trailing_stop_close_short_high) or low[2] <= trailing_stop_short_trigger_low and ta.crossover(close, trailing_stop_close_short_high) or low[3] <= trailing_stop_short_trigger_low and ta.crossover(close, trailing_stop_close_short_high) or
- // low[4] <= trailing_stop_short_trigger_low and ta.crossover(close, trailing_stop_close_short_high) or low[5] <= trailing_stop_short_trigger_low and ta.crossover(close, trailing_stop_close_short_high) or low[6] <= trailing_stop_short_trigger_low and ta.crossover(close, trailing_stop_close_short_high) or low[7] <= trailing_stop_short_trigger_low and ta.crossover(close, trailing_stop_close_short_high) or
- // low[8] <= trailing_stop_short_trigger_low and ta.crossover(close, trailing_stop_close_short_high) or low[9] <= trailing_stop_short_trigger_low and ta.crossover(close, trailing_stop_close_short_high) or low[10] <= trailing_stop_short_trigger_low and ta.crossover(close, trailing_stop_close_short_high) or low[11] <= trailing_stop_short_trigger_low and ta.crossover(close, trailing_stop_close_short_high) or
- // low[12] <= trailing_stop_short_trigger_low and ta.crossover(close, trailing_stop_close_short_high) or low[13] <= trailing_stop_short_trigger_low and ta.crossover(close, trailing_stop_close_short_high) or low[14] <= trailing_stop_short_trigger_low and ta.crossover(close, trailing_stop_close_short_high) or low[15] <= trailing_stop_short_trigger_low and ta.crossover(close, trailing_stop_close_short_high) or
- // low[16] <= trailing_stop_short_trigger_low and ta.crossover(close, trailing_stop_close_short_high)
- // Condizione Uscita Close Trailing Stop Long E Short
- // condExitLong = high >= trailing_stop_trigger_long and close < trailing_stop_close_long or high[1] >= trailing_stop_trigger_long and close < trailing_stop_close_long or high[2] >= trailing_stop_trigger_long and close < trailing_stop_close_long or high[3] >= trailing_stop_trigger_long and close < trailing_stop_close_long or
- // high[4] >= trailing_stop_trigger_long and close < trailing_stop_close_long or high[5] >= trailing_stop_trigger_long and close < trailing_stop_close_long or high[6] >= trailing_stop_trigger_long and close < trailing_stop_close_long or high[7] >= trailing_stop_trigger_long and close < trailing_stop_close_long or
- // high[8] >= trailing_stop_trigger_long and close < trailing_stop_close_long or high[9] >= trailing_stop_trigger_long and close < trailing_stop_close_long or high[10] >= trailing_stop_trigger_long and close < trailing_stop_close_long or high[11] >= trailing_stop_trigger_long and close < trailing_stop_close_long or
- // high[12] >= trailing_stop_trigger_long and close < trailing_stop_close_long or high[13] >= trailing_stop_trigger_long and close < trailing_stop_close_long or high[14] >= trailing_stop_trigger_long and close < trailing_stop_close_long or high[15] >= trailing_stop_trigger_long and close < trailing_stop_close_long or
- // high[16] >= trailing_stop_trigger_long and close < trailing_stop_close_long
- // condExitShort = low <= trailing_stop_trigger_short and close >= trailing_stop_close_short or low[1] <= trailing_stop_trigger_short and close >= trailing_stop_close_short or low[2] <= trailing_stop_trigger_short and close >= trailing_stop_close_short or low[3] <= trailing_stop_trigger_short and close >= trailing_stop_close_short or
- // low[4] <= trailing_stop_trigger_short and close >= trailing_stop_close_short or low[5] <= trailing_stop_trigger_short and close >= trailing_stop_close_short or low[6] <= trailing_stop_trigger_short and close >= trailing_stop_close_short or low[7] <= trailing_stop_trigger_short and close >= trailing_stop_close_short or
- // low[8] <= trailing_stop_trigger_short and close >= trailing_stop_close_short or low[9] <= trailing_stop_trigger_short and close >= trailing_stop_close_short or low[10] <= trailing_stop_trigger_short and close >= trailing_stop_close_short or low[11] <= trailing_stop_trigger_short and close >= trailing_stop_close_short or
- // low[12] <= trailing_stop_trigger_short and close >= trailing_stop_close_short or low[13] <= trailing_stop_trigger_short and close >= trailing_stop_close_short or low[14] <= trailing_stop_trigger_short and close >= trailing_stop_close_short or low[15] <= trailing_stop_trigger_short and close >= trailing_stop_close_short or
- // low[16] <= trailing_stop_trigger_short and close >= trailing_stop_close_short
- // Condizione Uscita Close Trailing Stop E Close [1] > < Long E Short
- // condExitLong = high >= trailing_stop_trigger_long and close <= trailing_stop_close_long and close[1] > trailing_stop_close_long or high[1] >= trailing_stop_trigger_long and close <= trailing_stop_close_long and close[1] > trailing_stop_close_long or high[2] >= trailing_stop_trigger_long and close <= trailing_stop_close_long and close[1] > trailing_stop_close_long or high[3] >= trailing_stop_trigger_long and close <= trailing_stop_close_long and close[1] > trailing_stop_close_long or
- // high[4] >= trailing_stop_trigger_long and close <= trailing_stop_close_long and close[1] > trailing_stop_close_long or high[5] >= trailing_stop_trigger_long and close <= trailing_stop_close_long and close[1] > trailing_stop_close_long or high[6] >= trailing_stop_trigger_long and close <= trailing_stop_close_long and close[1] > trailing_stop_close_long or high[7] >= trailing_stop_trigger_long and close <= trailing_stop_close_long and close[1] > trailing_stop_close_long or
- // high[8] >= trailing_stop_trigger_long and close <= trailing_stop_close_long and close[1] > trailing_stop_close_long or high[9] >= trailing_stop_trigger_long and close <= trailing_stop_close_long and close[1] > trailing_stop_close_long or high[10] >= trailing_stop_trigger_long and close <= trailing_stop_close_long and close[1] > trailing_stop_close_long or high[11] >= trailing_stop_trigger_long and close <= trailing_stop_close_long and close[1] > trailing_stop_close_long or
- // high[12] >= trailing_stop_trigger_long and close <= trailing_stop_close_long and close[1] > trailing_stop_close_long or high[13] >= trailing_stop_trigger_long and close <= trailing_stop_close_long and close[1] > trailing_stop_close_long or high[14] >= trailing_stop_trigger_long and close <= trailing_stop_close_long and close[1] > trailing_stop_close_long or high[15] >= trailing_stop_trigger_long and close <= trailing_stop_close_long and close[1] > trailing_stop_close_long or
- // high[16] >= trailing_stop_trigger_long and close <= trailing_stop_close_long and close[1] > trailing_stop_close_long
- // condExitShort = low <= trailing_stop_trigger_short and close >= trailing_stop_close_short and close[1] < trailing_stop_close_short or low[1] <= trailing_stop_trigger_short and close >= trailing_stop_close_short and close[1] < trailing_stop_close_short or low[2] <= trailing_stop_trigger_short and close >= trailing_stop_close_short and close[1] < trailing_stop_close_short or low[3] <= trailing_stop_trigger_short and close >= trailing_stop_close_short and close[1] < trailing_stop_close_short or
- // low[4] <= trailing_stop_trigger_short and close >= trailing_stop_close_short and close[1] < trailing_stop_close_short or low[5] <= trailing_stop_trigger_short and close >= trailing_stop_close_short and close[1] < trailing_stop_close_short or low[6] <= trailing_stop_trigger_short and close >= trailing_stop_close_short and close[1] < trailing_stop_close_short or low[7] <= trailing_stop_trigger_short and close >= trailing_stop_close_short and close[1] < trailing_stop_close_short or
- // low[8] <= trailing_stop_trigger_short and close >= trailing_stop_close_short and close[1] < trailing_stop_close_short or low[9] <= trailing_stop_trigger_short and close >= trailing_stop_close_short and close[1] < trailing_stop_close_short or low[10] <= trailing_stop_trigger_short and close >= trailing_stop_close_short and close[1] < trailing_stop_close_short or low[11] <= trailing_stop_trigger_short and close >= trailing_stop_close_short and close[1] < trailing_stop_close_short or
- // low[12] <= trailing_stop_trigger_short and close >= trailing_stop_close_short and close[1] < trailing_stop_close_short or low[13] <= trailing_stop_trigger_short and close >= trailing_stop_close_short and close[1] < trailing_stop_close_short or low[14] <= trailing_stop_trigger_short and close >= trailing_stop_close_short and close[1] < trailing_stop_close_short or low[15] <= trailing_stop_trigger_short and close >= trailing_stop_close_short and close[1] < trailing_stop_close_short or
- // low[16] <= trailing_stop_trigger_short and close >= trailing_stop_close_short and close[1] < trailing_stop_close_short
- plot(strategy.position_size != 0 ? strategy.opentrades.entry_price(0) : na , color=strategy.position_size > 0 ? color.blue : strategy.position_size < 0 ? color.red : na, style=plot.style_linebr, title="entry_price") // stampa l'entry price in rosso se short in blu se long
- plot(strategy.position_size > 0 ? take_profit_long_price : strategy.position_size < 0 ? take_profit_short_price: na, color=color.green, style=plot.style_cross, linewidth=2, title="tk_limit")
- plot(strategy.position_size > 0 ? stop_loss_long_price : strategy.position_size < 0 ? stop_loss_short_price: na, color=color.red, style=plot.style_cross, linewidth=2, title="sl_limit")
- plot(strategy.position_size > 0 ? trailing_stop_trigger_long : na, color=color.blue, style=plot.style_cross, linewidth=2, title="trail_trigger_long")
- plot(strategy.position_size > 0 ? trailing_stop_close_long : na, color=color.blue, style=plot.style_cross, linewidth=2, title="trail_close_long")
- plot(strategy.position_size < 0 ? trailing_stop_trigger_short : na, color=color.blue, style=plot.style_cross, linewidth=2, title="trail_trigger_short")
- plot(strategy.position_size < 0 ? trailing_stop_close_short : na, color=color.blue, style=plot.style_cross, linewidth=2, title="trail_close_short")
- bgcolor(strategy.position_size > 0 ? color.green : strategy.position_size < 0 ? color.red : na, transp=90) // sfondo verde quando siamo long, sfondo rosso quando siamo short, no sfondo quando non siamo in posizione
- // Calcolo Uscita Trailing Stop Long E Short
- // Bar_index = bar_index
- // plot(Bar_index, title = "Bar_index")
- // entry_bar_index = strategy.opentrades.entry_bar_index(0) +1
- // plot(entry_bar_index, title = "entry_bar_index")
- range_barre_trailing = bar_index - strategy.opentrades.entry_bar_index(0) +1
- //plot(lunghezza_trailing, title = 'lunghezza')
- highesthigh = strategy.opentrades ==1 ? ta.highest(high, range_barre_trailing): na
- //plot(highesthigh)
- lowestlow = strategy.opentrades ==1 ? ta.lowest(low, range_barre_trailing): na
- //plot(lowestlow)
- // Plot No Trading Allowed giorni da 1 a 7 1 è Domenica. Mesi da 1 a 12 1 è Gennaio
- //giorni_esclusi = dayofweek(time)
- //plotshape(giorni_esclusi[1] == 2 ? giorni_esclusi : na, color=color.green, title="giorni_esclusi")
- //mesi_esclusi = month(time)
- //plotshape(mesi_esclusi[1] == 9 ? mesi_esclusi : na, color=color.yellow, title="mesi_esclusi")
- // giorni da 1 a 7 1 è domenica. Entrambe le possibilità sono disponibili sia il cross, sia la close del livello trailing stop close
- //Condizione Entrata Long
- cond_long = math.abs(open - close) > atr_long * in_atr_Mult_long and close > open and close > media_long and not in_solo_short and inDateRange //and month != 9 and dayofweek != 2
- //Condizione Entrata Short
- cond_short = math.abs(open - close) > atr_short * in_atr_Mult_short and close < open and close < media_short and not in_solo_long and inDateRange // and month != 9 and dayofweek != 2
- barcolor(cond_long ? color.lime : cond_short ? color.purple : na)
- // Condizione Uscita Trailing Stop Long
- condExitLong = (highesthigh > trailing_stop_trigger_long and close <= trailing_stop_close_long)
- // Condizione Uscita Trailing Stop Short
- condExitShort = (lowestlow < trailing_stop_trigger_short and close >= trailing_stop_close_short)
- // isLong = false
- // if strategy.position_size > 0
- // isLong := true
- // isShort = false
- // if strategy.position_size < 0
- // isShort:= true
- // cond_long2 = cond_long and not isLong[1]// and not isLong[0]
- // cond_short2 = cond_short and not isShort[1]// and not isShort[0]
- // Allerts
- buy_command = '{"BUY COMMAND"}'
- sell_command = '{"SELL COMMAND"}'
- close_command = '{"CLOSE COMMAND"}'
- //entrata e uscita Long
- if cond_long // strategy.opentrades == 0
- strategy.entry('operazioneLong', strategy.long, alert_message = "Open Long Position", comment = buy_command)
- if strategy.opentrades ==1
- strategy.exit('SL e TP', from_entry='operazioneLong', loss = stop_loss_long, profit = take_profit_long, alert_message = "Your Long SL-TP Has Been Triggered.", comment = close_command)
- if condExitLong and strategy.opentrades == 1
- strategy.close('operazioneLong', alert_message = "Close Long Position", comment = close_command)
- //entrata e uscita Short
- if cond_short //and strategy.opentrades == 0
- strategy.entry('operazioneShort', strategy.short, alert_message = "Open Short position", comment = sell_command)
- if strategy.opentrades ==1
- strategy.exit('SL e TP', from_entry='operazioneShort', loss = stop_loss_short, profit = take_profit_short, alert_message = "Your Short SL-TP Has Been Triggered.", comment = close_command)
- if condExitShort and strategy.opentrades == 1
- strategy.close('operazioneShort', alert_message = "Close Short Position", comment = close_command)
- // Nome Alert: Break-In-New-Trailing-Gabriele-ETH-PERP-4H
- // Commento Alert: {{strategy.order.comment}}
- // ----------------- Inizio Tabella risultati mensili. Per visualizzare andare nelle impostazioni proprietà e spuntare ad ogni tick -----------------
- // new_month = month(time) != month(time[1])
- // new_year = year(time) != year(time[1])
- // eq = strategy.equity
- // bar_pnl = eq / eq[1] - 1
- // cur_month_pnl = 0.0
- // cur_year_pnl = 0.0
- // // Current Monthly P&L
- // cur_month_pnl := new_month ? 0.0 :
- // (1 + cur_month_pnl[1]) * (1 + bar_pnl) - 1
- // // Current Yearly P&L
- // cur_year_pnl := new_year ? 0.0 :
- // (1 + cur_year_pnl[1]) * (1 + bar_pnl) - 1
- // // Arrays to store Yearly and Monthly P&Ls
- // var month_pnl = array.new_float(0)
- // var month_time = array.new_int(0)
- // var year_pnl = array.new_float(0)
- // var year_time = array.new_int(0)
- // last_computed = false
- // if (not na(cur_month_pnl[1]) and (new_month or barstate.islast))
- // if (last_computed[1])
- // array.pop(month_pnl)
- // array.pop(month_time)
- // array.push(month_pnl , cur_month_pnl[1])
- // array.push(month_time, time[1])
- // if (not na(cur_year_pnl[1]) and (new_year or barstate.islast))
- // if (last_computed[1])
- // array.pop(year_pnl)
- // array.pop(year_time)
- // array.push(year_pnl , cur_year_pnl[1])
- // array.push(year_time, time[1])
- // last_computed := barstate.islast ? true : nz(last_computed[1])
- // // Monthly P&L Table
- // var monthly_table = table(na)
- // prec = input(2, title = "Return Precision")
- // if (barstate.islast)
- // monthly_table := table.new(position.bottom_right, columns = 14, rows = array.size(year_pnl) + 1, bgcolor=#0F0F0F,border_width=1,border_color=#000000)
- // table.cell(monthly_table, 0, 0, "", text_color=#D3D3D3, bgcolor=#0F0F0F)
- // table.cell(monthly_table, 1, 0, "Jan", text_color=#D3D3D3, bgcolor=#0F0F0F)
- // table.cell(monthly_table, 2, 0, "Feb", text_color=#D3D3D3, bgcolor=#0F0F0F)
- // table.cell(monthly_table, 3, 0, "Mar", text_color=#D3D3D3, bgcolor=#0F0F0F)
- // table.cell(monthly_table, 4, 0, "Apr", text_color=#D3D3D3, bgcolor=#0F0F0F)
- // table.cell(monthly_table, 5, 0, "May", text_color=#D3D3D3, bgcolor=#0F0F0F)
- // table.cell(monthly_table, 6, 0, "Jun", text_color=#D3D3D3, bgcolor=#0F0F0F)
- // table.cell(monthly_table, 7, 0, "Jul", text_color=#D3D3D3, bgcolor=#0F0F0F)
- // table.cell(monthly_table, 8, 0, "Aug", text_color=#D3D3D3, bgcolor=#0F0F0F)
- // table.cell(monthly_table, 9, 0, "Sep", text_color=#D3D3D3, bgcolor=#0F0F0F)
- // table.cell(monthly_table, 10, 0, "Oct", text_color=#D3D3D3, bgcolor=#0F0F0F)
- // table.cell(monthly_table, 11, 0, "Nov", text_color=#D3D3D3, bgcolor=#0F0F0F)
- // table.cell(monthly_table, 12, 0, "Dec", text_color=#D3D3D3, bgcolor=#0F0F0F)
- // table.cell(monthly_table, 13, 0, "Year", text_color=#D3D3D3, bgcolor=#0F0F0F)
- // for yi = 0 to array.size(year_pnl) - 1
- // table.cell(monthly_table, 0, yi + 1, str.tostring(year(array.get(year_time, yi))), text_color=#D3D3D3, bgcolor=#0F0F0F)
- // y_color = array.get(year_pnl, yi) > 0 ? color.lime : color.red
- // table.cell(monthly_table, 13, yi + 1, str.tostring(math.round(array.get(year_pnl, yi) * 100, prec)), bgcolor = y_color)
- // for mi = 0 to array.size(month_time) - 1
- // m_row = year(array.get(month_time, mi)) - year(array.get(year_time, 0)) + 1
- // m_col = month(array.get(month_time, mi))
- // m_color = array.get(month_pnl, mi) > 0 ? color.lime : color.red
- // table.cell(monthly_table, m_col, m_row, str.tostring(math.round(array.get(month_pnl, mi) * 100, prec)), bgcolor = m_color)
- // ----------------- Fine Tabella risultati mensili. Per visualizzare andare nelle impostazioni proprietà e spuntare ad ogni tick -----------------
Add Comment
Please, Sign In to add comment