Import Forex Volume from 5 biggest FX Brokers (single/combined) 
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// I typically use Forex.com for FX, which doesn't show volume. This indicator allows user to import Volume from a range of FX brokers that DO show volume
// Either pick a broker to draw from, or combine the reported volumes from all four brokers: "FXCM", "Currency.com", "OANDA", "GLOBALPRIME"
// Thank you @theEccentricTrader for the idea of pulling volume feed from other brokers 
// © twingall

//@version=5
indicator("Import Total FX Volume from Other Brokers", shorttitle = "Import FX Volume")
showAll = input.bool(true, "Show Volume from Multiple Brokers", group = "multiple brokers")
show3 = input.bool(false, "//(Only FXCM, Pepperstone & Oanda)", group = "multiple brokers", tooltip = "Only applies if the top checkbox is toggled ON\n\nLonger volume history for these three brokers=> start date for plotting is June 2012 as opposed to Oct 2019")
brokerPrefix = input.string("FXCM", "broker to import from", group="show only one broker's volume", options = ["FXCM","EIGHTCAP","PEPPERSTONE" , "Currency.com", "OANDA"], tooltip = "Only applies if the top checkbox is toggled OFF\n\nIn descending order of volume size")
showFutVol = input.bool(true, "show only Futures Mkts Volume", group = "Futures markets Volume", tooltip = "OVERRIDES ALL OF THE ABOVE\n\nShow volume from Futures market: i.e. if Eur/Usd chart, shows volume from 6E1! continuous futures contract (CME)\n\nWorking for EurUsd, GbpUsd, AudUsd, NzdUsd, UsdChf, UsdJpy\n\nIf USD is the first part of the currency pair, volume from inverse of the futures chart will be shown (i.e. Usd/Cad =>> volume from 1/6C1!)")
volBullCol = input.color(color.green, "Bull bar color:", group = "formatting", inline ='1')
volBearCol = input.color(color.red, "Bear bar color:", group = "formatting", inline ='1')
showTable = input.bool(true, "show Table", group = "formatting", inline ='2')
titleCellCol = input.color( color.orange, "|| Title cell:", group = "formatting", inline ='2')
valCellCol = input.color( color.yellow, "value cell:", group = "formatting", inline ='2')
txtSize = input.string(size.normal, "\\Table Text Size", group = "formatting", inline ='3', options = [ size.auto, size.tiny, size.small, size.normal, size.large, size.huge])
tablePos = input.string(position.top_right, "| Table Pos:" , group = "formatting", inline ='3', options =[position.top_right,position.middle_right, position.bottom_right,position.top_left, position.top_center,  position.middle_left, position.middle_center,  position.bottom_left, position.bottom_center])
string prefix = switch brokerPrefix
    "FXCM" => "FX"
    "EIGHTCAP" => "EIGHTCAP"
    "PEPPERSTONE" => "PEPPERSTONE"
    "Currency.com" => "CURRENCYCOM"
    "OANDA" => "OANDA"
///// ~~ FUTURES VOLUME ~~ //
modFutTicker = syminfo.ticker =="EURUSD"? "6E1!":
             syminfo.ticker =="GBPUSD"? "6B1!": 
             syminfo.ticker =="AUDUSD"? "6A1!": 
             syminfo.ticker =="NZDUSD"? "6N1!": 
             syminfo.ticker =="USDJPY"? "1/6J1!": //inverted because USD is the numerator in Usd/Jpy
             syminfo.ticker =="USDCHF"? "1/6S1!": //inverted because USD is the numerator
             syminfo.ticker =="USDCAD"? "1/6C1!": //inverted because USD is the numerator
             //~~ crosses ~~
                //Aud
             syminfo.ticker =="AUDCAD"?"6A1!/6C1!":
             syminfo.ticker =="AUDCHF"?"6A1!/6S1!":
             syminfo.ticker =="AUDJPY"?"6A1!/6J1!":
             syminfo.ticker =="AUDNZD"?"6A1!/6N1!":
             syminfo.ticker =="EURAUD"?"6E1!/6A1!":
             syminfo.ticker =="GBPAUD"?"6B1!/6A1!":
                //+Cad
             syminfo.ticker =="CADCHF"?"6C1!/6S1!":
             syminfo.ticker =="CADJPY"?"6C1!/6J1!":
             syminfo.ticker =="EURCAD"?"6E1!/6C1!":
             syminfo.ticker =="GBPCAD"?"6B1!/6C1!":
             syminfo.ticker =="NZDCAD"?"6N1!/6C1!":
                //+Chf
             syminfo.ticker =="CHFJPY"?"6S1!/6J1!":
             syminfo.ticker =="EURCHF"?"6E1!/6S1!":
             syminfo.ticker =="GBPCHF"?"6B1!/6S1!":
             syminfo.ticker =="NZDCHF"?"6N1!/6S1!":
                //+Eur
             syminfo.ticker =="EURGBP"?"6E1!/6B1!":
             syminfo.ticker =="EURJPY"?"6E1!/6J1!":
             syminfo.ticker =="EURNZD"?"6E1!/6N1!":
                //+Gbp
             syminfo.ticker =="GBPJPY"?"6B1!/6J1!":
             syminfo.ticker =="GBPNZD"?"6B1!/6N1!":
                //+Nzd
             syminfo.ticker =="NZDJPY"?"6N1!/6J1!":
                //(Jpy: see above)
             "Input_Futures_Paired_Mkt_into_Script!"
//////
ModifiedTicker =showFutVol?modFutTicker: prefix + ":" +syminfo.ticker 
importedVolume = request.security(ModifiedTicker, timeframe.period, volume)

var cumVol = 0.
cumVol += nz(importedVolume)
if barstate.islast and cumVol == 0
    runtime.error("No volume is provided by the data vendor.")
_chg = ta.change(close)  
_sign = _chg ==0?+1:_chg
nv = math.sign(_sign) * importedVolume
isBull = math.sign(nv)>=1?true:false
vol =isBull?nv:-nv
MA_single = ta.sma(vol,100)
plot(not showAll or (showAll and showFutVol)?vol:na, color=isBull?volBullCol:volBearCol, title="NV", style =plot.style_columns)

    //combined total volume from several brokers:
st5 = time > timestamp("30 Sept 2019")
st3 = time >timestamp("04 Jun 2012")
st_cond = showAll?(show3?st3:st5):false
impVol1 =request.security("FX" + ":" +syminfo.ticker , timeframe.period, volume)
impVol2 =request.security("EIGHTCAP" + ":" +syminfo.ticker , timeframe.period, volume)
impVol3 =request.security("PEPPERSTONE" + ":" +syminfo.ticker , timeframe.period, volume)
impVol4 =request.security("CURRENCYCOM" + ":" +syminfo.ticker , timeframe.period, volume)
impVol5=request.security("OANDA" + ":" +syminfo.ticker , timeframe.period, volume)
inpVolTot = show3? impVol1+impVol3+impVol5: impVol1+impVol2+impVol3+impVol4+impVol5

var cumVolTot = 0.
cumVolTot += nz(inpVolTot )
if barstate.islast and cumVolTot == 0 
    runtime.error("No volume is provided by the data vendor.")

_chgTot = ta.change(close)  
_signTot = _chgTot ==0?+1:_chgTot
nvTot = math.sign(_signTot) * (inpVolTot )
isBullTot = math.sign(nvTot)>=1?true:false
volTot =isBullTot?nvTot:-nvTot
MA_multi = ta.sma(volTot, 104)
plot(st_cond and not showFutVol?volTot:na, color=isBullTot?volBullCol:volBearCol, title="VolTot", style =plot.style_columns)

    //display Table
string brokerStr = showFutVol?modFutTicker: (showAll?(show3?"FX & Pepp & Oanda":"All Five"):prefix)
MA_broker = math.round((showAll?MA_multi:MA_single)/1000)
string Title = showFutVol?"Futures Volume":"Brokers"

var Table = table.new(tablePos, columns = 5, rows = 5, bgcolor = titleCellCol, border_width = 1)
if barstate.islast and showTable
    table.cell(Table, 0, 0, Title, bgcolor = titleCellCol, text_size =txtSize)
    table.cell(Table, 0, 1, str.tostring(brokerStr),bgcolor = valCellCol, text_size =txtSize)
if barstate.islast and showTable and not showFutVol
    table.cell(Table, 1, 0, "SMA 100", text_size =txtSize)
    table.cell(Table, 1, 1, str.tostring(MA_broker) + " K",bgcolor = valCellCol, text_size =txtSize)