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 - 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 01/10/21) (Out Of Sample Dal=01/10/21 Al 28/04/22)
- // (Progettatta Il=06/05/2022)
- //@version=5
- //1. Strategia
- strategy(title='Bot Scalping-Exponential-Bot ETH/PERP Ver-5 FTX 5M LONG E SHORT', overlay=true, precision = 2,
- 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=46)
- // Input
- input_target_long = input.float(title="input_take_profit_long", defval=5.0, minval=0.1, maxval=1000, group='Target')
- input_stop_loss_long = input.float(title="input_stop_loss_long", defval=1.0, minval=0.1, maxval=1000, group='Stop Loss')
- input_target_short = input.float(title="input_take_profit_short", defval=5.0, minval=0.1, maxval=1000, group='Target')
- input_stop_loss_short = input.float(title="input_stop_loss_short", defval=2.0, minval=0.1, maxval=1000, group='Stop Loss')
- lunghezza_adx = input.int(title="lunghezza_adx", defval=9, minval=0, maxval=1000, group='Differenziale Dmi')
- differenziale_adx_long_basso = input.float(title="differenziale_adx_basso_long", defval=5.0, minval=0.1, maxval=1000, group='Differenziale Adx', tooltip="Opera In Base Alla Tendenza")
- differenziale_adx_long_alto = input.float(title="differenziale_adx_alto_long", defval=25.0, minval=0.1, maxval=1000, group='Differenziale Adx', tooltip="Opera In Base Alla Tendenza")
- differenziale_adx_short_basso = input.float(title="differenziale_adx_basso_short", defval=30.0, minval=0.1, maxval=1000, group='Differenziale Adx', tooltip="Opera In Base Alla Tendenza")
- differenziale_adx_short_alto = input.float(title="differenziale_adx_alto_short", defval=60.0, minval=0.1, maxval=1000, group='Differenziale Adx', tooltip="Opera In Base Alla Tendenza")
- lunghezza_rsi = input.int(title="lunghezza_rsi", defval=9, minval=1, maxval=1000, group='Differenziale Rsi', tooltip="Opera In Base Ai Range Rsi")
- differenziale_rsi_long = input.float(title="differenziale_rsi_long", defval=65.0, minval=0.1, maxval=1000, group='Differenziale Rsi', tooltip="Opera In Base Ai Range Rsi")
- differenziale_rsi_short = input.float(title="differenziale_rsi_short", defval=35.0, minval=0.1, maxval=1000, group='Differenziale Rsi', tooltip="Opera In Base Ai Range Rsi")
- lunghezza_media_long = input.int(title="media_ema_long", defval=140, minval=1, maxval=1000, group='Medie')
- lunghezza_media_short = input.int(title="media_ema_short", defval=100, minval=1, maxval=1000, group='Medie')
- lunghezza_media_tendenza_veloce = input.int(title="media_ema_tendenza_veloce", defval=60, minval=1, maxval=1000, group='Medie', tooltip="Rende Più O Meno Dinamiche Le Medie")
- lunghezza_media_tendenza_lenta = input.int(title="media_ema_tendenza_lenta", defval=180, minval=1, maxval=1000, group='Medie', tooltip="Rende Più O Meno Dinamiche Le Medie")
- input_trailing_stop_trigger_long1 = input.int(title="trigger_long 1", defval=45, minval=1, maxval=1000, group='2 Trailing Stop')
- input_trailing_stop_close_long1 = input.int(title="close_long 1", defval=40, minval=1, maxval=1000, group='2 Trailing Stop')
- input_trailing_stop_trigger_long2 = input.int(title="trigger_long 2", defval=80, minval=1, maxval=1000, group='2 Trailing Stop')
- input_trailing_stop_close_long2 = input.int(title="close_long 2", defval=60, minval=1, maxval=1000, group='2 Trailing Stop')
- input_trailing_stop_trigger_short1 = input.int(title="trigger_short 1", defval=50, minval=1, maxval=1000, group='2 Trailing Stop')
- input_trailing_stop_close_short1 = input.int(title="close_short 1", defval=20, minval=1, maxval=1000, group='2 Trailing Stop')
- input_trailing_stop_trigger_short2 = input.int(title="trigger_short 2", defval=80, minval=1, maxval=1000, group='2 Trailing Stop')
- input_trailing_stop_close_short2 = input.int(title="close_short 2", defval=55, minval=1, maxval=1000, group='2 Trailing Stop')
- perc_apertura_minima_long = input.float(title="perc_apertura_minima_long", defval=0.09, minval=0.01, maxval=1000, group='Apertura Minima Close Media')
- perc_apertura_minima_short = input.float(title="perc_apertura_minima_short", defval=0.08, minval=0.01, maxval=1000, group='Apertura Minima Close Media')
- 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')
- // Calcolo del range del backtest
- startDate = input.int(title="Start Date",
- defval=1, minval=1, maxval=31, group="Periodo")
- startMonth = input.int(title="Start Month",
- defval=02, minval=1, maxval=12, group="Periodo")
- startYear = input.int(title="Start Year",
- defval=2021, 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)
- //Calcolo degli indicatori
- // Medie Mobili
- media_long = ta.ema(close, lunghezza_media_long)
- media_short = ta.ema(close, lunghezza_media_short)
- plot(media_long, color=color.new(color.blue, 0), title='Ema Long', linewidth=2)
- plot(media_short, color=color.new(color.red, 0), title='Ema Short', linewidth=2)
- media_tendenza_lenta = ta.ema(close, lunghezza_media_tendenza_lenta)
- media_tendenza_veloce = ta.ema(close, lunghezza_media_tendenza_veloce)
- plot(media_tendenza_lenta, color=color.new(color.purple, 0), title='media_tendenza_lenta', linewidth=2)
- plot(media_tendenza_veloce, color=color.new(color.aqua, 0), title='media_tendenza_veloce', linewidth=2)
- // Variabili Rsi Long e Short
- valore_rsi = ta.rsi(close, lunghezza_rsi)
- plot(valore_rsi, title = "valore_rsi", color=color.blue)
- // Variabili Adx
- [di_pos, di_neg, adx] = ta.dmi(lunghezza_adx, lunghezza_adx)
- valore_adx = adx
- plot(adx, title="adx_long")
- //Apertura minima
- apertura_minima_long = (media_long / 100) * perc_apertura_minima_long
- apertura_minima_short = (media_short / 100) * perc_apertura_minima_short
- // Money Menagment e stop loss
- // size = strategy.equity * input_risk / 100
- // nr_contratti = size / close
- // stop_loss_long = math.round(size / syminfo.mintick / 100 * input_stop_loss_long) / nr_contratti
- // stop_loss_short = math.round(size / syminfo.mintick / 100 * input_stop_loss_short) / nr_contratti
- // target_long = math.round(size / syminfo.mintick / 100 * input_target_long) / nr_contratti
- // target_short = math.round(size / syminfo.mintick / 100 * input_target_short) / nr_contratti
- //Variabili Stop Long e Short
- stop_loss_long_price =math.round(strategy.opentrades.entry_price(0) - (strategy.opentrades.entry_price(0) * input_stop_loss_long) / 100)
- stop_loss_short_price = math.round(strategy.opentrades.entry_price(0) + (strategy.opentrades.entry_price(0) * input_stop_loss_short) / 100)
- take_profit_long_price = math.round(strategy.opentrades.entry_price(0) + (strategy.opentrades.entry_price(0) * input_target_long) / 100)
- take_profit_short_price = math.round(strategy.opentrades.entry_price(0) - (strategy.opentrades.entry_price(0) * input_target_short) / 100)
- // Calcolo Trailing Stop
- trailing_stop_trigger_long1 = strategy.opentrades.entry_price(0) + (strategy.opentrades.entry_price(0) * input_target_long /100) * (input_trailing_stop_trigger_long1/100)
- trailing_stop_close_long1 = strategy.opentrades.entry_price(0) + (strategy.opentrades.entry_price(0) * input_target_long /100) * (input_trailing_stop_close_long1/100)
- trailing_stop_trigger_short1 = strategy.opentrades.entry_price(0) - (strategy.opentrades.entry_price(0) * input_target_short /100) * (input_trailing_stop_trigger_short1/100)
- trailing_stop_close_short1 = strategy.opentrades.entry_price(0) - (strategy.opentrades.entry_price(0) * input_target_short /100) * (input_trailing_stop_close_short1/100)
- trailing_stop_trigger_long2 = strategy.opentrades.entry_price(0) + (strategy.opentrades.entry_price(0) * input_target_long /100) * (input_trailing_stop_trigger_long2/100)
- trailing_stop_close_long2 = strategy.opentrades.entry_price(0) + (strategy.opentrades.entry_price(0) * input_target_long /100) * (input_trailing_stop_close_long2/100)
- trailing_stop_trigger_short2 = strategy.opentrades.entry_price(0) - (strategy.opentrades.entry_price(0) * input_target_short /100) * (input_trailing_stop_trigger_short2/100)
- trailing_stop_close_short2 = strategy.opentrades.entry_price(0) - (strategy.opentrades.entry_price(0) * input_target_short /100) * (input_trailing_stop_close_short2/100)
- // Trigger Trailing Stop: Quando la posizione è aperta, contando indietro dall'ultima chiusura fino a max 49 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_long = ( ((high >= trailing_stop_trigger_long1 and close <= trailing_stop_close_long1 and time_close >= strategy.opentrades.entry_time(0)) or (high >= trailing_stop_trigger_long2 and close <= trailing_stop_close_long2 and time_close >= strategy.opentrades.entry_time(0))) or ((high[1] >= trailing_stop_trigger_long1 and close <= trailing_stop_close_long1 and time_close[1] > strategy.opentrades.entry_time(0)) or (high[1] >= trailing_stop_trigger_long2 and close <= trailing_stop_close_long2 and time_close[1] > strategy.opentrades.entry_time(0))) or ((high[2] >= trailing_stop_trigger_long1 and close <= trailing_stop_close_long1 and time_close[2] > strategy.opentrades.entry_time(0)) or (high[2] >= trailing_stop_trigger_long2 and close <= trailing_stop_close_long2 and time_close[2] > strategy.opentrades.entry_time(0))) or ((high[3] >= trailing_stop_trigger_long1 and close <= trailing_stop_close_long1 and time_close[3] > strategy.opentrades.entry_time(0)) or (high[3] >= trailing_stop_trigger_long2 and close <= trailing_stop_close_long2 and time_close[3] > strategy.opentrades.entry_time(0))) or ((high[4] >= trailing_stop_trigger_long1 and close <= trailing_stop_close_long1 and time_close[4] > strategy.opentrades.entry_time(0)) or (high[4] >= trailing_stop_trigger_long2 and close <= trailing_stop_close_long2 and time_close[4] > strategy.opentrades.entry_time(0)))
- // or ((high[5] >= trailing_stop_trigger_long1 and close <= trailing_stop_close_long1 and time_close[5] > strategy.opentrades.entry_time(0)) or (high[5] >= trailing_stop_trigger_long2 and close <= trailing_stop_close_long2 and time_close[5] > strategy.opentrades.entry_time(0))) or ((high[6] >= trailing_stop_trigger_long1 and close <= trailing_stop_close_long1 and time_close[6] > strategy.opentrades.entry_time(0)) or (high[6] >= trailing_stop_trigger_long2 and close <= trailing_stop_close_long2 and time_close[6] > strategy.opentrades.entry_time(0))) or ((high[7] >= trailing_stop_trigger_long1 and close <= trailing_stop_close_long1 and time_close[7] > strategy.opentrades.entry_time(0)) or (high[7] >= trailing_stop_trigger_long2 and close <= trailing_stop_close_long2 and time_close[7] > strategy.opentrades.entry_time(0))) or ((high[8] >= trailing_stop_trigger_long1 and close <= trailing_stop_close_long1 and time_close[8] > strategy.opentrades.entry_time(0)) or (high[8] >= trailing_stop_trigger_long2 and close <= trailing_stop_close_long2 and time_close[8] > strategy.opentrades.entry_time(0))) or ((high[9] >= trailing_stop_trigger_long1 and close <= trailing_stop_close_long1 and time_close[9] > strategy.opentrades.entry_time(0)) or (high[9] >= trailing_stop_trigger_long2 and close <= trailing_stop_close_long2 and time_close[9] > strategy.opentrades.entry_time(0)))
- // or ((high[10] >= trailing_stop_trigger_long1 and close <= trailing_stop_close_long1 and time_close[10] > strategy.opentrades.entry_time(0)) or (high[10] >= trailing_stop_trigger_long2 and close <= trailing_stop_close_long2 and time_close[10] > strategy.opentrades.entry_time(0))) or ((high[11] >= trailing_stop_trigger_long1 and close <= trailing_stop_close_long1 and time_close[11] > strategy.opentrades.entry_time(0)) or (high[11] >= trailing_stop_trigger_long2 and close <= trailing_stop_close_long2 and time_close[11] > strategy.opentrades.entry_time(0))) or ((high[12] >= trailing_stop_trigger_long1 and close <= trailing_stop_close_long1 and time_close[12] > strategy.opentrades.entry_time(0)) or (high[12] >= trailing_stop_trigger_long2 and close <= trailing_stop_close_long2 and time_close[12] > strategy.opentrades.entry_time(0))) or ((high[13] >= trailing_stop_trigger_long1 and close <= trailing_stop_close_long1 and time_close[13] > strategy.opentrades.entry_time(0)) or (high[13] >= trailing_stop_trigger_long2 and close <= trailing_stop_close_long2 and time_close[13] > strategy.opentrades.entry_time(0))) or ((high[14] >= trailing_stop_trigger_long1 and close <= trailing_stop_close_long1 and time_close[14] > strategy.opentrades.entry_time(0)) or (high[14] >= trailing_stop_trigger_long2 and close <= trailing_stop_close_long2 and time_close[14] > strategy.opentrades.entry_time(0)))
- // or ((high[15] >= trailing_stop_trigger_long1 and close <= trailing_stop_close_long1 and time_close[15] > strategy.opentrades.entry_time(0)) or (high[15] >= trailing_stop_trigger_long2 and close <= trailing_stop_close_long2 and time_close[15] > strategy.opentrades.entry_time(0))) or ((high[16] >= trailing_stop_trigger_long1 and close <= trailing_stop_close_long1 and time_close[16] > strategy.opentrades.entry_time(0)) or (high[16] >= trailing_stop_trigger_long2 and close <= trailing_stop_close_long2 and time_close[16] > strategy.opentrades.entry_time(0))) or ((high[17] >= trailing_stop_trigger_long1 and close <= trailing_stop_close_long1 and time_close[17] > strategy.opentrades.entry_time(0)) or (high[17] >= trailing_stop_trigger_long2 and close <= trailing_stop_close_long2 and time_close[17] > strategy.opentrades.entry_time(0))) or ((high[18] >= trailing_stop_trigger_long1 and close <= trailing_stop_close_long1 and time_close[18] > strategy.opentrades.entry_time(0)) or (high[18] >= trailing_stop_trigger_long2 and close <= trailing_stop_close_long2 and time_close[18] > strategy.opentrades.entry_time(0))) or ((high[19] >= trailing_stop_trigger_long1 and close <= trailing_stop_close_long1 and time_close[19] > strategy.opentrades.entry_time(0)) or (high[19] >= trailing_stop_trigger_long2 and close <= trailing_stop_close_long2 and time_close[19] > strategy.opentrades.entry_time(0)))
- // or ((high[20] >= trailing_stop_trigger_long1 and close <= trailing_stop_close_long1 and time_close[20] > strategy.opentrades.entry_time(0)) or (high[20] >= trailing_stop_trigger_long2 and close <= trailing_stop_close_long2 and time_close[20] > strategy.opentrades.entry_time(0))) or ((high[21] >= trailing_stop_trigger_long1 and close <= trailing_stop_close_long1 and time_close[21] > strategy.opentrades.entry_time(0)) or (high[21] >= trailing_stop_trigger_long2 and close <= trailing_stop_close_long2 and time_close[21] > strategy.opentrades.entry_time(0))) or ((high[22] >= trailing_stop_trigger_long1 and close <= trailing_stop_close_long1 and time_close[22] > strategy.opentrades.entry_time(0)) or (high[22] >= trailing_stop_trigger_long2 and close <= trailing_stop_close_long2 and time_close[22] > strategy.opentrades.entry_time(0))) or ((high[23] >= trailing_stop_trigger_long1 and close <= trailing_stop_close_long1 and time_close[23] > strategy.opentrades.entry_time(0)) or (high[23] >= trailing_stop_trigger_long2 and close <= trailing_stop_close_long2 and time_close[23] > strategy.opentrades.entry_time(0))) or ((high[24] >= trailing_stop_trigger_long1 and close <= trailing_stop_close_long1 and time_close[24] > strategy.opentrades.entry_time(0)) or (high[24] >= trailing_stop_trigger_long2 and close <= trailing_stop_close_long2 and time_close[24] > strategy.opentrades.entry_time(0)))
- // or ((high[25] >= trailing_stop_trigger_long1 and close <= trailing_stop_close_long1 and time_close[25] > strategy.opentrades.entry_time(0)) or (high[25] >= trailing_stop_trigger_long2 and close <= trailing_stop_close_long2 and time_close[25] > strategy.opentrades.entry_time(0))) or ((high[26] >= trailing_stop_trigger_long1 and close <= trailing_stop_close_long1 and time_close[26] > strategy.opentrades.entry_time(0)) or (high[26] >= trailing_stop_trigger_long2 and close <= trailing_stop_close_long2 and time_close[26] > strategy.opentrades.entry_time(0))) or ((high[27] >= trailing_stop_trigger_long1 and close <= trailing_stop_close_long1 and time_close[27] > strategy.opentrades.entry_time(0)) or (high[27] >= trailing_stop_trigger_long2 and close <= trailing_stop_close_long2 and time_close[27] > strategy.opentrades.entry_time(0))) or ((high[28] >= trailing_stop_trigger_long1 and close <= trailing_stop_close_long1 and time_close[28] > strategy.opentrades.entry_time(0)) or (high[28] >= trailing_stop_trigger_long2 and close <= trailing_stop_close_long2 and time_close[28] > strategy.opentrades.entry_time(0))) or ((high[29] >= trailing_stop_trigger_long1 and close <= trailing_stop_close_long1 and time_close[29] > strategy.opentrades.entry_time(0)) or (high[29] >= trailing_stop_trigger_long2 and close <= trailing_stop_close_long2 and time_close[29] > strategy.opentrades.entry_time(0)))
- // or ((high[30] >= trailing_stop_trigger_long1 and close <= trailing_stop_close_long1 and time_close[30] > strategy.opentrades.entry_time(0)) or (high[30] >= trailing_stop_trigger_long2 and close <= trailing_stop_close_long2 and time_close[30] > strategy.opentrades.entry_time(0))) or ((high[31] >= trailing_stop_trigger_long1 and close <= trailing_stop_close_long1 and time_close[31] > strategy.opentrades.entry_time(0)) or (high[31] >= trailing_stop_trigger_long2 and close <= trailing_stop_close_long2 and time_close[31] > strategy.opentrades.entry_time(0))) or ((high[32] >= trailing_stop_trigger_long1 and close <= trailing_stop_close_long1 and time_close[32] > strategy.opentrades.entry_time(0)) or (high[32] >= trailing_stop_trigger_long2 and close <= trailing_stop_close_long2 and time_close[32] > strategy.opentrades.entry_time(0))) or ((high[33] >= trailing_stop_trigger_long1 and close <= trailing_stop_close_long1 and time_close[33] > strategy.opentrades.entry_time(0)) or (high[33] >= trailing_stop_trigger_long2 and close <= trailing_stop_close_long2 and time_close[33] > strategy.opentrades.entry_time(0))) or ((high[34] >= trailing_stop_trigger_long1 and close <= trailing_stop_close_long1 and time_close[34] > strategy.opentrades.entry_time(0)) or (high[34] >= trailing_stop_trigger_long2 and close <= trailing_stop_close_long2 and time_close[34] > strategy.opentrades.entry_time(0)))
- // or ((high[35] >= trailing_stop_trigger_long1 and close <= trailing_stop_close_long1 and time_close[35] > strategy.opentrades.entry_time(0)) or (high[35] >= trailing_stop_trigger_long2 and close <= trailing_stop_close_long2 and time_close[35] > strategy.opentrades.entry_time(0))) or ((high[36] >= trailing_stop_trigger_long1 and close <= trailing_stop_close_long1 and time_close[36] > strategy.opentrades.entry_time(0)) or (high[36] >= trailing_stop_trigger_long2 and close <= trailing_stop_close_long2 and time_close[36] > strategy.opentrades.entry_time(0))) or ((high[37] >= trailing_stop_trigger_long1 and close <= trailing_stop_close_long1 and time_close[37] > strategy.opentrades.entry_time(0)) or (high[37] >= trailing_stop_trigger_long2 and close <= trailing_stop_close_long2 and time_close[37] > strategy.opentrades.entry_time(0))) or ((high[38] >= trailing_stop_trigger_long1 and close <= trailing_stop_close_long1 and time_close[38] > strategy.opentrades.entry_time(0)) or (high[38] >= trailing_stop_trigger_long2 and close <= trailing_stop_close_long2 and time_close[38] > strategy.opentrades.entry_time(0))) or ((high[39] >= trailing_stop_trigger_long1 and close <= trailing_stop_close_long1 and time_close[39] > strategy.opentrades.entry_time(0)) or (high[39] >= trailing_stop_trigger_long2 and close <= trailing_stop_close_long2 and time_close[39] > strategy.opentrades.entry_time(0)))
- // or ((high[40] >= trailing_stop_trigger_long1 and close <= trailing_stop_close_long1 and time_close[40] > strategy.opentrades.entry_time(0)) or (high[40] >= trailing_stop_trigger_long2 and close <= trailing_stop_close_long2 and time_close[40] > strategy.opentrades.entry_time(0))) or ((high[41] >= trailing_stop_trigger_long1 and close <= trailing_stop_close_long1 and time_close[41] > strategy.opentrades.entry_time(0)) or (high[41] >= trailing_stop_trigger_long2 and close <= trailing_stop_close_long2 and time_close[41] > strategy.opentrades.entry_time(0))) or ((high[42] >= trailing_stop_trigger_long1 and close <= trailing_stop_close_long1 and time_close[42] > strategy.opentrades.entry_time(0)) or (high[42] >= trailing_stop_trigger_long2 and close <= trailing_stop_close_long2 and time_close[42] > strategy.opentrades.entry_time(0))) or ((high[43] >= trailing_stop_trigger_long1 and close <= trailing_stop_close_long1 and time_close[43] > strategy.opentrades.entry_time(0)) or (high[43] >= trailing_stop_trigger_long2 and close <= trailing_stop_close_long2 and time_close[43] > strategy.opentrades.entry_time(0))) or ((high[44] >= trailing_stop_trigger_long1 and close <= trailing_stop_close_long1 and time_close[44] > strategy.opentrades.entry_time(0)) or (high[44] >= trailing_stop_trigger_long2 and close <= trailing_stop_close_long2 and time_close[44] > strategy.opentrades.entry_time(0)))
- // or ((high[45] >= trailing_stop_trigger_long1 and close <= trailing_stop_close_long1 and time_close[45] > strategy.opentrades.entry_time(0)) or (high[45] >= trailing_stop_trigger_long2 and close <= trailing_stop_close_long2 and time_close[45] > strategy.opentrades.entry_time(0))) or ((high[46] >= trailing_stop_trigger_long1 and close <= trailing_stop_close_long1 and time_close[46] > strategy.opentrades.entry_time(0)) or (high[46] >= trailing_stop_trigger_long2 and close <= trailing_stop_close_long2 and time_close[46] > strategy.opentrades.entry_time(0))) or ((high[47] >= trailing_stop_trigger_long1 and close <= trailing_stop_close_long1 and time_close[47] > strategy.opentrades.entry_time(0)) or (high[47] >= trailing_stop_trigger_long2 and close <= trailing_stop_close_long2 and time_close[47] > strategy.opentrades.entry_time(0))) or ((high[48] >= trailing_stop_trigger_long1 and close <= trailing_stop_close_long1 and time_close[48] > strategy.opentrades.entry_time(0)) or (high[48] >= trailing_stop_trigger_long2 and close <= trailing_stop_close_long2 and time_close[48] > strategy.opentrades.entry_time(0))) or ((high[49] >= trailing_stop_trigger_long1 and close <= trailing_stop_close_long1 and time_close[49] > strategy.opentrades.entry_time(0)) or (high[49] >= trailing_stop_trigger_long2 and close <= trailing_stop_close_long2 and time_close[49] > strategy.opentrades.entry_time(0))))
- // Trigger Trailing Stop: Quando la posizione è aperta, contando indietro dall'ultima chiusura fino a max 49 candele indietro fino ad arrivare all'ingresso della posizione, se i low sono <= dei trailing_stop_trigger e le close sono >= dei trailing_stop_close la condizione è valida
- // trailing_short = ( ((low <= trailing_stop_trigger_short1 and close >= trailing_stop_close_short1 and time_close >= strategy.opentrades.entry_time(0)) or (low <= trailing_stop_trigger_short2 and close >= trailing_stop_close_short2 and time_close >= strategy.opentrades.entry_time(0))) or ((low[1] <= trailing_stop_trigger_short1 and close >= trailing_stop_close_short1 and time_close[1] > strategy.opentrades.entry_time(0)) or (low[1] <= trailing_stop_trigger_short2 and close >= trailing_stop_close_short2 and time_close[1] > strategy.opentrades.entry_time(0))) or ((low[2] <= trailing_stop_trigger_short1 and close >= trailing_stop_close_short1 and time_close[2] > strategy.opentrades.entry_time(0)) or (low[2] <= trailing_stop_trigger_short2 and close >= trailing_stop_close_short2 and time_close[2] > strategy.opentrades.entry_time(0))) or ((low[3] <= trailing_stop_trigger_short1 and close >= trailing_stop_close_short1 and time_close[3] > strategy.opentrades.entry_time(0)) or (low[3] <= trailing_stop_trigger_short2 and close >= trailing_stop_close_short2 and time_close[3] > strategy.opentrades.entry_time(0))) or ((low[4] <= trailing_stop_trigger_short1 and close >= trailing_stop_close_short1 and time_close[4] > strategy.opentrades.entry_time(0)) or (low[4] <= trailing_stop_trigger_short2 and close >= trailing_stop_close_short2 and time_close[4] > strategy.opentrades.entry_time(0)))
- // or ((low[5] <= trailing_stop_trigger_short1 and close >= trailing_stop_close_short1 and time_close[5] > strategy.opentrades.entry_time(0)) or (low[5] <= trailing_stop_trigger_short2 and close >= trailing_stop_close_short2 and time_close[5] > strategy.opentrades.entry_time(0))) or ((low[6] <= trailing_stop_trigger_short1 and close >= trailing_stop_close_short1 and time_close[6] > strategy.opentrades.entry_time(0)) or (low[6] <= trailing_stop_trigger_short2 and close >= trailing_stop_close_short2 and time_close[6] > strategy.opentrades.entry_time(0))) or ((low[7] <= trailing_stop_trigger_short1 and close >= trailing_stop_close_short1 and time_close[7] > strategy.opentrades.entry_time(0)) or (low[7] <= trailing_stop_trigger_short2 and close >= trailing_stop_close_short2 and time_close[7] > strategy.opentrades.entry_time(0))) or ((low[8] <= trailing_stop_trigger_short1 and close >= trailing_stop_close_short1 and time_close[8] > strategy.opentrades.entry_time(0)) or (low[8] <= trailing_stop_trigger_short2 and close >= trailing_stop_close_short2 and time_close[8] > strategy.opentrades.entry_time(0))) or ((low[9] <= trailing_stop_trigger_short1 and close >= trailing_stop_close_short1 and time_close[9] > strategy.opentrades.entry_time(0)) or (low[9] <= trailing_stop_trigger_short2 and close >= trailing_stop_close_short2 and time_close[9] > strategy.opentrades.entry_time(0)))
- // or ((low[10] <= trailing_stop_trigger_short1 and close >= trailing_stop_close_short1 and time_close[10] > strategy.opentrades.entry_time(0)) or (low[10] <= trailing_stop_trigger_short2 and close >= trailing_stop_close_short2 and time_close[10] > strategy.opentrades.entry_time(0))) or ((low[11] <= trailing_stop_trigger_short1 and close >= trailing_stop_close_short1 and time_close[11] > strategy.opentrades.entry_time(0)) or (low[11] <= trailing_stop_trigger_short2 and close >= trailing_stop_close_short2 and time_close[11] > strategy.opentrades.entry_time(0))) or ((low[12] <= trailing_stop_trigger_short1 and close >= trailing_stop_close_short1 and time_close[12] > strategy.opentrades.entry_time(0)) or (low[12] <= trailing_stop_trigger_short2 and close >= trailing_stop_close_short2 and time_close[12] > strategy.opentrades.entry_time(0))) or ((low[13] <= trailing_stop_trigger_short1 and close >= trailing_stop_close_short1 and time_close[13] > strategy.opentrades.entry_time(0)) or (low[13] <= trailing_stop_trigger_short2 and close >= trailing_stop_close_short2 and time_close[13] > strategy.opentrades.entry_time(0))) or ((low[14] <= trailing_stop_trigger_short1 and close >= trailing_stop_close_short1 and time_close[14] > strategy.opentrades.entry_time(0)) or (low[14] <= trailing_stop_trigger_short2 and close >= trailing_stop_close_short2 and time_close[14] > strategy.opentrades.entry_time(0)))
- // or ((low[15] <= trailing_stop_trigger_short1 and close >= trailing_stop_close_short1 and time_close[15] > strategy.opentrades.entry_time(0)) or (low[15] <= trailing_stop_trigger_short2 and close >= trailing_stop_close_short2 and time_close[15] > strategy.opentrades.entry_time(0))) or ((low[16] <= trailing_stop_trigger_short1 and close >= trailing_stop_close_short1 and time_close[16] > strategy.opentrades.entry_time(0)) or (low[16] <= trailing_stop_trigger_short2 and close >= trailing_stop_close_short2 and time_close[16] > strategy.opentrades.entry_time(0))) or ((low[17] <= trailing_stop_trigger_short1 and close >= trailing_stop_close_short1 and time_close[17] > strategy.opentrades.entry_time(0)) or (low[17] <= trailing_stop_trigger_short2 and close >= trailing_stop_close_short2 and time_close[17] > strategy.opentrades.entry_time(0))) or ((low[18] <= trailing_stop_trigger_short1 and close >= trailing_stop_close_short1 and time_close[18] > strategy.opentrades.entry_time(0)) or (low[18] <= trailing_stop_trigger_short2 and close >= trailing_stop_close_short2 and time_close[18] > strategy.opentrades.entry_time(0))) or ((low[19] <= trailing_stop_trigger_short1 and close >= trailing_stop_close_short1 and time_close[19] > strategy.opentrades.entry_time(0)) or (low[19] <= trailing_stop_trigger_short2 and close >= trailing_stop_close_short2 and time_close[19] > strategy.opentrades.entry_time(0)))
- // or ((low[20] <= trailing_stop_trigger_short1 and close >= trailing_stop_close_short1 and time_close[20] > strategy.opentrades.entry_time(0)) or (low[20] <= trailing_stop_trigger_short2 and close >= trailing_stop_close_short2 and time_close[20] > strategy.opentrades.entry_time(0))) or ((low[21] <= trailing_stop_trigger_short1 and close >= trailing_stop_close_short1 and time_close[21] > strategy.opentrades.entry_time(0)) or (low[21] <= trailing_stop_trigger_short2 and close >= trailing_stop_close_short2 and time_close[21] > strategy.opentrades.entry_time(0))) or ((low[22] <= trailing_stop_trigger_short1 and close >= trailing_stop_close_short1 and time_close[22] > strategy.opentrades.entry_time(0)) or (low[22] <= trailing_stop_trigger_short2 and close >= trailing_stop_close_short2 and time_close[22] > strategy.opentrades.entry_time(0))) or ((low[23] <= trailing_stop_trigger_short1 and close >= trailing_stop_close_short1 and time_close[23] > strategy.opentrades.entry_time(0)) or (low[23] <= trailing_stop_trigger_short2 and close >= trailing_stop_close_short2 and time_close[23] > strategy.opentrades.entry_time(0))) or ((low[24] <= trailing_stop_trigger_short1 and close >= trailing_stop_close_short1 and time_close[24] > strategy.opentrades.entry_time(0)) or (low[24] <= trailing_stop_trigger_short2 and close >= trailing_stop_close_short2 and time_close[24] > strategy.opentrades.entry_time(0)))
- // or ((low[25] <= trailing_stop_trigger_short1 and close >= trailing_stop_close_short1 and time_close[25] > strategy.opentrades.entry_time(0)) or (low[25] <= trailing_stop_trigger_short2 and close >= trailing_stop_close_short2 and time_close[25] > strategy.opentrades.entry_time(0))) or ((low[26] <= trailing_stop_trigger_short1 and close >= trailing_stop_close_short1 and time_close[26] > strategy.opentrades.entry_time(0)) or (low[26] <= trailing_stop_trigger_short2 and close >= trailing_stop_close_short2 and time_close[26] > strategy.opentrades.entry_time(0))) or ((low[27] <= trailing_stop_trigger_short1 and close >= trailing_stop_close_short1 and time_close[27] > strategy.opentrades.entry_time(0)) or (low[27] <= trailing_stop_trigger_short2 and close >= trailing_stop_close_short2 and time_close[27] > strategy.opentrades.entry_time(0))) or ((low[28] <= trailing_stop_trigger_short1 and close >= trailing_stop_close_short1 and time_close[28] > strategy.opentrades.entry_time(0)) or (low[28] <= trailing_stop_trigger_short2 and close >= trailing_stop_close_short2 and time_close[28] > strategy.opentrades.entry_time(0))) or ((low[29] <= trailing_stop_trigger_short1 and close >= trailing_stop_close_short1 and time_close[29] > strategy.opentrades.entry_time(0)) or (low[29] <= trailing_stop_trigger_short2 and close >= trailing_stop_close_short2 and time_close[29] > strategy.opentrades.entry_time(0)))
- // or ((low[30] <= trailing_stop_trigger_short1 and close >= trailing_stop_close_short1 and time_close[30] > strategy.opentrades.entry_time(0)) or (low[30] <= trailing_stop_trigger_short2 and close >= trailing_stop_close_short2 and time_close[30] > strategy.opentrades.entry_time(0))) or ((low[31] <= trailing_stop_trigger_short1 and close >= trailing_stop_close_short1 and time_close[31] > strategy.opentrades.entry_time(0)) or (low[31] <= trailing_stop_trigger_short2 and close >= trailing_stop_close_short2 and time_close[31] > strategy.opentrades.entry_time(0))) or ((low[32] <= trailing_stop_trigger_short1 and close >= trailing_stop_close_short1 and time_close[32] > strategy.opentrades.entry_time(0)) or (low[32] <= trailing_stop_trigger_short2 and close >= trailing_stop_close_short2 and time_close[32] > strategy.opentrades.entry_time(0))) or ((low[33] <= trailing_stop_trigger_short1 and close >= trailing_stop_close_short1 and time_close[33] > strategy.opentrades.entry_time(0)) or (low[33] <= trailing_stop_trigger_short2 and close >= trailing_stop_close_short2 and time_close[33] > strategy.opentrades.entry_time(0))) or ((low[34] <= trailing_stop_trigger_short1 and close >= trailing_stop_close_short1 and time_close[34] > strategy.opentrades.entry_time(0)) or (low[34] <= trailing_stop_trigger_short2 and close >= trailing_stop_close_short2 and time_close[34] > strategy.opentrades.entry_time(0)))
- // or ((low[35] <= trailing_stop_trigger_short1 and close >= trailing_stop_close_short1 and time_close[35] > strategy.opentrades.entry_time(0)) or (low[35] <= trailing_stop_trigger_short2 and close >= trailing_stop_close_short2 and time_close[35] > strategy.opentrades.entry_time(0))) or ((low[36] <= trailing_stop_trigger_short1 and close >= trailing_stop_close_short1 and time_close[36] > strategy.opentrades.entry_time(0)) or (low[36] <= trailing_stop_trigger_short2 and close >= trailing_stop_close_short2 and time_close[36] > strategy.opentrades.entry_time(0))) or ((low[37] <= trailing_stop_trigger_short1 and close >= trailing_stop_close_short1 and time_close[37] > strategy.opentrades.entry_time(0)) or (low[37] <= trailing_stop_trigger_short2 and close >= trailing_stop_close_short2 and time_close[37] > strategy.opentrades.entry_time(0))) or ((low[38] <= trailing_stop_trigger_short1 and close >= trailing_stop_close_short1 and time_close[38] > strategy.opentrades.entry_time(0)) or (low[38] <= trailing_stop_trigger_short2 and close >= trailing_stop_close_short2 and time_close[38] > strategy.opentrades.entry_time(0))) or ((low[39] <= trailing_stop_trigger_short1 and close >= trailing_stop_close_short1 and time_close[39] > strategy.opentrades.entry_time(0)) or (low[39] <= trailing_stop_trigger_short2 and close >= trailing_stop_close_short2 and time_close[39] > strategy.opentrades.entry_time(0)))
- // or ((low[40] <= trailing_stop_trigger_short1 and close >= trailing_stop_close_short1 and time_close[40] > strategy.opentrades.entry_time(0)) or (low[40] <= trailing_stop_trigger_short2 and close >= trailing_stop_close_short2 and time_close[40] > strategy.opentrades.entry_time(0))) or ((low[41] <= trailing_stop_trigger_short1 and close >= trailing_stop_close_short1 and time_close[41] > strategy.opentrades.entry_time(0)) or (low[41] <= trailing_stop_trigger_short2 and close >= trailing_stop_close_short2 and time_close[41] > strategy.opentrades.entry_time(0))) or ((low[42] <= trailing_stop_trigger_short1 and close >= trailing_stop_close_short1 and time_close[42] > strategy.opentrades.entry_time(0)) or (low[42] <= trailing_stop_trigger_short2 and close >= trailing_stop_close_short2 and time_close[42] > strategy.opentrades.entry_time(0))) or ((low[43] <= trailing_stop_trigger_short1 and close >= trailing_stop_close_short1 and time_close[43] > strategy.opentrades.entry_time(0)) or (low[43] <= trailing_stop_trigger_short2 and close >= trailing_stop_close_short2 and time_close[43] > strategy.opentrades.entry_time(0))) or ((low[44] <= trailing_stop_trigger_short1 and close >= trailing_stop_close_short1 and time_close[44] > strategy.opentrades.entry_time(0)) or (low[44] <= trailing_stop_trigger_short2 and close >= trailing_stop_close_short2 and time_close[44] > strategy.opentrades.entry_time(0)))
- // or ((low[45] <= trailing_stop_trigger_short1 and close >= trailing_stop_close_short1 and time_close[45] > strategy.opentrades.entry_time(0)) or (low[45] <= trailing_stop_trigger_short2 and close >= trailing_stop_close_short2 and time_close[45] > strategy.opentrades.entry_time(0))) or ((low[46] <= trailing_stop_trigger_short1 and close >= trailing_stop_close_short1 and time_close[46] > strategy.opentrades.entry_time(0)) or (low[46] <= trailing_stop_trigger_short2 and close >= trailing_stop_close_short2 and time_close[46] > strategy.opentrades.entry_time(0))) or ((low[47] <= trailing_stop_trigger_short1 and close >= trailing_stop_close_short1 and time_close[47] > strategy.opentrades.entry_time(0)) or (low[47] <= trailing_stop_trigger_short2 and close >= trailing_stop_close_short2 and time_close[47] > strategy.opentrades.entry_time(0))) or ((low[48] <= trailing_stop_trigger_short1 and close >= trailing_stop_close_short1 and time_close[48] > strategy.opentrades.entry_time(0)) or (low[48] <= trailing_stop_trigger_short2 and close >= trailing_stop_close_short2 and time_close[48] > strategy.opentrades.entry_time(0))) or ((low[49] <= trailing_stop_trigger_short1 and close >= trailing_stop_close_short1 and time_close[49] > strategy.opentrades.entry_time(0)) or (low[49] <= trailing_stop_trigger_short2 and close >= trailing_stop_close_short2 and time_close[49] > strategy.opentrades.entry_time(0))))
- 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_long1 : strategy.position_size < 0 ? trailing_stop_trigger_short1: na, color=strategy.position_size > 0 ? color.blue : strategy.position_size < 0 ? color.red : na, style=plot.style_cross, linewidth=2, transp=0, title="trigger1")
- plot(strategy.position_size > 0 ? trailing_stop_close_long1 : strategy.position_size < 0 ? trailing_stop_close_short1: na, color=strategy.position_size > 0 ? color.blue : strategy.position_size < 0 ? color.red : na, style=plot.style_cross, linewidth=2,transp=0, title="trailing 1")
- plot(strategy.position_size > 0 ? trailing_stop_trigger_long2 : strategy.position_size < 0 ? trailing_stop_trigger_short2: na, color=strategy.position_size > 0 ? color.blue : strategy.position_size < 0 ? color.red : na, style=plot.style_cross, linewidth=2, transp=50, title="trigger2")
- plot(strategy.position_size > 0 ? trailing_stop_close_long2 : strategy.position_size < 0 ? trailing_stop_close_short2: na, color=strategy.position_size > 0 ? color.blue : strategy.position_size < 0 ? color.red : na, style=plot.style_cross, linewidth=2, transp=50, title="trailing2")
- 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")
- //Condizione Entrata Long
- condEntryLong = ta.crossover(close, media_long) and close > (media_long + apertura_minima_long) and media_tendenza_veloce > media_tendenza_lenta and valore_adx > differenziale_adx_long_basso and valore_adx < differenziale_adx_long_alto and valore_rsi < differenziale_rsi_long and not in_solo_short
- // Condizione Uscita Trailing Stop Long
- 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)
- //Condizione Entrata Short
- condEntryShort = ta.crossunder(close, media_short) and close < (media_short - apertura_minima_short) and media_tendenza_lenta > media_tendenza_veloce and valore_adx > differenziale_adx_short_basso and valore_adx < differenziale_adx_short_alto and valore_rsi > differenziale_rsi_short and not in_solo_long
- // Condizione Uscita Trailing Stop Short
- 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)
- barcolor(condEntryLong ? color.lime : condEntryShort ? color.purple : na)
- // Allerts
- buy_command = '{"BUY COMMAND"}'
- sell_command = '{"SELL COMMAND"}'
- close_command = '{"CLOSE COMMAND"}'
- //entrata e uscita Long (stop/limit x prezzo) (loss/profit x ticks)
- if condEntryLong and 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', stop=stop_loss_long_price, limit=take_profit_long_price, alert_message = "Your Long SL-TP Has Been Triggered.", comment = close_command)
- if trailing_long and strategy.opentrades == 1
- strategy.close(id='operazioneLong', alert_message = "Close Long Position", comment = close_command)
- //entrata e uscita Short
- if condEntryShort 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', stop=stop_loss_short_price, limit=take_profit_short_price, alert_message = "Your Short SL-TP Has Been Triggered.", comment = close_command)
- if trailing_short and strategy.opentrades == 1
- strategy.close(id='operazioneShort', alert_message = "Close Short Position", comment = close_command)
- // Nome Alert: Scalping-Exponential-Bot ETH/PERP Ver-5 FTX 5M
- // 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