Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy PNL update

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

    Strategy PNL update

    I am working on a strategy and adding fixed text for account daily profit and Strategy daily profit, on the account profit


    #region Method-OnAccountItemUpdate

    protected override void OnAccountItemUpdate(Cbi.Account account, Cbi.AccountItem accountItem, double value)
    {
    // Updated Account P&L
    AccountRealizedPL = account.Get(AccountItem.RealizedProfitLoss, Currency.UsDollar);
    AccountUnrealizedPL = account.Get(AccountItem.UnrealizedProfitLoss, Currency.UsDollar);
    DailyAccountPNL=Math.Round(AccountRealizedPL+Accou ntUnrealizedPL,2);
    Draw.TextFixed(this, "DailyAcctPNL","\n\n\n\n\t\t" + DailyAccountPNL , TextPosition.TopLeft, Brushes.Green, new SimpleFont ("Arial",14), Brushes.Transparent, Brushes.Green, 0) }

    #endregion

    On the first account profit, it updates correctly by using the OnAccountItemUpdate method however for the strategy daily profit I cannot get to update correctly, it only updates when the candle closes.


    protected override void OnPositionUpdate(Cbi.Position position, double averagePrice, int quantity, Cbi.MarketPosition marketPosition)
    {
    OpenedTrades=quantity;
    DailyStrategyPNL=SystemPerformance.AllTrades.Trade sPerformance.Currency.CumProfit-PriorTradesCumProfit+Position.GetUnrealizedProfitL oss(PerformanceUnit.Currency, Close[0]);
    Draw.TextFixed(this, "DailyStratPNL","\n\n\n\t\t" + DailyStrategyPNL , TextPosition.TopLeft, Brushes.Green, new SimpleFont ("Arial",14), Brushes.Transparent, Brushes.Green, 0); }


    I tried onbarupdate and onpositionupdate and none of them updated correctly on each price change as the account does. what am I doing wrong?

    Thanks, Marcelo



    #2
    Hello Marcelo,

    Thanks for your question.

    OnPositionUpdate will change whenever the strategy position state changes. Close[0] will update depending on the Calculate m,ode of the strategy. If you set Calculate to OnPriceChange, Close[0] will update with erach price change.

    I would recommend using OnBarUpdate to call your drawing code when using Calculate.OnPriceChange so Close[0] updates with each price change and your drawing object does as well.

    It will also be helpful to use debugging prints while you are testing. You will be able to observe how often OnPositionUpdate gets called, if Close[0] is updating as you expect, and if your drawing method is being called as you intend.

    Please let me know if I can be of further assistance.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, Today, 05:17 AM
    0 responses
    52 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    130 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    70 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    43 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    48 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X