Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 GLFX005, Today, 03:23 AM
    0 responses
    1 view
    0 likes
    Last Post GLFX005
    by GLFX005
     
    Started by XXtrader, Yesterday, 11:30 PM
    2 responses
    11 views
    0 likes
    Last Post XXtrader  
    Started by Waxavi, Today, 02:10 AM
    0 responses
    6 views
    0 likes
    Last Post Waxavi
    by Waxavi
     
    Started by TradeForge, Today, 02:09 AM
    0 responses
    14 views
    0 likes
    Last Post TradeForge  
    Started by Waxavi, Today, 02:00 AM
    0 responses
    3 views
    0 likes
    Last Post Waxavi
    by Waxavi
     
    Working...
    X