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

Account Wide PNL

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

    Account Wide PNL

    I am writing this to seek some clarification with respect to the AccountItem Object.

    I am using the following to obtain the Account Wide Daily PNL:

    return (double)Account.Get(AccountItem.RealizedProfitLoss , Currency.UsDollar);
    Would it be correct to assume that this value returns to Zero When
    Bars.IsFirstBarOfSession = true
    What is the difference between AccountItem.CaseValue, AccountItem.TotalCashValue and AccountItem.SodCashValue?

    What is the difference between AccountItem.UnrealizedProfitLoss and AccountItem.RealizedProfitLoss? Is Unrealized changeable per tick as a position is open? ort is unrealized the PNL for the day until its added to the account balance?


    Thanks,

    #2
    Hello jeliner,

    Thanks for your post.

    Your live account would be reset by the broker and the timing would be broker dependant. The SIM account is reset when you restart in the next session.

    Realized would be the accumulation of closed positions. Unrealized would be any open positions and yes it will change per tick.

    You wrote, "What is the difference between AccountItem.CaseValue, AccountItem.TotalCashValue and AccountItem.SodCashValue?" On the first two, do you mean:
    AccountItem.CashValue? (If so, this would be the account value).
    AccountItem.TotalCashBalance?
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Money Management

      Your live account would be reset by the broker and the timing would be broker dependant. The SIM account is reset when you restart in the next session.
      Humm .. Ok, then I need to use a custom reset time to make sure things remain consistent. What I am hoping to do is create a strategy that will help me exit/manage the trade when I have an open position. My money management rules are too complex for the ATM.



      My money management rules are as follows:
      1. The 24 hour trading day is broken down into four sessions:
        • Trading only occurs between the time frame of the sessions
      2. Each session has its own custom session risk level and session target per market traded per session
        • Maximum Simultaneous instruments traded per session is six
        • Each market has its own independent risk and target that can differ between sessions on the same instrument
        • Per Session Target is 2 times Session Risk
      3. The sum of each instruments session Risk is totaled for what I call a Gross Total Session Risk... Example:
        • (ES Session 1 Risk) + (YM Session 1 Risk) + (GC Session 1 Risk) ... ect..
      4. The Sum of each instruments session Target is totaled for what I call a Gross Total Target.
      5. Gross Daily Risk is calculated as follows on all instruments combined:
        • ([Session1Risk]+[Session2Risk]+[Session3Risk]+[Session4Risk]) - 30%
      6. Gross Daily Target = Gross Daily Risk x 3
      7. If Gross Session Risk and Gross Session Targets are reached - trading stops
        • Since my entry into the market is always manual, Using a drawing object on the chart of each instrument to display this in real-time rather than using an excel spreadsheet to do this calculation
      8. Each Session and Each instrument has a Per Trade Risk and Per Trade Target.
        • Trade is not executed if Max Adverse Excursion is greater than per trade risk
        • Risk is calculated from the last pivot to the entry signal point.
          • Trade is not executed if Calculated risk is greater than defined risk
        • Per Trade Target is 1.5 times the per trade risk With the following exceptions:
          • If at 1.5 times risk the following conditions exist, target is increased by 0.5 times risk for each bar where:
            • Hammer remains within positive influence of the trend (this is a one of my custom indicators)
            • The directional index (another one of my custom indicators) remains greater than 55 for long or less than -55 for short.
      9. The Floor Levels
        • Each Session has a floor level that is calculated as follows..
          • Initial floor is Zero - Session Risk
          • Floor Risk increases as profit rises... Example
            • A trade results in $250 Profit... Session floor risk moves up from Zero - Session Risk to $250 - Session Risk.
          • Daily Floor risk functions in the same way as session floor risk
        • If at any time session PNL < Session Floor Risk or Daily PNL < Daily Floor risk, trading is halted for either session or day.
        • Since this is a manual entry process, A draw box will appear on each chart (red for halted trading/green for ok)
      In order for me to create an exit strategy to function like Ninja's ATM I need to be able to have access to the following:
      • Profit/Loss Per session basis per instrument
      • Profit/Loss Per session overall instruments
      • Profit/Loss Per Daily per instrument
      • Profit/Loss Per Daily overall instruments traded
      I created the following function and enumerator to get the per trade PNL
      Code:
       
      [COLOR=black]/// <summary>[/COLOR]
      [COLOR=black]/// Defines the Profit Type enumeration[/COLOR]
      [COLOR=black]/// </summary>[/COLOR]
      [COLOR=black]private enum enumProfitType[/COLOR]
      [COLOR=black]{[/COLOR]
      [COLOR=black]Currency,[/COLOR]
      [COLOR=black]Percent,[/COLOR]
      [COLOR=black]Pips,[/COLOR]
      [COLOR=black]Points,[/COLOR]
      [COLOR=black]Ticks[/COLOR]
      [COLOR=black]}[/COLOR]
       
      [COLOR=black]/// <summary>[/COLOR]
      [COLOR=black]/// Searches the Trade collection for a completed trade. Completed trades require both[/COLOR]
      [COLOR=black]/// entry and exit iOrder objects. {JEL}[/COLOR]
      [COLOR=black]/// </summary>[/COLOR]
      [COLOR=black]/// <param name="myEntryOrder">An entry order object used to ideitify the specific trade</param>[/COLOR]
      [COLOR=black]/// <param name="myProfitType">Profit type of the returned value</param>[/COLOR]
      [COLOR=black]/// <returns>Returns a double value of the PNL from a completed trade</returns>[/COLOR]
      [COLOR=black]private double getTradePNL(Order myEntryOrder, enumProfitType myProfitType)[/COLOR]
      [COLOR=black]{[/COLOR]
      [COLOR=black]double retValue = 0;[/COLOR]
      [COLOR=black]foreach (Trade thisTrade in SystemPerformance.AllTrades)[/COLOR]
      [COLOR=black]{[/COLOR]
      [COLOR=black]if (thisTrade.Entry.Order == myEntryOrder)[/COLOR]
      [COLOR=black]{[/COLOR]
      [COLOR=black]switch (myProfitType)[/COLOR]
      [COLOR=black]{[/COLOR]
      [COLOR=black]case enumProfitType.Currency:[/COLOR]
      [COLOR=black]retValue = thisTrade.ProfitCurrency;[/COLOR]
      [COLOR=black]break;[/COLOR]
      [COLOR=black]case enumProfitType.Percent:[/COLOR]
      [COLOR=black]retValue = thisTrade.ProfitPercent;[/COLOR]
      [COLOR=black]break;[/COLOR]
      [COLOR=black]case enumProfitType.Pips:[/COLOR]
      [COLOR=black]retValue = thisTrade.ProfitPips;[/COLOR]
      [COLOR=black]break;[/COLOR]
      [COLOR=black]case enumProfitType.Points:[/COLOR]
      [COLOR=black]retValue = thisTrade.ProfitPoints;[/COLOR]
      [COLOR=black]break;[/COLOR]
      [COLOR=black]case enumProfitType.Ticks:[/COLOR]
      [COLOR=black]retValue = thisTrade.ProfitTicks;[/COLOR]
      [COLOR=black]break; [/COLOR]
      [COLOR=black]}[/COLOR]
      [COLOR=black]}[/COLOR]
      [COLOR=black]}[/COLOR]
       
      [COLOR=black]return retValue;[/COLOR]
      [COLOR=black]}[/COLOR]
      In order to obtain the PNL on a daily basis across instruments I created the following:

      Code:
      [INDENT][COLOR=black][COLOR=black]/// <summary>[/COLOR]
      [COLOR=black]/// Obtains the profit/loss on a daily basis, account wide[/COLOR]
      [COLOR=black]/// </summary>[/COLOR]
      [COLOR=black]/// <returns>Returns the account wide daily PNL</returns> [/COLOR]
      [COLOR=black]private double getAccountPNL()[/COLOR]
      [COLOR=black]{[/COLOR]
      [COLOR=black]return (double)Account.Get(AccountItem.RealizedProfitLoss, Currency.UsDollar); [/COLOR]
      [COLOR=black]}[/COLOR]
      [/COLOR]
      [/INDENT]
      If the AccountItem.RealizedProfitLoss can be reset my ninja, then I need to find an alternative.



      Which leads me to the following Questions:
      1. Does the trade object span all trades executed, even for instruments on different charts?
      2. Is there another way to access an accounts balance that would be reflective of closed positions. I could use the account balance instead and do my own reset programmatically.
        • If so, which of the following would it be:
          • AccountItem.CashValue
          • AccountItem.SodCashValue
          • AccountItem.TotalCashBalance
      Thanks,
      Johnny

      Comment


        #4
        Hello jeliner,

        Thanks for your reply.

        1. The trade object would only know of trades initiated by the strategy. If the strategy placed orders on different instruments then it would know of those trades. If other strategies have placed trades, or manual trades have been placed, then no, the trade object in one strategy is not known to another and no trade object would be aware of manually placed trades.

        2. Not all items shown under AccountItem apply to each connection/broker. Please see this link for the broker information supported in each connection: http://ninjatrader.com/support/forum...ead.php?t=5474
        AccountItem.CashValue would reflect your current cash value which includes all closed trades.

        SodCashValue would only apply to a CQG connection and means "StartOfDayCashValue".

        TotalCashBalance would only apply to an IB (InterActive Broker) account.
        Paul H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by algospoke, Yesterday, 06:40 PM
        2 responses
        24 views
        0 likes
        Last Post algospoke  
        Started by ghoul, Today, 06:02 PM
        3 responses
        15 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by jeronymite, 04-12-2024, 04:26 PM
        3 responses
        46 views
        0 likes
        Last Post jeronymite  
        Started by Barry Milan, Yesterday, 10:35 PM
        7 responses
        23 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by AttiM, 02-14-2024, 05:20 PM
        10 responses
        181 views
        0 likes
        Last Post jeronymite  
        Working...
        X