Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Getting Account Positions in Playback vs. Optimizer

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Getting Account Positions in Playback vs. Optimizer


    Question: Will routines such as:

    Position.AveragePrice
    Position.GetUnrealizedProfitLoss(PerformanceUnit.C urrency, Close[0])

    return the correct value within the Strategy Analyzer?

    I've written some code utilizing these procedures. They work as expected during Playback mode, returning the correct value. However, when the same code is in the Strategy Analyzer, it appears these procedures return zero values.

    Would this be the current behavior? Thanks,













    #2
    Hello timmbbo,

    Those should work in the analyzer as well, Position is the property which represents the strategies virtual position which is what would be used in the analyzer. Are you certain that the methods are being called while the position is open? Just as an example, if you are running the strategy OnPriceChange in playback you will see that updated intrabar where in a backtest it would be on bar close which could mean the position is already closed when that code gets executed. That would be one sitiation where you may see it work in playback but not in a backtest.

    I would likely need more specific details on how you have used those in your code and also what Calculate setting you are using in realtime to know why that may be 0.

    Just as an example this code prints values while used in the analyzer:

    Code:
    protected override void OnBarUpdate()
    {
        if(Position.MarketPosition == MarketPosition.Flat) EnterLong();
    
        Print(Position.AveragePrice + " " + Position.GetUnrealizedProfitLoss(PerformanceUnit.C urrency));
    }

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    60 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    39 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    21 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    23 views
    0 likes
    Last Post TheRealMorford  
    Started by Mindset, 02-28-2026, 06:16 AM
    0 responses
    51 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Working...
    X