Skip to content

strategy.account_currency returns the symbol's quote currency, and two common uses do not compile #227

Closed

Description

@letiep97

Summary

strategy.account_currency is generated as syminfo_.currency, so on a USDT-quoted symbol with strategy(currency=currency.USD) it reads USDT instead of USD. Comparing it with a currency.* constant, or concatenating it into a string, produces C++ that does not compile.

Versions

pineforge-codegen 1.6.1, pineforge-engine 1.6.1 (693fd9e6), Apple clang 17

Reproduction

  1. Wrong value (compiles, fails at run time on BTCUSDT):
//@version=6
strategy('Account currency', currency=currency.USD)
if barstate.islast and strategy.account_currency != 'USD'
    runtime.error('account currency is not USD')
plot(close)

PineForge stops with account currency is not USD. On TradingView the account currency is the currency argument (USD), so no error is raised.

  1. Comparison with a constant does not build:
//@version=6
strategy('Account currency', currency=currency.USD)
if strategy.account_currency != currency.USD
    runtime.error('USD account required')

clang: no matching conversion for static_cast from 'std::string' to 'double' (twice) and no matching function for call to 'is_na'.

  1. Concatenation does not build:
//@version=6
strategy('Account currency', currency=currency.USD)
label_text = 'account ' + strategy.account_currency
plot(close)

clang: no matching function for call to 'to_string' with a std::string argument.

Expected

strategy.account_currency yields the strategy's account currency, and works with currency.* constants and string operations like any other string.

Activity

  1. letiep97 commented on Oct 20, 2026

    @letiep97
    Author

    Still reproduces on main (aebad8c). There are two separate causes, in case it helps:

    1. Value. codegen/visit_expr.py#L811-L812 lowers strategy.account_currency to syminfo_.currency. On TradingView it is the strategy(currency=...) argument, and the symbol's currency only when that argument is currency.NONE. The declaration is already read in codegen/capabilities.py, so the lowering could emit that string when it isn't NONE.
    2. Build errors. The analyzer types both strategy.account_currency and currency.* as string (analyzer/base.py#L6806, #L6902), but the C++ type inference _infer_type has a case for neither (codegen/types.py#L4042). So != takes the numeric na-aware comparison (static_cast<double> on a std::string), and + wraps the operand in std::to_string (codegen/visit_expr.py#L1602-L1611). Comparing with the literal 'USD' builds fine, which fits. Returning std::string for both in _infer_type should fix the two build failures.
  2. luisleo526 commented on Oct 25, 2026

    @luisleo526
    Contributor

    Thank you for the report. We checked the v1.7.0 source and the cause of all three cases is still there: strategy.account_currency still returns the symbol's quote currency instead of the strategy's currency argument, and the comparison with a currency.* constant and the string concatenation still fail to build. This is not fixed in v1.7.0. A fix is being written now: the value will follow the currency argument of strategy() (the symbol's currency when it is omitted or currency.NONE), and both forms will build. We expect to open the pull request on 2026-10-26. This change does not add currency conversion; it only corrects the value.

  3. added a commit that references this issue on Oct 25, 2026
  4. luisleo526 commented on Oct 25, 2026

    @luisleo526
    Contributor

    Fixed by #250, merged to main: strategy.account_currency now follows the currency argument of strategy() (the symbol's currency when it is omitted or currency.NONE), and the comparison with a currency.* constant and the string concatenation both build. It will ship in the next codegen release; I will note the version here when it is published. Thank you for the clear cases.

  5. luisleo526 commented on Oct 25, 2026

    @luisleo526
    Contributor

    Update: this fix ships in the next codegen release, 1.8.0 (paired with the engine; I will confirm here when it is published).

  6. letiep97 commented on Oct 28, 2026

    @letiep97
    Author

    Verified on main (11b5ca5, with engine 1.6.1): with currency=currency.USD on a symbol whose quote currency is not USD, strategy.account_currency now reads USD, and the comparison and concatenation cases both build and run. Thank you for the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions