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 NullPointStrategies, Today, 05:17 AM
    0 responses
    44 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    125 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    65 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    42 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    46 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X