This code is for an indicator which aggregates trading volume data from multiple tickers, but I would like to add an option so that it only uses the ticker displayed on the chart. I think that I have come pretty close but now I am stuck. Everything regarding this question is between the lines of slashes.
The indicator also has an option to calculate the value of the traded volume which I would like to be able to be enabled when the "Only use symbol on chart" is checked.
The original code is written by @BjornMistiaen which he gave to me as an answer to this question I have asked earlier to which I have added a few new features.
This is probably an easy to solve problem, or so I think / hope but I am not familiar to coding, although I am slowly starting to get better at it :)
Code:
//@version=4
study(title="Aggregated Volume Colored", precision=0, overlay=false)
//
// Plot style selections
var string PS1 = "Columns"
var string PS2 = "Histogram"
// Inputs
i_sym1 = input(true, "", input.bool, inline="1", group="Symbols")
i_sym2 = input(true, "", input.bool, inline="2", group="Symbols")
i_sym3 = input(true, "", input.bool, inline="3", group="Symbols")
i_sym4 = input(true, "", input.bool, inline="4", group="Symbols")
i_sym5 = input(true, "", input.bool, inline="5", group="Symbols")
i_sym6 = input(true, "", input.bool, inline="6", group="Symbols")
i_sym7 = input(true, "", input.bool, inline="7", group="Symbols")
i_sym8 = input(true, "", input.bool, inline="8", group="Symbols")
i_sym9 = input(true, "", input.bool, inline="9", group="Symbols")
i_sym10 = input(true, "", input.bool, inline="10", group="Symbols")
i_sym1_color = input(color.yellow, "", input.color, inline="1", group="Symbols")
i_sym2_color = input(color.orange, "", input.color, inline="2", group="Symbols")
i_sym3_color = input(#133B57, "", input.color, inline="3", group="Symbols")
i_sym4_color = input(#2483FF, "", input.color, inline="4", group="Symbols")
i_sym5_color = input(color.white, "", input.color, inline="5", group="Symbols")
i_sym6_color = input(color.navy, "", input.color, inline="6", group="Symbols")
i_sym7_color = input(color.teal, "", input.color, inline="7", group="Symbols")
i_sym8_color = input(color.aqua, "", input.color, inline="8", group="Symbols")
i_sym9_color = input(color.purple, "", input.color, inline="9", group="Symbols")
i_sym10_color = input(color.green, "", input.color, inline="10", group="Symbols")
i_sym1_ticker = input("BINANCE:BTCUSDT", "", input.symbol, inline="1", group="Symbols")
i_sym2_ticker = input("BINANCE:BTCBUSD", "", input.symbol, inline="2", group="Symbols")
i_sym3_ticker = input("BINGBON:BTCUSDT", "", input.symbol, inline="3", group="Symbols")
i_sym4_ticker = input("HUOBI:BTCUSDT", "", input.symbol, inline="4", group="Symbols")
i_sym5_ticker = input("OKEX:BTCUSDT", "", input.symbol, inline="5", group="Symbols")
i_sym6_ticker = input("COINBASE:BTCUSD", "", input.symbol, inline="6", group="Symbols")
i_sym7_ticker = input("BITFINEX:BTCUSD", "", input.symbol, inline="7", group="Symbols")
i_sym8_ticker = input("GEMINI:BTCUSD", "", input.symbol, inline="8", group="Symbols")
i_sym9_ticker = input("KRAKEN:XBTUSD", "", input.symbol, inline="9", group="Symbols")
i_sym10_ticker = input("BITSTAMP:BTCUSD", "", input.symbol, inline="10", group="Symbols")
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
onchart_ticker = input(false, title= "Only use symbol on chart", inline="12", group="Symbols") // 'inline=12' on purpose so there is a blank line to make it clearer //
i_chart_color = input(#e91cec, "", input.color, inline="12", group="Symbols")
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// MA
showMA = input (false, title = "Show MA", inline="0", group = "Moving Average")
MAcolor = input (#f44336, "", input.color, inline="0", group = "Moving Average")
ma_len = input (10, title = "MA Length", group = "Moving Average")
// Plot
i_plot_style = input(PS1, "Plot style", input.string, options=[PS1,PS2], group = "Plot")
i_single_color = input(false, "Use single color", input.bool, inline="0", group = "Plot")
i_default_color = input(color.gray, "", input.color, inline="0", group = "Plot")
price_enable = input(false, "Show value of volume (volume * price)", tooltip="This is an estimate", group = "Plot")
src = input(ohlc4, title="Source (value used for calculation)", group = "Plot")
height = input(100, "Height in % (for overlay on chart)", minval=0, maxval=100, step=5, tooltip = "How to: (Settings) set 'Bottom Margin' to 0 -> (Chart) Indicator name -> ●●● 'More' -> 'Move To' main pane -> 'Pin To Scale' -> 'No scale (Full Screen)' -> (Indicator Settings) -> Change Height in %'", group = "Plot")
// Variables
var int plot_style = i_plot_style == PS1 ? plot.style_columns : plot.style_histogram
var color sym1_color = i_single_color ? i_default_color : i_sym1_color
var color sym2_color = i_single_color ? i_default_color : i_sym2_color
var color sym3_color = i_single_color ? i_default_color : i_sym3_color
var color sym4_color = i_single_color ? i_default_color : i_sym4_color
var color sym5_color = i_single_color ? i_default_color : i_sym5_color
var color sym6_color = i_single_color ? i_default_color : i_sym6_color
var color sym7_color = i_single_color ? i_default_color : i_sym7_color
var color sym8_color = i_single_color ? i_default_color : i_sym8_color
var color sym9_color = i_single_color ? i_default_color : i_sym9_color
var color sym10_color = i_single_color ? i_default_color : i_sym10_color
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
var color chart_color = i_single_color ? i_default_color : i_chart_color
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Functions
value = price_enable ? volume*src : volume
f_volume(_ticker) => security(_ticker, timeframe.period, value)
// Calculations
v1 = i_sym1 ? f_volume(i_sym1_ticker) : 0
v2 = v1 + (i_sym2 ? f_volume(i_sym2_ticker) : 0)
v3 = v2 + (i_sym3 ? f_volume(i_sym3_ticker) : 0)
v4 = v3 + (i_sym4 ? f_volume(i_sym4_ticker) : 0)
v5 = v4 + (i_sym5 ? f_volume(i_sym5_ticker) : 0)
v6 = v5 + (i_sym6 ? f_volume(i_sym6_ticker) : 0)
v7 = v6 + (i_sym7 ? f_volume(i_sym7_ticker) : 0)
v8 = v7 + (i_sym8 ? f_volume(i_sym8_ticker) : 0)
v9 = v8 + (i_sym9 ? f_volume(i_sym9_ticker) : 0)
v10 = v9 + (i_sym10 ? f_volume(i_sym10_ticker) : 0)
if i_single_color
v1 := na, v2 := na, v3 := na, v4 := na, v5 := na, v6 := na, v7 := na, v8 := na, v9 := na
// Plots
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
onchart_plot=(volume, style=plot_style, color=chart_color, linewidth=2, editable=false) // This line makes the indicator to only use the ticker from the chart //
//?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
(v10, style=plot_style, color=sym10_color, linewidth=2, editable=false)
(v9 , style=plot_style, color=sym9_color, linewidth=2, editable=false)
(v8 , style=plot_style, color=sym8_color, linewidth=2, editable=false)
(v7 , style=plot_style, color=sym7_color, linewidth=2, editable=false)
(v6 , style=plot_style, color=sym6_color, linewidth=2, editable=false)
(v5 , style=plot_style, color=sym5_color, linewidth=2, editable=false)
(v4 , style=plot_style, color=sym4_color, linewidth=2, editable=false)
(v3 , style=plot_style, color=sym3_color, linewidth=2, editable=false)
(v2 , style=plot_style, color=sym2_color, linewidth=2, editable=false)
(v1 , style=plot_style, color=sym1_color, linewidth=2, editable=false)
//?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
chart_plot = onchart_ticker ? onchart_plot : ((((((everything between lines of question marks)))))) // The same 'if statement' as used under '// Functions' //
Plot => plot(chart_plot)
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
plot(showMA ? sma(v10, ma_len) : na, style = plot.style_line, color = MAcolor, linewidth=2, title = "Volume MA", editable=false)
plot(height==100 ? na : (100.0/height)*v10, "blank", na, editable=false)
Aucun commentaire:
Enregistrer un commentaire