Search code examples
pine-script-v5

ema for different currency pairs in Indicator


I am trying to write a script where I use ta.ema(close,200) function for multiple currency pairs eg. If close > ema for AUDUSD it should give a "Bullish" signal and if close < ema for USDJPY it should give a "Bearish" signal ect ect I identified 14 currency pairs. Is it possible to have a ema for each pair ? I tried the following code but I get just one result for all the pairs

EMA_LEN = input(200)

ticker01 = input.symbol("AUDUSD", "Ticker")           
// = input.symbol("ADAUSD", title="", group="Portfolio Asset #1", inline="Ticker 1")
ticker01EMA = request.security(ticker01 , ta.ema(close,EMA_LEN) 
//ta.ema(close,EMA_LEN) 
ticker01TREND = close > ticker01EMA ? "Bullish" : close < ticker01EMA ? "Bearish" : "Neutral"  

Solution

  • example with two pairs

    EMA_LEN = input(200)
    
    ticker01 = input.symbol("AUDUSD", "Ticker")
    ticker01EMA = request.security(ticker01 , timeframe.period, ta.ema(close,EMA_LEN))
    ticker01TREND = close > ticker01EMA ? "Bullish" : close < ticker01EMA ? "Bearish" : "Neutral"
    ticker02 = input.symbol("EURUSD", "Ticker")
    ticker02EMA = request.security(ticker02 , timeframe.period, ta.ema(close,EMA_LEN))
    ticker02TREND = close > ticker02EMA ? "Bullish" : close < ticker02EMA ? "Bearish" : "Neutral"
    
    
    var table tbl = table.new(position.top_right, 3, 40)// 40 is max call request security
    
    table.cell(tbl, 0,0, ticker01TREND)
    table.cell(tbl, 1,0, ticker01)
    table.cell(tbl, 0,1, ticker02TREND)
    table.cell(tbl, 1,1, ticker02)