Sidechair

strategy.convert_to_symbol()

Browse the reference

Converts an amount from the strategy's account currency into the symbol's currency.

Try it in the editor

strategy.convert_to_symbol(value) divides out the exchange rate used by strategy.convert_to_account, turning an amount in the account currency into the symbol's currency (syminfo.currency). With matching currencies, it returns value unchanged.

The usual job is sizing: divide the converted amount by the price to get a quantity that spends a fixed amount of account currency.

Syntax

Pine Script
strategy.convert_to_symbol(value: series int/float) -> series float

Arguments

NameTypeDefaultDescription
valueseries int/floatrequiredAn amount in the strategy's account currency to convert.

Returns

series float: The amount expressed in the symbol's currency.

Remarks

  • The conversion uses the exchange rate of the current bar.

Examples

Pine ScriptSpend 5,000 per tradeOpen in editor
//@version=6
strategy("Fixed spend", overlay = true, currency = currency.EUR)
qty = strategy.convert_to_symbol(5000) / close
if ta.crossover(ta.sma(close, 10), ta.sma(close, 30))
    strategy.entry("Long", strategy.long, qty = qty)
if ta.crossunder(ta.sma(close, 10), ta.sma(close, 30))
    strategy.close("Long")
plot(ta.sma(close, 30), "SMA 30", color.orange)
Pine ScriptSymbol currency on the chartOpen in editor
//@version=6
strategy("Symbol currency", overlay = true)
var table t = table.new(position.top_right, 1, 1)
if barstate.islast
    table.cell(t, 0, 0, "Quoted in " + syminfo.currency, text_color = color.white, bgcolor = color.blue)
plot(close, "Close", color.gray)

See also

Runs on Sidechair