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

Displaying Profit and Loss When Having Multiple Exit Types?

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

    Displaying Profit and Loss When Having Multiple Exit Types?

    I have a strategy that has the same entry for both trades but has different exits coded for each exit. I have my system set up to account for my wins, losses, and PnL. Is there an extra function where I could have Win, Loss, PnL for trade 1 and trade 2 exits?

    This could be very beneficial so I can run through market replay quicker while testing my strategies. If anyone is familiar with any code for this, it would be greatly appreciated. Thanks!

    #2
    Hello durdcash,

    Thank you for your post.

    It is possible to track the PnL for a specific exit by using a collection in the SystemPerfomance object. You could loop through the trades in the collection to find trades with a specific exit name, and then track the PnL in a variable based on the exit name.

    I created an example by modifying the SampleOnOrderUpdate reference sample. It adds the following variables:
    private int tradeCount;
    private double stopPnL;
    private double targetPnL;​

    In lines 105-121 of OnBarUpdate() I added the following:
    Code:
    // keeping track of tradeCount so that the following block of code will only be processed when a new trade is added to the collection
    if (SystemPerformance.AllTrades.Count > tradeCount)
    {
    tradeCount = SystemPerformance.AllTrades.Count;
    foreach (Trade myTrade in SystemPerformance.AllTrades)
    {
    if (myTrade.Exit.Name == "MyStop")
    {
    stopPnL += myTrade.ProfitCurrency;
    }
    if (myTrade.Exit.Name == "MyTarget")
    {
    targetPnL += myTrade.ProfitCurrency;
    }
    }
    Print(String.Format("The total number of trades is: {0} | stopPnL: {1} | targetPnL: {2}", tradeCount, stopPnL, targetPnL));
    }
    What this does is checks if the total count of trades in the SystemPerformance.AllTrades collection has increased, and if so it updates the tradeCount. It then loops through all trades and checks for the exit name to be either "MyStop" or "MyTarget." Based on the exit name, it adds the ProfitCurrency to either stopPnL or targetPnL and finally it prints the total tradeCount as well as the values for stopPnL and targetPnL.

    Here is the example that you may download:
    ModifiedOnOrderUpdatePnL_NT8.zip

    Please let me know if I may be of further assistance.

    Emily C.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by mintos, 04-02-2024, 08:22 PM
    4 responses
    29 views
    0 likes
    Last Post mintos
    by mintos
     
    Started by Felix Reichert, 04-26-2024, 02:12 PM
    10 responses
    69 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by PaulMohn, 04-24-2024, 03:49 AM
    4 responses
    36 views
    0 likes
    Last Post PaulMohn  
    Started by lightsun47, Today, 11:37 AM
    1 response
    9 views
    0 likes
    Last Post NinjaTrader_Zachary  
    Started by vitaly_p, Yesterday, 05:09 PM
    4 responses
    36 views
    0 likes
    Last Post vitaly_p  
    Working...
    X