• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

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 Induna, Today, 08:44 AM
    0 responses
    1 view
    0 likes
    Last Post Induna
    by Induna
     
    Started by TangoTX, Today, 08:36 AM
    0 responses
    0 views
    0 likes
    Last Post TangoTX
    by TangoTX
     
    Started by abdullah, 11-15-2017, 08:44 PM
    11 responses
    822 views
    0 likes
    Last Post NinjaTrader_Kate  
    Started by brunoviveiros, Today, 04:31 AM
    3 responses
    13 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Started by foxy_rav, Today, 06:31 AM
    2 responses
    5 views
    0 likes
    Last Post foxy_rav  
    Working...
    X