Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Needs help to figure out what's wrong with GetAtmStrategyRealizedProfitLoss

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

    Needs help to figure out what's wrong with GetAtmStrategyRealizedProfitLoss

    I created a strategy to place orders with the AtmStrategyCreate() method. So far everything works perfectly except when comes the time to record the realised PnL. Most of the time the PnL returned by the GetAtmStrategyRealizedProfitLoss() method is exact but in some cases it is not. It returns 0 as PnL and can't figure out why.

    Here is the portion of the code i use in the OnBarUpdate event. Attached to this comment, there are two screen captures. One shows the Tab order in Ninja showing a buy order with a small profit and the results returned by the GetAtmStrategyRealizedProfitLoss command in the output window. The problem occurs when i close the trade manually by pressing the Close button with the middle mouse button. Any idea wha's going on?

    Code:
    #region MonitorOrderStatus
    //-
    if (orderId.Length > 0)
    {
    
    string[] status = GetAtmStrategyEntryOrderStatus(orderId);
    
    if (status.GetLength(0) > 0)
    {
    if (status[2] == "Filled") {
    IsTradeFilled = true;
    IsStopReadyToMove = true;
    countOnBarUpdateSinceTradeFilled = -1;
    }
    // If the order state is terminal, reset the order id value
    if (status[2] == "Filled" || status[2] == "Cancelled" || status[2] == "Rejected")
    orderId = string.Empty;
    }
    }
    else if (atmStrategyId.Length > 0 && GetAtmStrategyMarketPosition(atmStrategyId) == Cbi.MarketPosition.Flat)
    {
    // when the trade is over, record the PnL
    PnL_atmStrategy = GetAtmStrategyRealizedProfitLoss( atmStrategyId );
    Print("PnL_atmStrategy read: " + PnL_atmStrategy + " at bar " + CurrentBar);
    // reset the strategy id
    atmStrategyId = string.Empty;
    }
    //-
    #endregion
    Attached Files

    #2
    Hi, thanks for posting.

    GetAtmStrategyRealizedProfitLoss will only report a PnL if the stop or target is filled. NinjaScript strategies were not designed to work with manual trading from chart trader, so if that is a required action the realized PnL will need to be calculated using an Addon-style Account object to detect when trades open and close through OnExecutionUpdate, see here for example documentation:

    https://ninjatrader.com/support/help...ount_class.htm

    Kind regards,
    -ChrisL

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Mindset, 04-21-2026, 06:46 AM
    0 responses
    88 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    134 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    68 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    119 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    67 views
    0 likes
    Last Post PaulMohn  
    Working...
    X