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/
- // © Maurizio-Ciullo
- // Versione con uscita chiusuara sotto la baseline //
- // Il trading system completo - Over The Clouds ETH/USDT.P BYBIT 4H LONG E SHORT (Trend Following)
- // (Sviluppo Dati Exchange = BINANCE + BYBIT) (BINANCE Dal=18/08/2017 Al 21/10/2020) (BYBIT Dal=21/10/2020 Al 20/05/2023)
- // (Exchange= BYBIT) (Sottostante ETH-USDT.P) (Timeframe= 4H) (Direzione= LONG E SHORT) (Swing Posizione= SI) (Esclusione Ore=NO) (Esclusione Giorni=NO) (Esclusione Mesi=NO)
- // (Take Profit Long/Short Market = NO) (Take Profit Limit Long/Short= NO)
- // (Stop Loss Limit Long= NO) (Stop Loss Limit Short= NO) (Stop Loss Market Long/Short= SI) (Trailing Stop Market=SI) (Stop Emergenza= NO)
- // (Rischio Operazione 2% Perdita Media Calcolato Sul Ticker: ETHUSDT BINANCE SPOT) (Max Drawdown Permesso 10,03% Calcolato Sul Ticker: ETHUSDT.P BYBIT CHE E' IL PEGGIORE DELLE ENTRIES MODE)
- // (In Sample Dal=18/08/17 Al 12/07/22) (Out Of Sample Dal=12/07/22 Al 20/05/23)
- // (Money Management = 23% Del Capitale)
- // (Money Management = 25% Del Capitale Tradestation)
- // (Progettatta Il=07/07/23)
- // Caricamento Dati Bybit Su Tradestation: Exchange Time, Regular Session, 7x7 23:00 23:00, Session Hour.
- // Auentare il Max Bars Back A 75 Su Tradestation Altrimenti Non Funziona E Cliccare Su Enable Strategy Altrimenti Non Parte
- // ATTENZIONE //
- // Quando si mette la strategia live, ricordarsi di impostare 1 solo input "quello che vogliamo utilizzare come normal/ more_aggressive/less_aggressive entries" su true e
- // impostare gli altri su false. Commentare anche i BUY COMMAND che non utilizziamo.
- //@version=5
- strategy(title='Bot Over-The-Clouds ETH/USDT.P BYBIT 4H LONG E SHORT', overlay=true,
- //max_bars_back=5000, // Serve Per Caricare Più Storico Per Il Trailing Stop
- pyramiding=0,
- initial_capital=1000,
- commission_type=strategy.commission.percent,
- commission_value=0.1,
- slippage=3,
- default_qty_type=strategy.percent_of_equity,
- precision=2,
- default_qty_value=23)
- // Inputs
- onlyLong = input.bool(title='Solo long', defval=false, inline='1', group='Direction')
- onlyShort = input.bool(title='Solo short', defval=false, inline='1', group='Direction')
- in_normal = input.bool(title="normal entry mode", defval=true, tooltip = "Entry Conditions Choice", inline='1', group='Aggresivity Entries Noraml')
- in_more_aggressive = input.bool(title="more aggressive entry mode", defval=false, tooltip = "Entry Conditions Choice", inline='1', group='Aggresivity Entries Aggresive')
- in_less_aggressive = input.bool(title="less aggressive entry mode", defval=false, tooltip = "Entry Conditions Choicee", inline='1', group='Aggresivity Entries Less Aggressive')
- in_ema_long = input.int(title='in_ema_long', defval=84, minval=0, maxval=300, step=1, inline='1', group='Ema Lenght')
- in_ema_short = input.int(title='in_ema_short', defval=83, minval=0, maxval=300, step=1, inline='1', group='Ema Lenght')
- // Calcolo del range del backtest
- startDate = input.int(title='Start Date', defval=17, minval=1, maxval=31, group='Time Window')
- startMonth = input.int(title='Start Month', defval=08, minval=1, maxval=12, group='Time Window')
- startYear = input.int(title='Start Year', defval=2000, minval=1800, maxval=2100, group='Time Window')
- endDate = input.int(title='End Date', defval=01, minval=1, maxval=31, group='Time Window')
- endMonth = input.int(title='End Month', defval=01, minval=1, maxval=12, group='Time Window')
- endYear = input.int(title='End Year', defval=2121, minval=1800, maxval=2150, group='Time Window')
- 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 Ichimoku Cloud //
- conversionPeriods = input.int(9, minval=1, title="Conversion Line Periods", group='Ichomoku'),
- basePeriods = input.int(26, minval=1, title="Base Line Periods", group='Ichomoku')
- laggingSpan2Periods = input.int(52, minval=1, title="Lagging Span 2 Periods", group='Ichomoku'),
- displacement = input.int(26, minval=1, title="Displacement", group='Ichomoku')
- donchian(len) => math.avg(ta.lowest(len), ta.highest(len))
- conversionLine = donchian(conversionPeriods)
- baseLine = donchian(basePeriods)
- spanA = math.avg(conversionLine, baseLine)
- spanB = donchian(laggingSpan2Periods)
- StdLine = (ta.highest(high, 52) + ta.lowest(low, 52)) / 2
- plot(conversionLine, title="Conversion Line", color=#0496ff)
- plot(baseLine, color=#991515, title="Base Line")
- plot(close, title="Lagging Span", offset = -displacement + 1, color=#459915)
- p1 = plot(spanA, offset = displacement - 1, color=color.green,
- title="Plot Span A")
- p2 = plot(spanB, offset = displacement - 1, color=color.red,
- title="Plot Span B")
- fill(p1, p2, color = spanA > spanB ? color.green : color.red)
- // plot(spanA[25], title="Span A", color=color.orange)
- // plot(spanB[25], title="Span B",color=color.yellow)
- // plot(spanA, title="Span A No 25 Offset", color=color.rgb(218, 16, 253))
- // plot(spanB, title="Span B No 25 Offset", color=color.rgb(218, 16, 253))
- // End Detecting Ichimoku Cloud //
- // Start Detecting ATR Long Normal //
- in_length_atr_long_normal = input.int(title="Atr Length_long_normal", defval=11, minval=0, group='Atr Long Normal')
- in_smoothing_atr_long_normal = input.string(title="Smoothing_atr_long_normal", defval="SMA", options=["RMA", "SMA", "EMA", "WMA"], group='Atr Long Normal')
- ma_function_long(source, in_length_atr_long_normal) =>
- switch in_smoothing_atr_long_normal
- "RMA" => ta.rma(source, in_length_atr_long_normal)
- "SMA" => ta.sma(source, in_length_atr_long_normal)
- "EMA" => ta.ema(source, in_length_atr_long_normal)
- => ta.wma(source, in_length_atr_long_normal)
- plot(ma_function_long(ta.tr(true), in_length_atr_long_normal), title = "ATR_long_normal", color=color.new(#ca5555, 0))
- // End Detecting ATR Long Normal //
- // Start Detecting ATR Long More Aggressive //
- in_length_atr_long_more_aggressive = input.int(title="Atr Length_long_more_aggressive", defval=7, minval=0, group='Atr Long More Aggresive')
- in_smoothing_atr_long_more_aggressive = input.string(title="Smoothing_atr_long_more_aggressive", defval="SMA", options=["RMA", "SMA", "EMA", "WMA"], group='Atr Long More Aggresive')
- ma_function_long_more_aggressive(source, in_length_atr_long_more_aggressive) =>
- switch in_smoothing_atr_long_more_aggressive
- "RMA" => ta.rma(source, in_length_atr_long_more_aggressive)
- "SMA" => ta.sma(source, in_length_atr_long_more_aggressive)
- "EMA" => ta.ema(source, in_length_atr_long_more_aggressive)
- => ta.wma(source, in_length_atr_long_more_aggressive)
- plot(ma_function_long_more_aggressive(ta.tr(true), in_length_atr_long_more_aggressive), title = "ATR_long_more_aggressive", color=color.new(#ff4646, 0))
- // End Detecting ATR Long More Aggressive //
- // Start Detecting ATR Long Less Aggressive //
- in_length_atr_long_less_aggressive = input.int(title="Atr Length_long_less_aggressive", defval=12, minval=0, group='Atr Long Less Aggresive')
- in_smoothing_atr_long_less_aggressive = input.string(title="Smoothing_atr_long_less_aggressive", defval="SMA", options=["RMA", "SMA", "EMA", "WMA"], group='Atr Long Less Aggresive')
- ma_function_long_less_aggressive(source, in_length_atr_long_less_aggressive) =>
- switch in_smoothing_atr_long_less_aggressive
- "RMA" => ta.rma(source, in_length_atr_long_less_aggressive)
- "SMA" => ta.sma(source, in_length_atr_long_less_aggressive)
- "EMA" => ta.ema(source, in_length_atr_long_less_aggressive)
- => ta.wma(source, in_length_atr_long_less_aggressive)
- plot(ma_function_long_less_aggressive(ta.tr(true), in_length_atr_long_less_aggressive), title = "ATR_long_less__aggressive", color=color.new(#ff4646, 0))
- // End Detecting ATR Long Less Aggressive //
- // Start Detecting ATR Short //
- in_length_atr_short = input.int(title="Atr Length_short", defval=11, minval=0, group='Atr Short')
- in_smoothing_atr_short = input.string(title="Smoothing_atr_short", defval="SMA", options=["RMA", "SMA", "EMA", "WMA"], group='Atr Short')
- ma_function_short(source, in_length_atr_short) =>
- switch in_smoothing_atr_short
- "RMA" => ta.rma(source, in_length_atr_short)
- "SMA" => ta.sma(source, in_length_atr_short)
- "EMA" => ta.ema(source, in_length_atr_short)
- => ta.wma(source, in_length_atr_short)
- plot(ma_function_short(ta.tr(true), in_length_atr_short), title = "ATR_short", color=color.new(#B71C1C, 0))
- // End Detecting ATR Short //
- // Start Detecting Boom Bar Long (Normal-Aggressive-Less_aggressive//
- atr_long_normal = ma_function_long(ta.tr(true), in_length_atr_long_normal)
- atr_long_more_aggressive = ma_function_long_more_aggressive(ta.tr(true), in_length_atr_long_more_aggressive)
- atr_long_less_aggressive = ma_function_long_less_aggressive(ta.tr(true), in_length_atr_long_less_aggressive)
- in_atr_Mult_long_normal = input.float(title='atr_Mult_long_normal', minval=0, maxval=5, defval=1.2, step=0.1, group='Atr Long Normal')
- in_atr_Mult_long_more_aggressive = input.float(title='atr_Mult_long_more_aggressive', minval=0, maxval=5, defval=1.2, step=0.1, group='Atr Long More Aggresive')
- in_atr_Mult_long_less_aggressive = input.float(title='atr_Mult_long_less_aggressive', minval=0, maxval=5, defval=1.2, step=0.1, group='Atr Long Less Aggresive')
- boom_bar_long_normal = math.abs(open - close) > atr_long_normal * in_atr_Mult_long_normal
- boom_bar_long_more_aggressive = math.abs(open - close) > atr_long_more_aggressive * in_atr_Mult_long_more_aggressive
- boom_bar_long_less_aggressive = math.abs(open - close) > atr_long_less_aggressive * in_atr_Mult_long_less_aggressive
- // End Detecting Boom Bar Long //
- // Start Detecting Boom Bar Short //
- atr_short = ma_function_short(ta.tr(true), in_length_atr_short)
- in_atr_Mult_short = input.float(title='atr_Mult_short', minval=0, maxval=5, defval=1.2, step=0.1, group='Atr Short')
- boom_bar_short = math.abs(open - close) > atr_short * in_atr_Mult_short
- // End Detecting Boom Bar Short //
- barcolor(boom_bar_long_normal and in_normal and not in_more_aggressive and not in_less_aggressive ? color.lime : boom_bar_short and in_normal and not in_more_aggressive and not in_less_aggressive ? color.lime : na)
- barcolor(boom_bar_long_more_aggressive and in_more_aggressive and not in_normal and not in_less_aggressive ? color.lime : boom_bar_short and in_more_aggressive and not in_normal and not in_less_aggressive ? color.lime : na)
- barcolor(boom_bar_long_less_aggressive and in_less_aggressive and not in_normal and not in_more_aggressive ? color.lime : boom_bar_short and in_less_aggressive and not in_normal and not in_more_aggressive ? color.lime : na)
- // Start Detecting Ema Long And Short //
- ema_long = ta.ema(close, in_ema_long)
- plot(ema_long, title="ema_long", color=color.green, linewidth = 2)
- ema_short = ta.ema(close, in_ema_short)
- plot(ema_short, title="ema_short", color=color.red, linewidth = 2)
- // End Detecting Ema Long And 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")
- 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 //color.new(color.red, 99): na)
- // 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")
- // Qui abbiamo in delay buy, sell, close command: ,"delay":"15" per dare il tempo di cancellare prima eventuali ordini pendenti e poi entrare in posizione
- // Il cancel command non deve avere il delay.
- buy_command = 'BUY COMMAND'
- sell_command = 'SELL COMMAND'
- close_command = 'CLOSE COMMAND'
- //cancel_command = 'CANCEL COMMAND'
- // Start Entry Conditions Long And Short //
- entry_long = close > baseLine and conversionLine>baseLine and close>spanB and close > ema_long and boom_bar_long_normal and inDateRange and not onlyShort and in_normal and not in_more_aggressive and not in_less_aggressive
- entry_long_more_aggressive = close > baseLine and conversionLine>baseLine and close>spanB and close > ema_long and boom_bar_long_more_aggressive and inDateRange and not onlyShort and in_more_aggressive and not in_normal and not in_less_aggressive
- entry_long_less_aggressive = close > baseLine and conversionLine>baseLine and close>spanB and close > ema_long and boom_bar_long_less_aggressive and inDateRange and not onlyShort and in_less_aggressive and not in_normal and not in_more_aggressive
- entry_short = close < baseLine and conversionLine<baseLine and close<spanB and close < ema_short and boom_bar_short and inDateRange and not onlyLong and ((in_normal and not in_more_aggressive and not in_less_aggressive) or (in_more_aggressive and not in_normal and not in_less_aggressive) or (in_less_aggressive and not in_normal and not in_more_aggressive))
- // End Entry Conditions Long And Short //
- // Start Exit Conditions Long And Short //
- exit_long = close < baseLine
- exit_short = close > baseLine
- // End Exit Conditions Long And Short //
- plot(strategy.opentrades)
- // Entry Exit Long / Short
- if entry_long // and strategy.opentrades == 0
- strategy.entry('long', strategy.long, alert_message = "Open Long Position")//, comment = buy_command)
- if entry_long_more_aggressive
- strategy.entry('long', strategy.long, alert_message = "Open Long Position More Aggressive")//, comment = buy_command)
- if entry_long_less_aggressive
- strategy.entry('long', strategy.long, alert_message = "Open Long Position Less Aggressive")//, comment = buy_command)
- if exit_long
- strategy.close(id='long', alert_message = "Close Long Position")//, comment = close_command)
- if entry_short // and strategy.opentrades == 0
- strategy.entry('short', strategy.short, alert_message = "Open Short Position")//, comment = sell_command)
- if exit_short
- strategy.close(id='short', alert_message = "Close Short Position")//, comment = close_command)
- // Nome Alert: Over-The-Clouds ETH/USDT.P BYBIT 4H
- // Commento Alert: {{strategy.order.comment}}
- // Webhook Classico Più Sicuro Ma Più Lento: https://alerts.tv-hub.org
- // Webhook Nuovo Meno Sicuro Ma Più Veloce: https://alerts.tv-hub.org/api/ExecuteTradeSignalClassic
- // ------- Inizio Calcolatore Size Posizioni Aperte E Size Posizioni Residue E Segna Con Una Croce Se Abbiamo Realizzato Un Profitto ------- //
- // Il Segno Croce Profitto Realizzato Non Funziona Sullo Swing Posizione //
- // bought = strategy.position_size[0]> strategy.position_size[1]
- // Close_TP = false
- // Close_TP := strategy.position_size[1] - strategy.position_size[0] and strategy.position_size[1] != 0 and strategy.position_size[0] != 0
- // plotshape(Close_TP,title="Close_TP", style=shape.xcross, color=color.blue, size =size.small, editable = true)
- // plot(strategy.position_size[1],"Position Old")
- // plot(strategy.position_size,"Position")
- // ------- Fine Calcolatore Size Posizioni Aperte E Size Posizioni Residue E Segna Con Una Croce Se Abbiamo Realizzato Un Profitto ------- //
- // ----------------- 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 -----------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement