'How i can call request.security on ta.sar (pinescript/TradingView)?

I need to call a ta.sar in heikin ashi security, that gives me a buy/sell signal to execute in japanise candles values.

//SAR security example (not working)
start = input(0.02)
increment = input(0.02)
maximum = input(0.2, "Max Value")
out = (request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, close) ta.sar(start, increment, maximum))
sarColor = out < low ? color.lime : color.red
plot(out, "ParabolicSAR", style=plot.style_cross, color=sarColor)


Solution 1:[1]

The request.security() function 3rd paramter is the expression you wish to return. In you case, you're requesting Close, while you want to get sar. You also use an extra parenthesis you can delete from your code:

//@version=5
indicator(title="Money Flow Index", shorttitle="MFI", format=format.price, precision=2, timeframe="", timeframe_gaps=true)
start = input(0.02)
increment = input(0.02)
maximum = input(0.2, "Max Value")
out = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, ta.sar(start, increment, maximum))
sarColor = out < low ? color.lime : color.red
plot(out, "ParabolicSAR", style=plot.style_cross, color=sarColor)

You can get both Close and sar if you wish using Close at a later time:

//@version=5
indicator(title="Money Flow Index", shorttitle="MFI", format=format.price, precision=2, timeframe="", timeframe_gaps=true)
start = input(0.02)
increment = input(0.02)
maximum = input(0.2, "Max Value")
[_close, out] = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, [close, ta.sar(start, increment, maximum)])
sarColor = out < low ? color.lime : color.red
plot(out, "ParabolicSAR", style=plot.style_cross, color=sarColor)
plot(_close)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 mr_statler