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!
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!
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
NinjaTrader
Displaying Profit and Loss When Having Multiple Exit Types?
Collapse
X
-
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!Tags: None
-
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)); }
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
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by mintos, 04-02-2024, 08:22 PM
|
4 responses
29 views
0 likes
|
Last Post
by mintos
Today, 12:50 PM
|
||
Started by Felix Reichert, 04-26-2024, 02:12 PM
|
10 responses
69 views
0 likes
|
Last Post Today, 11:56 AM | ||
Started by PaulMohn, 04-24-2024, 03:49 AM
|
4 responses
36 views
0 likes
|
Last Post
by PaulMohn
Today, 11:54 AM
|
||
Started by lightsun47, Today, 11:37 AM
|
1 response
9 views
0 likes
|
Last Post Today, 11:45 AM | ||
Started by vitaly_p, Yesterday, 05:09 PM
|
4 responses
36 views
0 likes
|
Last Post
by vitaly_p
Today, 11:40 AM
|
Comment