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.
    JimNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by wjadevries, Today, 03:35 PM
    1 response
    7 views
    0 likes
    Last Post NinjaTrader_ChrisL  
    Started by Mykro, Today, 03:59 PM
    0 responses
    4 views
    0 likes
    Last Post Mykro
    by Mykro
     
    Started by venkateshdvk, Today, 01:34 PM
    1 response
    21 views
    0 likes
    Last Post NinjaTrader_Kate  
    Started by westofpluto, Today, 01:54 PM
    1 response
    7 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Started by zacharydw00, Today, 02:11 PM
    4 responses
    15 views
    0 likes
    Last Post zacharydw00  
    Working...
    X