Untitled
unknown
plain_text
2 years ago
50 kB
9
Indexable
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // © ScryptoMB //@version=5 // Visualization colorScheme = input.string('CryptoGraph', title="Color Scheme ", options=['CryptoGraph', 'Traditional'], group='🟣 Visualization', inline='colorScheme', tooltip='The indicative liquidation numbers and levels are for reference only. The realized numbers may be slightly different due to trading fees and funding fees') liqLineCol = input.color(#fbc02d, title="Liquidation Line ", group='🟣 Visualization', inline='colorScheme') showTable = input.bool(true, title="Backtest Results Table", group='🟣 Visualization', inline="Table1") tableSize = input.string('normal', title="Size ", options=['normal'], group='🟣 Visualization', inline="Table2") tablePosition = input.string('Top Right', title='Position ', options=['Top Right'], group='🟣 Visualization', inline="Table2") // Strategy Signal Inputs strategy = input.string('Long & Short', title="Strategy Direction", options=['Long & Short', 'Long', 'Short'], group='🟣 Strategy', inline='1', tooltip='Long bots profit when asset prices rise, Short bots profit when asset prices fall' + '\n\n' + 'Please note: to run a Short bot on a spot exchange account, you need to own the asset you want to trade. The bot will sell the asset at the current chart price and buy it back at a lower price - the profit made is actually trapped equity released from an asset you own that is declining in value.') Profit_currency = input.string('USDT', 'Profit currency ', options=['USDT', 'BTC', '$'], group='🟣 Strategy', inline='1') // Strategy settings leverageType = input.string('Isolated', title='Leverage Type ', options=['Isolated', 'Cross'], group='🟣 Strategy', inline="Leverage & Liq Line") leverage = input.float(10, title="Leverage Value", step=1, group="🟣 Strategy", inline="Leverage & Liq Line") // Entry Conditions entry_source_type = input.string('Strategizer', title="Entry Source Type", options=['Strategizer', 'External Indicator'], inline="Entry S", group="🟣 Entry Conditions") entry_source = input.source(close, title='Entry Source', inline="Entry S", group="🟣 Entry Conditions") useRSI = input.bool(false, title="RSI", group="🟣 Entry Conditions", inline="Entry C") useEMA = input.bool(false, title="Moving Average", group="🟣 Entry Conditions", inline="Entry C") rsiLength = input.int(14, title="Length ", inline='RSIL', group="• RSI") rsiLong = input.string('Smaller Than', title="RSI Long ", options=['Smaller Than', 'Greater Than', 'Crossing Up', 'Crossing Down'], inline='RSI 1', group="• RSI") rsiShort = input.string('Greater Than', title="RSI Short ", options=['Greater Than', 'Smaller Than', 'Crossing Up', 'Crossing Down'], inline='RSI 2', group="• RSI") rsiLongValue = input.int(25, title='', inline='RSI 1', group="• RSI") rsiShortValue = input.int(75, title='', inline='RSI 2', group="• RSI") emaType = input.string('EMA', title="MA Type ", options=['EMA', 'SMA', 'SMMA (RMA)', 'WMA', 'VWMA', 'HMA'], group="• Moving Average", inline="EMA 1") emaLength = input.int(200, title="MA Length", group="• Moving Average", inline="EMA 1") // Take Profit & Stop Loss tpsl_method = input.string('%', title="Take Profit & Stop Loss Method ", options=['%', 'ATR'], inline="TP", group='🟣 Take Profit & Stop Loss Settings', tooltip='This is the percentage/ATR factor distance that price needs to move in the opposite direction to your take profit or loss, at which point the bot will execute a Limit Order for profits or a Market Order for losses, on the exchange account to close the deal.' + '\n' + 'Please note, the Take Profit/ Stop Loss are calculated from the Average Entry Price.') // Percentage based TPSL Target_profit_long1 = input.float(2.0, 'Take Profit 1 Long (%)', step=0.1, inline="TP1%", group='• Take Profit & Stop Loss (%)') * 0.01 Target_profit_short1 = input.float(2.0, 'Short (%)', step=0.1, inline="TP1%", group='• Take Profit & Stop Loss (%)') * 0.01 Target_profit_close1 = input.int(50, title="Take Profit 1 Close (%)", inline='Close 1 %', group='• Take Profit & Stop Loss (%)', tooltip='Decrease position size by % input when price hits Take Profit 1. Once Take Profit 2 hits the remainder of the position will be closed\n\nExample:\nWhen having a position size of $1000 and set to 50%, after Take Profit 1 hits position size will decrease to $500') Target_profit_long2 = input.float(4.0, 'Take Profit 2 Long (%)', step=0.1, inline="TP2%", group='• Take Profit & Stop Loss (%)') * 0.01 Target_profit_short2 = input.float(4.0, 'Short (%)', step=0.1, inline="TP2%", group='• Take Profit & Stop Loss (%)') * 0.01 // Target_profit_close2 = input.int(50, title="Take Profit 2 Close (%)", inline='Close 2 %', group='• Take Profit & Stop Loss (%)', tooltip='Decrease position size by % input when price hits Take Profit 2\n\nRecommended to close the remainder of position with Take Profit 2') stop_loss_long = input.float(2.0, 'Stop Loss Long (%)', step=0.1, inline="SL1%", group='• Take Profit & Stop Loss (%)') * 0.01 stop_loss_short = input.float(2.0, 'Short (%)', step=0.1, inline="SL1%", group='• Take Profit & Stop Loss (%)') * 0.01 // ATR Based TPSL atr_length = input.int(14, title="ATR Length ", inline="ATR 3", group='• Take Profit & Stop Loss (ATR)') Target_profit_atr_long = input.float(2.0, 'Take Profit 1 Long (ATR)', step=0.1, inline='ATR 1', group='• Take Profit & Stop Loss (ATR)') target_profit_atr_short = input.float(2.0, 'Short (ATR)', step=0.1, inline='ATR 1', group='• Take Profit & Stop Loss (ATR)') Target_profit_close_atr1 = input.int(50, title="Take Profit 1 Close (%)", inline='Close 1 ATR', group='• Take Profit & Stop Loss (ATR)', tooltip='Decrease position size by % input when price hits Take Profit 1. Once Take Profit 2 hits the remainder of the position will be closed\n\nExample:\nWhen having a position size of $1000 and set to 50%, after Take Profit 1 hits position size will decrease to $500') Target_profit_atr_long2 = input.float(4.0, 'Take Profit 2 Long (ATR)', step=0.1, inline='ATR 2', group='• Take Profit & Stop Loss (ATR)') target_profit_atr_short2 = input.float(4.0, 'Short (ATR)', step=0.1, inline='ATR 2', group='• Take Profit & Stop Loss (ATR)') // Target_profit_close_atr2 = input.int(50, title="Take Profit 2 Close (%)", inline='Close 2 ATR', group='• Take Profit & Stop Loss (ATR)', tooltip='Decrease position size by % input when price hits Take Profit 2\n\nRecommended to close the remainder of position with Take Profit 2') stop_loss_atr_long = input.float(2.0, 'Stop Loss Long (ATR)', step=0.1, inline='ATR 1sl', group='• Take Profit & Stop Loss (ATR)') stop_loss_atr_short = input.float(2.0, 'Short (ATR)', step=0.1, inline='ATR 1sl', group='• Take Profit & Stop Loss (ATR)') // Order Size Settings orderSizeType = input.string('Margin (%)', title='Order Size Method', inline='OS', options=['Margin (%)', 'Margin ($)','Risk (%)', 'Risk ($)', 'Contracts'], group='🟣 Base Order Size Settings', tooltip="Margin (%): Position Size as Margin of Balance in Percentage. For example when set to 1% and using x2 leverage, one percent of your account margin will be used and the position value will be doubled because of x2 leverage\n\nMargin ($):Position Size in Dollars. When set to $100, one hundred dollars of your account margin will be used\n\nRisk (%): Risk in percentage of account balance. For example when set to 1%, when losing a trade your account balance will be -1%\n\nRisk($): Risk in Dollars of account balance. For example when set to $50, when losing a trade your account balance will be -$50\n\nContracts: Position size in Contracts. For example when set to 1 while trading Bitcoin, a position of 1 BTC will be opened") buyInputPerc = input.float(1, title='Margin (%) ', inline='Order Size1', group='🟣 Base Order Size Settings')/100 buyInputDol = input.float(100, title='Margin ($)', inline='Order Size1', group='🟣 Base Order Size Settings') percentRiskOrderSize = input.float(1, title='Risk (%) ', inline='Order Size2', group='🟣 Base Order Size Settings') dollarRiskOrderSize = input.int(50, title='Risk ($) ', inline='Order Size2', group='🟣 Base Order Size Settings') contractOrderSize = input.float(1, title='Contracts ', inline='Order Size3', group='🟣 Base Order Size Settings') // DCA Inputs useDCA = input.bool(false, title="Use Safety Orders (DCA)", group="🟣 DCA Order Settings", tooltip="Safety Orders are used to Average the cost of the asset being traded, this can help your bot to close deals faster with more profit. Safety Orders are also known as Dollar Cost Averaging and help when prices moves in the opposite direction to your bot's take profit target.") input_option = input.string("Scaling", title="DCA Input Method", options = ["Scaling", "Manual"], group="🟣 DCA Order Settings") Max_safety_trades_count = input.int(1, 'Max safety orders count', maxval=15, group='🟣 DCA Order Settings') // Scaling Distance & Size Inputs Price_deviation = input.float(0.25, 'Price deviation for first safety order (%)', step=0.01, group='• Scaling DCA Inputs') * 0.01 Safety_order_step_scale = input.float(1, 'Safety order distance scale ', step=0.01, group='• Scaling DCA Inputs', tooltip="Enter the factor you wish your safety orders to deviate from each other.\n\nFor example:\nWith distance scale 2, safety order 1 is 1% away from initial entry, safety order 2 is 2% away from safety order 1, safety order 3 is 4% away from safety order 2.") Safety_order_volume_scale = input.float(1, 'Safety order volume scale ', step=0.01, group='• Scaling DCA Inputs', tooltip="Enter the factor of your initial entry size your Safety Orders will use, to Average the cost of the asset being traded, this can help your bot to close deals faster with more profit. Safety Orders are also known as Dollar Cost Averaging and help when prices moves in the opposite direction to your bot's take profit target.\n\nFor example:\nInitial entry size of 1%, with volume scale of 2, makes the first safety order size 2% of your balance, second safety order 4% of your balance etc.") // Manual Distance & Size Inputs DCA1perc = input.float(0.25, title="Safety Order 1 (%)", step=0.1, group="• Manual DCA Inputs", inline="DCA1") / 100 DCA2perc = input.float(0.5, title="Safety Order 2 (%)", step=0.1, group="• Manual DCA Inputs", inline="DCA2") / 100 DCA3perc = input.float(0.75, title="Safety Order 3 (%)", step=0.1, group="• Manual DCA Inputs", inline="DCA3") / 100 DCA4perc = input.float(1.0, title="Safety Order 4 (%)", step=0.1, group="• Manual DCA Inputs", inline="DCA4") / 100 DCA5perc = input.float(1.25, title="Safety Order 5 (%)", step=0.1, group="• Manual DCA Inputs", inline="DCA5") / 100 DCA6perc = input.float(1.5, title="Safety Order 6 (%)", step=0.1, group="• Manual DCA Inputs", inline="DCA6") / 100 DCA7perc = input.float(1.75, title="Safety Order 7 (%)", step=0.1, group="• Manual DCA Inputs", inline="DCA7") / 100 DCA8perc = input.float(2.0, title="Safety Order 8 (%)", step=0.1, group="• Manual DCA Inputs", inline="DCA8") / 100 DCA9perc = input.float(2.25, title="Safety Order 9 (%)", step=0.1, group="• Manual DCA Inputs", inline="DCA9") / 100 DCA10perc = input.float(2.5, title="Safety Order 10 (%)", step=0.1, group="• Manual DCA Inputs", inline="DCA10") / 100 DCA11perc = input.float(2.75, title="Safety Order 11 (%)", step=0.1, group="• Manual DCA Inputs", inline="DCA11") / 100 DCA12perc = input.float(3.0, title="Safety Order 12 (%)", step=0.1, group="• Manual DCA Inputs", inline="DCA12") / 100 DCA13perc = input.float(3.25, title="Safety Order 13 (%)", step=0.1, group="• Manual DCA Inputs", inline="DCA13") / 100 DCA14perc = input.float(3.5, title="Safety Order 14 (%)", step=0.1, group="• Manual DCA Inputs", inline="DCA14") / 100 DCA15perc = input.float(3.75, title="Safety Order 15 (%)", step=0.1, group="• Manual DCA Inputs", inline="DCA15") / 100 so_size_perc1 = input.float(0.25, title="Size (%)", step=0.1, group="• Manual DCA Inputs", inline="DCA1") / 100 so_size_perc2 = input.float(0.5, title="Size (%)", step=0.1, group="• Manual DCA Inputs", inline="DCA2") / 100 so_size_perc3 = input.float(1, title="Size (%)", step=0.1, group="• Manual DCA Inputs", inline="DCA3") / 100 so_size_perc4 = input.float(1, title="Size (%)", step=0.1, group="• Manual DCA Inputs", inline="DCA4") / 100 so_size_perc5 = input.float(1, title="Size (%)", step=0.1, group="• Manual DCA Inputs", inline="DCA5") / 100 so_size_perc6 = input.float(2, title="Size (%)", step=0.1, group="• Manual DCA Inputs", inline="DCA6") / 100 so_size_perc7 = input.float(2, title="Size (%)", step=0.1, group="• Manual DCA Inputs", inline="DCA7") / 100 so_size_perc8 = input.float(2, title="Size (%)", step=0.1, group="• Manual DCA Inputs", inline="DCA8") / 100 so_size_perc9 = input.float(4, title="Size (%)", step=0.1, group="• Manual DCA Inputs", inline="DCA9") / 100 so_size_perc10 = input.float(4, title="Size (%)", step=0.1, group="• Manual DCA Inputs", inline="DCA10") / 100 so_size_perc11 = input.float(4, title="Size (%)", step=0.1, group="• Manual DCA Inputs", inline="DCA11") / 100 so_size_perc12 = input.float(8, title="Size (%)", step=0.1, group="• Manual DCA Inputs", inline="DCA12") / 100 so_size_perc13 = input.float(8, title="Size (%)", step=0.1, group="• Manual DCA Inputs", inline="DCA13") / 100 so_size_perc14 = input.float(8, title="Size (%)", step=0.1, group="• Manual DCA Inputs", inline="DCA14") / 100 so_size_perc15 = input.float(10, title="Size (%)", step=0.1, group="• Manual DCA Inputs", inline="DCA15") / 100 // Bot Confirguation configureMethod = input.string('WickHunter Auto-Configuration', title='Bot Configuration Method', options=['WickHunter Auto-Configuration', 'Alertatron Auto-Configuration', 'Manual Configuration'], inline='Bot1', group="🟣 Bot Alert Configuration", tooltip="Always use alert function () calls only when setting up alerts with this strategy") userID = input.string('uuid', title='WickHunter user ID ', tooltip="Insert your WickHunter user ID", inline='WH', group="🟣 Bot Alert Configuration") manual_Configure = input.text_area("", title='Place Manual Bot Configuration Below', group="🟣 Bot Alert Configuration") strategy(title='CryptoGraph Strategizer', overlay=true, initial_capital=1000, pyramiding=16, calc_on_order_fills=false, process_orders_on_close=false, calc_on_every_tick=true, backtest_fill_limits_assumption=1, slippage=2, commission_type=strategy.commission.percent, commission_value=0.03, use_bar_magnifier=true, close_entries_rule="ANY") // Position status_none = strategy.position_size == 0 status_long = strategy.position_size[1] == 0 and strategy.position_size > 0 status_long_offset = strategy.position_size[2] == 0 and strategy.position_size[1] > 0 status_short = strategy.position_size[1] == 0 and strategy.position_size < 0 status_increase = strategy.opentrades[1] < strategy.opentrades // Currency currency = Profit_currency == 'USDT' ? ' USDT' : Profit_currency == 'BTC' ? ' BTC' : Profit_currency == '$' ? ' $' : na // Strategy Signal ema1 = ta.ema(close, 10) ema2 = ta.ema(close, 20) Base_order_Condition_Long = ta.crossover(ema1, ema2) and barstate.isconfirmed and (strategy.position_size == 0) and ((strategy == 'Long & Short') or (strategy == 'Long')) Base_order_Condition_Short = ta.crossunder(ema1, ema2) and barstate.isconfirmed and (strategy.position_size == 0) and ((strategy == 'Long & Short') or (strategy == 'Short')) // ta.crossover(ema1, ema2) // Safety Orders pd = Price_deviation ss = Safety_order_step_scale step(i) => i == 1 ? pd : i == 2 ? pd + pd * ss : i == 3 ? pd + (pd + pd * ss) * ss : i == 4 ? pd + (pd + (pd + pd * ss) * ss) * ss : i == 5 ? pd + (pd + (pd + (pd + pd * ss) * ss) * ss) * ss : i == 6 ? pd + (pd + (pd + (pd + (pd + pd * ss) * ss) * ss) * ss) * ss : i == 7 ? pd + (pd + (pd + (pd + (pd + (pd + pd * ss) * ss) * ss) * ss) * ss) * ss : i == 8 ? pd + (pd + (pd + (pd + (pd + (pd + (pd + pd * ss) * ss) * ss) * ss) * ss) * ss) * ss : i == 9 ? pd + (pd + (pd + (pd + (pd + (pd + (pd + (pd + pd * ss) * ss) * ss) * ss) * ss) * ss) * ss) * ss : i == 10 ? pd + (pd + (pd + (pd + (pd + (pd + (pd + (pd + (pd + pd * ss) * ss) * ss) * ss) * ss) * ss) * ss) * ss) * ss : i == 11 ? pd + (pd + (pd + (pd + (pd + (pd + (pd + (pd + (pd + (pd + pd * ss) * ss) * ss) * ss) * ss) * ss) * ss) * ss) * ss) * ss : i == 12 ? pd + (pd + (pd + (pd + (pd + (pd + (pd + (pd + (pd + (pd + (pd + pd * ss) * ss) * ss) * ss) * ss) * ss) * ss) * ss) * ss) *ss) * ss : i == 13 ? pd + (pd + (pd + (pd + (pd + (pd + (pd + (pd + (pd + (pd + (pd + (pd + pd * ss) * ss) * ss) * ss) * ss) * ss) * ss) * ss) * ss) * ss) * ss) * ss : i == 14 ? pd + (pd + (pd + (pd + (pd + (pd + (pd + (pd + (pd + (pd + (pd + (pd + (pd + pd * ss) * ss) * ss) * ss) * ss) * ss) * ss) * ss) * ss) * ss) * ss) * ss) * ss : i == 15 ? pd + (pd + (pd + (pd + (pd + (pd + (pd + (pd + (pd + (pd + (pd + (pd + (pd + (pd + pd * ss) * ss) * ss) * ss) * ss) * ss) * ss) * ss) * ss) * ss) * ss) * ss) * ss) * ss : na // long_line(i) => // close[1] - close[1] * (step(i)) // short_line(i) => // close[1] + close[1] * (step(i)) so_line_long(i) => close[1] - close[1] * (step(i)) so_line_short(i) => close[1] + close[1] * (step(i)) // Safety Order global variables var float bo_size = 0.0 var float SO0L = 0.0 var float SO1L = 0.0 var float SO2L = 0.0 var float SO3L = 0.0 var float SO4L = 0.0 var float SO5L = 0.0 var float SO6L = 0.0 var float SO7L = 0.0 var float SO8L = 0.0 var float SO9L = 0.0 var float SO10L = 0.0 var float SO11L = 0.0 var float SO12L = 0.0 var float SO13L = 0.0 var float SO14L = 0.0 var float SO15L = 0.0 var float SO0S = 0.0 var float SO1S = 0.0 var float SO2S = 0.0 var float SO3S = 0.0 var float SO4S = 0.0 var float SO5S = 0.0 var float SO6S = 0.0 var float SO7S = 0.0 var float SO8S = 0.0 var float SO9S = 0.0 var float SO10S = 0.0 var float SO11S = 0.0 var float SO12S = 0.0 var float SO13S = 0.0 var float SO14S = 0.0 var float SO15S = 0.0 var float so_size1 = 0.0 var float so_size2 = 0.0 var float so_size3 = 0.0 var float so_size4 = 0.0 var float so_size5 = 0.0 var float so_size6 = 0.0 var float so_size7 = 0.0 var float so_size8 = 0.0 var float so_size9 = 0.0 var float so_size10 = 0.0 var float so_size11 = 0.0 var float so_size12 = 0.0 var float so_size13 = 0.0 var float so_size14 = 0.0 var float so_size15 = 0.0 // Take Profit & Stop Loss //Percentage based tp_perc_long1 = strategy.position_avg_price * (1 + Target_profit_long1) tp_perc_long2 = strategy.position_avg_price * (1 + Target_profit_long2) sl_perc_long = strategy.opentrades.entry_price(0) * (1 - stop_loss_long) tp_perc_short1 = strategy.position_avg_price * (1 - Target_profit_short1) tp_perc_short2 = strategy.position_avg_price * (1 - Target_profit_short2) sl_perc_short = strategy.opentrades.entry_price(0) * (1 + stop_loss_short) // ATR based atr = ta.atr(atr_length) stopLong = close - (atr * stop_loss_atr_long) stopShort = close + (atr * stop_loss_atr_short) longTP1 = close + (atr * Target_profit_atr_long) longTP2 = close + (atr * Target_profit_atr_long2) shortTP1 = close - (atr * target_profit_atr_short) shortTP2 = close - (atr * target_profit_atr_short2) // TPSL Input Options TP_line1_Long = 0.0 TP_line2_Long = 0.0 SL_line_Long = 0.0 TP_line1_Short = 0.0 TP_line2_Short = 0.0 SL_line_Short = 0.0 close_tp1 = 0 close_tp2 = 0 if tpsl_method == '%' TP_line1_Long := tp_perc_long1 TP_line2_Long := tp_perc_long2 SL_line_Long := sl_perc_long close_tp1 := Target_profit_close1 // close_tp2 := Target_profit_close2 if tpsl_method == '%' TP_line1_Short := tp_perc_short1 TP_line2_Short := tp_perc_short2 SL_line_Short := sl_perc_short if tpsl_method == 'ATR' TP_line1_Long := ta.valuewhen(Base_order_Condition_Long, longTP1, 0) TP_line2_Long := ta.valuewhen(Base_order_Condition_Long, longTP2, 0) SL_line_Long := ta.valuewhen(Base_order_Condition_Long, stopLong, 0) close_tp1 := Target_profit_close_atr1 // close_tp2 := Target_profit_close_atr2 if tpsl_method == 'ATR' TP_line1_Short := ta.valuewhen(Base_order_Condition_Short, shortTP1, 0) TP_line2_Short := ta.valuewhen(Base_order_Condition_Short, shortTP2, 0) SL_line_Short := ta.valuewhen(Base_order_Condition_Short, stopShort, 0) // Base Order Size Base_order_size = 0.0 entrySize = 0.0 entrySizeType = '' // Margin % & $ if orderSizeType == 'Margin (%)' Base_order_size := math.abs(((strategy.initial_capital + strategy.netprofit)/close) * buyInputPerc) * leverage entrySize := buyInputPerc * leverage entrySizeType := '"PERCENT"' if orderSizeType == 'Margin ($)' Base_order_size := (buyInputDol / close) * leverage entrySize := buyInputDol * leverage entrySizeType := '"DOLLAR"' // Risk (%) if orderSizeType == 'Risk (%)' if Base_order_Condition_Long Base_order_size := ((strategy.initial_capital + strategy.netprofit) / 100 * percentRiskOrderSize) / (((close-(close - stop_loss_atr_long*atr)) / close) * syminfo.pointvalue * close) entrySize := math.abs((percentRiskOrderSize / 100) / ((stopLong - close) / close)) entrySizeType := '"PERCENT"' if Base_order_Condition_Short Base_order_size := ((strategy.initial_capital + strategy.netprofit) / 100 * percentRiskOrderSize) / (((close-(close - stop_loss_atr_short*atr)) / close) * syminfo.pointvalue * close) entrySize := math.abs((percentRiskOrderSize / 100) / ((stopShort - close) / close)) entrySizeType := '"PERCENT"' Base_order_long = Base_order_size[ta.barssince(Base_order_Condition_Long)] Base_order_short = Base_order_size[ta.barssince(Base_order_Condition_Short)] if strategy.position_size > 0 Base_order_size := Base_order_long if strategy.position_size < 0 Base_order_size := Base_order_short // Risk ($) if orderSizeType == 'Risk ($)' if Base_order_Condition_Long Base_order_size := dollarRiskOrderSize / (((close-(close - stop_loss_atr_long*atr)) / close) * syminfo.pointvalue * close) entrySize := dollarRiskOrderSize / ((close-(close - stop_loss_atr_long*atr)) / close) entrySizeType := '"DOLLAR"' if Base_order_Condition_Short Base_order_size := dollarRiskOrderSize / (((close-(close - stop_loss_atr_short*atr)) / close) * syminfo.pointvalue * close) entrySize := dollarRiskOrderSize / ((close-(close - stop_loss_atr_short*atr)) / close) entrySizeType := '"DOLLAR"' Base_order_long = Base_order_size[ta.barssince(Base_order_Condition_Long)] Base_order_short = Base_order_size[ta.barssince(Base_order_Condition_Short)] if strategy.position_size > 0 Base_order_size := Base_order_long // Contracts if orderSizeType == 'Contracts' Base_order_size := contractOrderSize entrySize := contractOrderSize * close entrySizeType := '"DOLLAR"' // Liq base order Base_order_size_liq = math.abs(((strategy.initial_capital + strategy.netprofit)/close) * (buyInputPerc+0.014)) // Safety Order Logics if input_option == "Scaling" // Scaling SO Distance Long SO0L := ta.valuewhen(status_long, so_line_long(0), 0) SO1L := ta.valuewhen(status_long, so_line_long(1), 0) SO2L := ta.valuewhen(status_long, so_line_long(2), 0) SO3L := ta.valuewhen(status_long, so_line_long(3), 0) SO4L := ta.valuewhen(status_long, so_line_long(4), 0) SO5L := ta.valuewhen(status_long, so_line_long(5), 0) SO6L := ta.valuewhen(status_long, so_line_long(6), 0) SO7L := ta.valuewhen(status_long, so_line_long(7), 0) SO8L := ta.valuewhen(status_long, so_line_long(8), 0) SO9L := ta.valuewhen(status_long, so_line_long(9), 0) SO10L := ta.valuewhen(status_long, so_line_long(10), 0) SO11L := ta.valuewhen(status_long, so_line_long(11), 0) SO12L := ta.valuewhen(status_long, so_line_long(12), 0) SO13L := ta.valuewhen(status_long, so_line_long(13), 0) SO14L := ta.valuewhen(status_long, so_line_long(14), 0) SO15L := ta.valuewhen(status_long, so_line_long(15), 0) // Scaling SO Distance Short SO0S := ta.valuewhen(status_short, so_line_short(0), 0) SO1S := ta.valuewhen(status_short, so_line_short(1), 0) SO2S := ta.valuewhen(status_short, so_line_short(2), 0) SO3S := ta.valuewhen(status_short, so_line_short(3), 0) SO4S := ta.valuewhen(status_short, so_line_short(4), 0) SO5S := ta.valuewhen(status_short, so_line_short(5), 0) SO6S := ta.valuewhen(status_short, so_line_short(6), 0) SO7S := ta.valuewhen(status_short, so_line_short(7), 0) SO8S := ta.valuewhen(status_short, so_line_short(8), 0) SO9S := ta.valuewhen(status_short, so_line_short(9), 0) SO10S := ta.valuewhen(status_short, so_line_short(10), 0) SO11S := ta.valuewhen(status_short, so_line_short(11), 0) SO12S := ta.valuewhen(status_short, so_line_short(12), 0) SO13S := ta.valuewhen(status_short, so_line_short(13), 0) SO14S := ta.valuewhen(status_short, so_line_short(14), 0) SO15S := ta.valuewhen(status_short, so_line_short(15), 0) // Scaling Order size bo_size := Base_order_size so_size1 := Base_order_size * math.pow(Safety_order_volume_scale, 1) so_size2 := Base_order_size * math.pow(Safety_order_volume_scale, 2) so_size3 := Base_order_size * math.pow(Safety_order_volume_scale, 3) so_size4 := Base_order_size * math.pow(Safety_order_volume_scale, 4) so_size5 := Base_order_size * math.pow(Safety_order_volume_scale, 5) so_size6 := Base_order_size * math.pow(Safety_order_volume_scale, 6) so_size7 := Base_order_size * math.pow(Safety_order_volume_scale, 7) so_size8 := Base_order_size * math.pow(Safety_order_volume_scale, 8) so_size9 := Base_order_size * math.pow(Safety_order_volume_scale, 9) so_size10 := Base_order_size * math.pow(Safety_order_volume_scale, 10) so_size11 := Base_order_size * math.pow(Safety_order_volume_scale, 11) so_size12 := Base_order_size * math.pow(Safety_order_volume_scale, 12) so_size13 := Base_order_size * math.pow(Safety_order_volume_scale, 13) so_size14 := Base_order_size * math.pow(Safety_order_volume_scale, 14) so_size15 := Base_order_size * math.pow(Safety_order_volume_scale, 15) if input_option == "Manual" // Manual SO Distance Long SO0L := ta.valuewhen(Base_order_Condition_Long and strategy.opentrades == 0,close,0) * (1 - 0) SO1L := ta.valuewhen(Base_order_Condition_Long and strategy.opentrades == 0,close,0) * (1 - DCA1perc) SO2L := ta.valuewhen(Base_order_Condition_Long and strategy.opentrades == 0,close,0) * (1 - DCA2perc) SO3L := ta.valuewhen(Base_order_Condition_Long and strategy.opentrades == 0,close,0) * (1 - DCA3perc) SO4L := ta.valuewhen(Base_order_Condition_Long and strategy.opentrades == 0,close,0) * (1 - DCA4perc) SO5L := ta.valuewhen(Base_order_Condition_Long and strategy.opentrades == 0,close,0) * (1 - DCA5perc) SO6L := ta.valuewhen(Base_order_Condition_Long and strategy.opentrades == 0,close,0) * (1 - DCA6perc) SO7L := ta.valuewhen(Base_order_Condition_Long and strategy.opentrades == 0,close,0) * (1 - DCA7perc) SO8L := ta.valuewhen(Base_order_Condition_Long and strategy.opentrades == 0,close,0) * (1 - DCA8perc) SO9L := ta.valuewhen(Base_order_Condition_Long and strategy.opentrades == 0,close,0) * (1 - DCA9perc) SO10L := ta.valuewhen(Base_order_Condition_Long and strategy.opentrades == 0,close,0) * (1 - DCA10perc) SO11L := ta.valuewhen(Base_order_Condition_Long and strategy.opentrades == 0,close,0) * (1 - DCA11perc) SO12L := ta.valuewhen(Base_order_Condition_Long and strategy.opentrades == 0,close,0) * (1 - DCA12perc) SO13L := ta.valuewhen(Base_order_Condition_Long and strategy.opentrades == 0,close,0) * (1 - DCA13perc) SO14L := ta.valuewhen(Base_order_Condition_Long and strategy.opentrades == 0,close,0) * (1 - DCA14perc) SO15L := ta.valuewhen(Base_order_Condition_Long and strategy.opentrades == 0,close,0) * (1 - DCA15perc) // Manual SO Distance Short SO0S := ta.valuewhen(Base_order_Condition_Short and strategy.opentrades == 0,close,0) * (1 + 0) SO1S := ta.valuewhen(Base_order_Condition_Short and strategy.opentrades == 0,close,0) * (1 + DCA1perc) SO2S := ta.valuewhen(Base_order_Condition_Short and strategy.opentrades == 0,close,0) * (1 + DCA2perc) SO3S := ta.valuewhen(Base_order_Condition_Short and strategy.opentrades == 0,close,0) * (1 + DCA3perc) SO4S := ta.valuewhen(Base_order_Condition_Short and strategy.opentrades == 0,close,0) * (1 + DCA4perc) SO5S := ta.valuewhen(Base_order_Condition_Short and strategy.opentrades == 0,close,0) * (1 + DCA5perc) SO6S := ta.valuewhen(Base_order_Condition_Short and strategy.opentrades == 0,close,0) * (1 + DCA6perc) SO7S := ta.valuewhen(Base_order_Condition_Short and strategy.opentrades == 0,close,0) * (1 + DCA7perc) SO8S := ta.valuewhen(Base_order_Condition_Short and strategy.opentrades == 0,close,0) * (1 + DCA8perc) SO9S := ta.valuewhen(Base_order_Condition_Short and strategy.opentrades == 0,close,0) * (1 + DCA9perc) SO10S := ta.valuewhen(Base_order_Condition_Short and strategy.opentrades == 0,close,0) * (1 + DCA10perc) SO11S := ta.valuewhen(Base_order_Condition_Short and strategy.opentrades == 0,close,0) * (1 + DCA11perc) SO12S := ta.valuewhen(Base_order_Condition_Short and strategy.opentrades == 0,close,0) * (1 + DCA12perc) SO13S := ta.valuewhen(Base_order_Condition_Short and strategy.opentrades == 0,close,0) * (1 + DCA13perc) SO14S := ta.valuewhen(Base_order_Condition_Short and strategy.opentrades == 0,close,0) * (1 + DCA14perc) SO15S := ta.valuewhen(Base_order_Condition_Short and strategy.opentrades == 0,close,0) * (1 + DCA15perc) // Manual Order size bo_size := Base_order_size so_size1 := math.abs(((strategy.initial_capital + strategy.netprofit)/close) * so_size_perc1) so_size2 := math.abs(((strategy.initial_capital + strategy.netprofit)/close) * so_size_perc2) so_size3 := math.abs(((strategy.initial_capital + strategy.netprofit)/close) * so_size_perc3) so_size4 := math.abs(((strategy.initial_capital + strategy.netprofit)/close) * so_size_perc4) so_size5 := math.abs(((strategy.initial_capital + strategy.netprofit)/close) * so_size_perc5) so_size6 := math.abs(((strategy.initial_capital + strategy.netprofit)/close) * so_size_perc6) so_size7 := math.abs(((strategy.initial_capital + strategy.netprofit)/close) * so_size_perc7) so_size8 := math.abs(((strategy.initial_capital + strategy.netprofit)/close) * so_size_perc8) so_size9 := math.abs(((strategy.initial_capital + strategy.netprofit)/close) * so_size_perc9) so_size10 := math.abs(((strategy.initial_capital + strategy.netprofit)/close) * so_size_perc10) so_size11 := math.abs(((strategy.initial_capital + strategy.netprofit)/close) * so_size_perc11) so_size12 := math.abs(((strategy.initial_capital + strategy.netprofit)/close) * so_size_perc12) so_size13 := math.abs(((strategy.initial_capital + strategy.netprofit)/close) * so_size_perc13) so_size14 := math.abs(((strategy.initial_capital + strategy.netprofit)/close) * so_size_perc14) so_size15 := math.abs(((strategy.initial_capital + strategy.netprofit)/close) * so_size_perc15) // Safety Order Functions Safe_order_line_long(i) => i == 0 ? SO0L : i == 1 ? SO1L : i == 2 ? SO2L : i == 3 ? SO3L : i == 4 ? SO4L : i == 5 ? SO5L : i == 6 ? SO6L : i == 7 ? SO7L : i == 8 ? SO8L : i == 9 ? SO9L : i == 10 ? SO10L : i == 11 ? SO11L : i == 12 ? SO12L : i == 13 ? SO13L : i == 14 ? SO14L : i == 15 ? SO15L : na Safe_order_line_short(i) => i == 0 ? SO0S : i == 1 ? SO1S : i == 2 ? SO2S : i == 3 ? SO3S : i == 4 ? SO4S : i == 5 ? SO5S : i == 6 ? SO6S : i == 7 ? SO7S : i == 8 ? SO8S : i == 9 ? SO9S : i == 10 ? SO10S : i == 11 ? SO11S : i == 12 ? SO12S : i == 13 ? SO13S : i == 14 ? SO14S : i == 15 ? SO15S : na safety_order_size(i) => i == 1 ? so_size1 : i == 2 ? so_size2 : i == 3 ? so_size3 : i == 4 ? so_size4 : i == 5 ? so_size5 : i == 6 ? so_size6 : i == 7 ? so_size7 : i == 8 ? so_size8 : i == 9 ? so_size9 : i == 10 ? so_size10 : i == 11 ? so_size11 : i == 12 ? so_size12 : i == 13 ? so_size13 : i == 14 ? so_size14 : i == 15 ? so_size15 : na // Liquidation Levels Isolated/Cross // ISOLATED Leverage //long liqIsoL = (strategy.position_avg_price * (1 - (1/leverage) + 0.005)) if liqIsoL <= 0 liqIsoL := 0.5 //short liqIsoS = (strategy.position_avg_price * (1 + (1/leverage) - 0.005)) // CROSS Leverage sum_safety_order_size(i) => sum_so = 0.0 if i >= 1 for x = 1 to i by 1 temp = sum_so sum_so := temp + safety_order_size(x) sum_so initial_margin = (Base_order_size + sum_safety_order_size(strategy.opentrades - 1)) * strategy.position_avg_price * 0.01 maintenance_margin = (Base_order_size + sum_safety_order_size(strategy.opentrades - 1)) * strategy.position_avg_price * 0.005 available_balance = strategy.equity - (((Base_order_size_liq * close)/leverage)) - ((sum_safety_order_size(strategy.opentrades - 1)*close)/leverage) total_sustainable_loss = available_balance + initial_margin - maintenance_margin //long liqCrossLong = strategy.position_avg_price - (total_sustainable_loss/Base_order_size) if liqCrossLong <= 0 liqCrossLong := 0.5 //short liqCrossShort = strategy.position_avg_price + (total_sustainable_loss/Base_order_size) // Strategy entry/exit logics // Base order Long if Base_order_Condition_Long and strategy.opentrades == 0 strategy.entry('Base order', strategy.long, qty=Base_order_size, comment='BO' + ' - ' + str.tostring(bo_size * close) + str.tostring(currency)) // Safety Orders Long if Max_safety_trades_count >= 1 and useDCA for i = 1 to Max_safety_trades_count by 1 i_s = str.tostring(i) if Base_order_Condition_Long and strategy.opentrades == 0 strategy.entry('Safety order' + i_s, strategy.long, qty=safety_order_size(i), limit=Safe_order_line_long(i), comment='SO' + i_s + ' - ' + str.tostring(safety_order_size(i) * close) + str.tostring(currency)) // Exit Long for i = 1 to Max_safety_trades_count by 1 i_s = str.tostring(i) strategy.cancel('Safety order' + i_s, when=status_none) strategy.exit('Exit Long 1','Base order', qty_percent=close_tp1, limit=TP_line1_Long, stop=SL_line_Long) strategy.exit('Exit Long 1','Safety order' + i_s, qty_percent=close_tp1, limit=TP_line1_Long, stop=SL_line_Long) strategy.exit('Exit Long 2','Base order', limit=TP_line2_Long, stop=SL_line_Long) strategy.exit('Exit Long 2','Safety order' + i_s, limit=TP_line2_Long, stop=SL_line_Long) // Base Order Short if Base_order_Condition_Short and strategy.opentrades == 0 strategy.entry('Base order short', strategy.short, qty=Base_order_size) if Max_safety_trades_count >= 1 and useDCA strategy.entry("Safety order short1", strategy.short, qty=safety_order_size(1), limit=Safe_order_line_short(1), comment="Safety Order 1") // for i = 1 to Max_safety_trades_count by 1 // i_s = str.tostring(i) // strategy.entry('Safety order short' + i_s, strategy.short, qty=safety_order_size(i), limit=Safe_order_line_short(i)) // Safety Orders Short // if Max_safety_trades_count >= 1 and useDCA // for i = 1 to Max_safety_trades_count by 1 // i_s = str.tostring(i) // if Base_order_Condition_Short and strategy.opentrades == 0 // strategy.entry('Safety order short' + i_s, strategy.short, qty=safety_order_size(i), // limit=Safe_order_line_short(i)) // Exit Short for i = 1 to Max_safety_trades_count by 1 i_s = str.tostring(i) strategy.cancel('Safety order short' + i_s, when=status_none) strategy.exit('Exit Short 1 bo','Base order short', qty_percent=close_tp1, limit=TP_line1_Short, stop=SL_line_Short) strategy.exit('Exit Short 1 so','Safety order short' + i_s, qty_percent=close_tp1, limit=TP_line1_Short, stop=SL_line_Short) strategy.exit('Exit Short 2 bo','Base order short', limit=TP_line2_Short, stop=SL_line_Short) strategy.exit('Exit Short 2 so','Safety order short' + i_s, limit=TP_line2_Short, stop=SL_line_Short) // Plots plot(ema1, color=color.yellow) plot(ema2, color=color.orange) plotshape(Base_order_Condition_Long, title='Long Entry', location=location.belowbar, style=shape.labelup, color=color.new(#2C9670, 0), text='Long', textcolor=color.new(color.white, 0)) plotshape(Base_order_Condition_Short, title='Short Entry', location=location.abovebar, style=shape.labeldown, color=color.red, text='Short', textcolor=color.new(color.white, 0)) var float liqLineType = 0.0 if leverageType == 'Isolated' if strategy.position_size > 0 liqLineType := liqIsoL if strategy.position_size < 0 liqLineType := liqIsoS if leverageType == 'Cross' if strategy.position_size > 0 liqLineType := liqCrossLong if strategy.position_size < 0 liqLineType := liqCrossShort // account_balance = plot(strategy.equity) entryLevel = plot(strategy.position_avg_price, title="Entry level", color=color.white, linewidth=1, style=plot.style_linebr) tpLineLong1 = plot(strategy.position_size > 0 ? TP_line1_Long : na, 'Take Profit', color=#26c6da, linewidth=2, style=plot.style_linebr) tpLineLong2 = plot(strategy.position_size > 0 ? TP_line2_Long : na, 'Take Profit', color=#26c6da, linewidth=2, style=plot.style_linebr) slLineLong = plot(strategy.position_size > 0 ? SL_line_Long : na, 'Stop Loss', color=#ec407a, linewidth=2, style=plot.style_linebr) tpLineShort1 = plot(strategy.position_size < 0 ? TP_line1_Short : na, 'Take Profit', color=#26c6da, linewidth=2, style=plot.style_linebr) tpLineShort2 = plot(strategy.position_size < 0 ? TP_line2_Short : na, 'Take Profit', color=#26c6da, linewidth=2, style=plot.style_linebr) slLineShort = plot(strategy.position_size < 0 ? SL_line_Short : na, 'Stop Loss', color=#ec407a, linewidth=2, style=plot.style_linebr) liqLine = plot(strategy.position_size == 0 ? na : liqLineType, title="Isolated Liquidation Price", color=liqLineCol, linewidth=2, style=plot.style_linebr) // Safety Orders Long so1Line = plot(strategy.position_size > 0 and Max_safety_trades_count >= 1 and (strategy.opentrades <= 1) and useDCA ? Safe_order_line_long(1) : na, 'Safety order1', color=#d86dff, style=plot.style_linebr) so2Line = plot(strategy.position_size > 0 and Max_safety_trades_count >= 2 and (strategy.opentrades <= 2) and useDCA ? Safe_order_line_long(2) : na, 'Safety order2', color=#d86dff, style=plot.style_linebr) so3Line = plot(strategy.position_size > 0 and Max_safety_trades_count >= 3 and (strategy.opentrades <= 3) and useDCA ? Safe_order_line_long(3) : na, 'Safety order3', color=#d86dff, style=plot.style_linebr) so4Line = plot(strategy.position_size > 0 and Max_safety_trades_count >= 4 and (strategy.opentrades <= 4) and useDCA ? Safe_order_line_long(4) : na, 'Safety order4', color=#d86dff, style=plot.style_linebr) so5Line = plot(strategy.position_size > 0 and Max_safety_trades_count >= 5 and (strategy.opentrades <= 5) and useDCA ? Safe_order_line_long(5) : na, 'Safety order5', color=#d86dff, style=plot.style_linebr) so6Line = plot(strategy.position_size > 0 and Max_safety_trades_count >= 6 and (strategy.opentrades <= 6) and useDCA ? Safe_order_line_long(6) : na, 'Safety order6', color=#d86dff, style=plot.style_linebr) so7Line = plot(strategy.position_size > 0 and Max_safety_trades_count >= 7 and (strategy.opentrades <= 7) and useDCA ? Safe_order_line_long(7) : na, 'Safety order7', color=#d86dff, style=plot.style_linebr) so8Line = plot(strategy.position_size > 0 and Max_safety_trades_count >= 8 and (strategy.opentrades <= 8) and useDCA ? Safe_order_line_long(8) : na, 'Safety order8', color=#d86dff, style=plot.style_linebr) so9Line = plot(strategy.position_size > 0 and Max_safety_trades_count >= 9 and (strategy.opentrades <= 9) and useDCA ? Safe_order_line_long(9) : na, 'Safety order9', color=#d86dff, style=plot.style_linebr) so10Line = plot(strategy.position_size > 0 and Max_safety_trades_count >= 10 and (strategy.opentrades <= 10) and useDCA ? Safe_order_line_long(10) : na, 'Safety order10', color=#d86dff, style=plot.style_linebr) so11Line = plot(strategy.position_size > 0 and Max_safety_trades_count >= 11 and (strategy.opentrades <= 11) and useDCA ? Safe_order_line_long(11) : na, 'Safety order11', color=#d86dff, style=plot.style_linebr) so12Line = plot(strategy.position_size > 0 and Max_safety_trades_count >= 12 and (strategy.opentrades <= 12) and useDCA ? Safe_order_line_long(12) : na, 'Safety order12', color=#d86dff, style=plot.style_linebr) so13Line = plot(strategy.position_size > 0 and Max_safety_trades_count >= 13 and (strategy.opentrades <= 13) and useDCA ? Safe_order_line_long(13) : na, 'Safety order13', color=#d86dff, style=plot.style_linebr) so14Line = plot(strategy.position_size > 0 and Max_safety_trades_count >= 14 and (strategy.opentrades <= 14) and useDCA ? Safe_order_line_long(14) : na, 'Safety order14', color=#d86dff, style=plot.style_linebr) so15Line = plot(strategy.position_size > 0 and Max_safety_trades_count >= 15 and (strategy.opentrades <= 15) and useDCA ? Safe_order_line_long(15) : na, 'Safety order15', color=#d86dff, style=plot.style_linebr) // Safety Orders Short plot(strategy.position_size < 0 and Max_safety_trades_count >= 1 and (strategy.opentrades <= 1) and useDCA ? Safe_order_line_short(1) : na, 'Safety order1', color=#d86dff, style=plot.style_linebr) plot(strategy.position_size < 0 and Max_safety_trades_count >= 2 and (strategy.opentrades <= 2) and useDCA ? Safe_order_line_short(2) : na, 'Safety order2', color=#d86dff, style=plot.style_linebr) plot(strategy.position_size < 0 and Max_safety_trades_count >= 3 and (strategy.opentrades <= 3) and useDCA ? Safe_order_line_short(3) : na, 'Safety order3', color=#d86dff, style=plot.style_linebr) plot(strategy.position_size < 0 and Max_safety_trades_count >= 4 and (strategy.opentrades <= 4) and useDCA ? Safe_order_line_short(4) : na, 'Safety order4', color=#d86dff, style=plot.style_linebr) plot(strategy.position_size < 0 and Max_safety_trades_count >= 5 and (strategy.opentrades <= 5) and useDCA ? Safe_order_line_short(5) : na, 'Safety order5', color=#d86dff, style=plot.style_linebr) plot(strategy.position_size < 0 and Max_safety_trades_count >= 6 and (strategy.opentrades <= 6) and useDCA ? Safe_order_line_short(6) : na, 'Safety order6', color=#d86dff, style=plot.style_linebr) plot(strategy.position_size < 0 and Max_safety_trades_count >= 7 and (strategy.opentrades <= 7) and useDCA ? Safe_order_line_short(7) : na, 'Safety order7', color=#d86dff, style=plot.style_linebr) plot(strategy.position_size < 0 and Max_safety_trades_count >= 8 and (strategy.opentrades <= 8) and useDCA ? Safe_order_line_short(8) : na, 'Safety order8', color=#d86dff, style=plot.style_linebr) plot(strategy.position_size < 0 and Max_safety_trades_count >= 9 and (strategy.opentrades <= 9) and useDCA ? Safe_order_line_short(9) : na, 'Safety order9', color=#d86dff, style=plot.style_linebr) plot(strategy.position_size < 0 and Max_safety_trades_count >= 10 and (strategy.opentrades <= 10) and useDCA ? Safe_order_line_short(10) : na, 'Safety order10', color=#d86dff, style=plot.style_linebr) plot(strategy.position_size < 0 and Max_safety_trades_count >= 11 and (strategy.opentrades <= 11) and useDCA ? Safe_order_line_short(11) : na, 'Safety order11', color=#d86dff, style=plot.style_linebr) plot(strategy.position_size < 0 and Max_safety_trades_count >= 12 and (strategy.opentrades <= 12) and useDCA ? Safe_order_line_short(12) : na, 'Safety order12', color=#d86dff, style=plot.style_linebr) plot(strategy.position_size < 0 and Max_safety_trades_count >= 13 and (strategy.opentrades <= 13) and useDCA ? Safe_order_line_short(13) : na, 'Safety order13', color=#d86dff, style=plot.style_linebr) plot(strategy.position_size < 0 and Max_safety_trades_count >= 14 and (strategy.opentrades <= 14) and useDCA ? Safe_order_line_short(14) : na, 'Safety order14', color=#d86dff, style=plot.style_linebr) plot(strategy.position_size < 0 and Max_safety_trades_count >= 15 and (strategy.opentrades <= 15) and useDCA ? Safe_order_line_short(15) : na, 'Safety order15', color=#d86dff, style=plot.style_linebr) //Background fill(tpLineLong2, entryLevel, title="Background", top_value=TP_line1_Long, bottom_value=strategy.position_avg_price,top_color=color.rgb(0, 188, 212, 65), bottom_color=color.rgb(0, 188, 212, 92)) fill(slLineLong, entryLevel, title="Background", top_value=strategy.position_avg_price, bottom_value=SL_line_Long, top_color=color.rgb(177, 41, 255, 94), bottom_color=color.rgb(177, 41, 255, 70)) fill(tpLineShort2, entryLevel, title="Background", top_value=strategy.position_avg_price, bottom_value=TP_line1_Short,top_color=color.rgb(0, 188, 212, 92), bottom_color=color.rgb(0, 188, 212, 65)) fill(slLineShort, entryLevel, title="Background", top_value=SL_line_Short, bottom_value=strategy.position_avg_price, top_color=color.rgb(177, 41, 255, 70), bottom_color=color.rgb(177, 41, 255, 94)) // bot_usage(i) => // i == 1 ? Base_order_size + safety_order_size(1) : // i == 2 ? Base_order_size + safety_order_size(1) + safety_order_size(2) : // i == 3 ? Base_order_size + safety_order_size(1) + safety_order_size(2) + safety_order_size(3) : // i == 4 ? Base_order_size + safety_order_size(1) + safety_order_size(2) + safety_order_size(3) + safety_order_size(4) : // i == 5 ? Base_order_size + safety_order_size(1) + safety_order_size(2) + safety_order_size(3) + safety_order_size(4) + safety_order_size(5) : // i == 6 ? Base_order_size + safety_order_size(1) + safety_order_size(2) + safety_order_size(3) + safety_order_size(4) + safety_order_size(5) + safety_order_size(6) : // i == 7 ? Base_order_size + safety_order_size(1) + safety_order_size(2) + safety_order_size(3) + safety_order_size(4) + safety_order_size(5) + safety_order_size(6) + safety_order_size(7) : // i == 8 ? Base_order_size + safety_order_size(1) + safety_order_size(2) + safety_order_size(3) + safety_order_size(4) + safety_order_size(5) + safety_order_size(6) + safety_order_size(7) + safety_order_size(8) : // i == 9 ? Base_order_size + safety_order_size(1) + safety_order_size(2) + safety_order_size(3) + safety_order_size(4) + safety_order_size(5) + safety_order_size(6) + safety_order_size(7) + safety_order_size(8) + safety_order_size(9) : // i == 10 ? Base_order_size + safety_order_size(1) + safety_order_size(2) + safety_order_size(3) + safety_order_size(4) + safety_order_size(5) + safety_order_size(6) + safety_order_size(7) + safety_order_size(8) + safety_order_size(9) + safety_order_size(10) : na // equity = strategy.equity // bot_use = bot_usage(Max_safety_trades_count) // bot_dev = float(step(Max_safety_trades_count)) * 100 // bot_ava = (bot_use / equity) * 100 // string label = // 'Balance : ' + str.tostring(math.round(equity, 0), '###,###,###,###') + ' USDT' + '\n' + // 'Max amount for bot usage : ' + str.tostring(math.round(bot_use, 0), '###,###,###,###') + ' USDT' + '\n' + // 'Max safety order price deviation : ' + str.tostring(math.round(bot_dev, 0), '##.##') + ' %' + '\n' + // '% of available balance : ' + str.tostring(math.round(bot_ava, 0), '###,###,###,###') + ' %' // + (bot_ava > 100 ? '\n \n' + '⚠ Warning! Bot will use amount greater than you have on exchange' : na) // if status_long // day_label = // label.new( // x=time[1], // y=high * 1.03, // text=label, // xloc=xloc.bar_time, // yloc=yloc.price, // color=bot_ava > 100 ? color.new(color.yellow, 0) : color.new(color.black, 50), // style=label.style_label_lower_right, // textcolor=bot_ava > 100 ? color.new(color.red, 0) : color.new(color.silver, 0), // size=size.normal, // textalign=text.align_left) // var color soCol = na // var color tpCol = na // var color slCol = na // var color tpBgTop = na // var color tpBgBot = na // var color slBgTop = na // var color slBgBot = na // if colorScheme == 'CryptoGraph' // soCol := #d86dff // tpCol := #26c6da // slCol := #ec407a // tpBgTop := color.rgb(0, 188, 212, 65) // tpBgBot := color.rgb(0, 188, 212, 92) // slBgTop := color.rgb(177, 41, 255, 94) // slBgBot := color.rgb(177, 41, 255, 70) // if colorScheme == 'Traditional' // soCol := #ff5252 // tpCol := #00e676 // slCol := #ff5252 // tpBgTop := color.rgb(0, 255, 0, 65) // tpBgBot := color.rgb(0, 255, 0, 98) // slBgTop := color.rgb(255, 0, 0, 88) // slBgBot := color.rgb(255, 0, 0, 66)
Editor is loading...