Fix request.security math reducers and flat avg price#39
Merged
Conversation
A rolling math reducer (math.sum) inside a request.security() expression lowered to `0.0 /* unsupported: math.sum */`, so the whole security silently returned 0. _build_security_expr routed the math.* node to the scalar-math inline lowering (_build_security_math_call) before the TA-site lookup, discarding the math::Sum helper the security machinery had already precomputed into a committed _secval_*. Return that committed _secval_ when a math.* call inside a security expression is a registered rolling TA site. Scalar math (abs/round/min/max/...) is not a TA site and still lowers inline. Adds tests/test_security_math_reducer.py locking both directions. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013tuvZmenDcKuPu8LVqfqag
Pine returns na for strategy.position_avg_price when the position is flat (position_size == 0). The codegen mapped it directly to the engine field position_entry_price_, which is 0.0 when flat, silently defeating the common `na(strategy.position_avg_price)` flat/in-position guard idiom (0.0 is not na) — exit/SL/TP logic then ran against avg=0 (e.g. a 0-priced stop firing immediately). Emit the field guarded by the flat test, matching the engine's own avg-price accessor which already returns na when FLAT: (signed_position_size() == 0.0 ? na<double>() : position_entry_price_). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013tuvZmenDcKuPu8LVqfqag
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Validation