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

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
    Chris L.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CortexZenUSA, Today, 12:53 AM
    0 responses
    1 view
    0 likes
    Last Post CortexZenUSA  
    Started by CortexZenUSA, Today, 12:46 AM
    0 responses
    1 view
    0 likes
    Last Post CortexZenUSA  
    Started by usazencortex, Today, 12:43 AM
    0 responses
    5 views
    0 likes
    Last Post usazencortex  
    Started by sidlercom80, 10-28-2023, 08:49 AM
    168 responses
    2,265 views
    0 likes
    Last Post sidlercom80  
    Started by Barry Milan, Yesterday, 10:35 PM
    3 responses
    11 views
    0 likes
    Last Post NinjaTrader_Manfred  
    Working...
    X