![]() |
This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com
|
|||||||
| Strategy Development Support for the development of custom automated trading strategies using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Senior Member
Join Date: Mar 2009
Posts: 220
Thanks: 0
Thanked 0 times in 0 posts
|
I was trying to keep track of my profits during backtesting, however when I check my the Total Net Profit in the Strategy Analyzer Summary, it is not the same value as the Cumulative Profit which I printed using
Print("Cum Profit:" +Performance.AllTrades.TradesPerformance.Currency. CumProfit); Why is that so? |
|
|
|
|
|
#2 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
Please ensure you are printing it at the correct time and that you have Strategy Analyzer set to currency.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Senior Member
Join Date: Mar 2009
Posts: 220
Thanks: 0
Thanked 0 times in 0 posts
|
How do I set the Strategy Analyzer to currency? I put the print code on the first line of OnBarUpdate(), would that be a problem? I only check that the final values are different. Therefore shouldn't be a problem of printing at the wrong timing?
|
|
|
|
|
|
#4 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
tjendra,
You may be missing the final Exit on Close order as the backtest finishes and closes out any remaining position at that point in time. I suggest you print out Position.MarketPosition to confirm/deny this. If your final CumProfit print is from an active long/short position then you know you are missing that final closing trade in your stats. You can change the presentation method of the Strategy Analyzer in the top toolbar. There should be a drop down menu where you can select Currency.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Senior Member
Join Date: Mar 2009
Posts: 220
Thanks: 0
Thanked 0 times in 0 posts
|
My final market position is Long. How do I make it flat so the calculation is correct?
|
|
|
|
|
|
#6 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
tjendra,
You would not be able to unless you tell it to place an explicit exit before close. Whatever logic you use to place this exit will not necessarily be an exit you would like in your strategy code though.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#7 |
|
Senior Member
|
Hello Josh, I used Print("Average cumulative profit of all trades is: " + Performance.AllTrades.TradesPerformance.Currency.C umProfit); but it prints nothing even if there is already a trade in the Account Performance Tab. The value is always zero. I don't understand why. I am using a market replay to test my strategies. I already set the accounts to replay and correct chart, templates and the providers. When I generate it, it does many trades but still the in the output window is zero. Please help me on this.
|
|
|
|
|
|
#8 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,414
Thanks: 252
Thanked 978 times in 961 posts
|
luxurious_04, are you using NinjaScript strategies that call ATM's here in your testing?
http://www.ninjatrader.com/support/f...ad.php?t=19148
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#9 |
|
Senior Member
|
Yes I am using ATM templates but there is a line on the link that you give that says " Accessing all the trade data is still possible, but the set of commands to use differ from the traditional NinjaScript commands.". Now, if it still possible to access all the trade data then what would be other set of commands to use? Because I really want to access all the trade data as a trade filter to my strategy. Please give me tip or a sample code for it. It must be easy if I have a code just like the function of CLOSE button in the DOM. Just the code for disabling automatically the strategies running. If you can give me a tip or a HOT KEY for that one then it would be great. I hope.
Last edited by luxurious_04; 02-14-2011 at 06:37 PM.
|
|
|
|
|
|
#10 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
luxurious_04,
When working with ATM strategies in NinjaScript you would want to use this subset of methods: http://www.ninjatrader.com/support/h...gy_methods.htm To close out of your ATM strategy you could use this method: http://www.ninjatrader.com/support/h...ategyclose.htm For a hot key to disable strategies, there is none per se, but you can setup in the Hot Key Manager under the Globals section one for "Flatten Everything" which will stop your strategies.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#11 |
|
Senior Member
|
Flatten Everything can stop my strategies. But in the next signal it will take an order again. Is it? Anyway, please give me a sample Ninja code to automatically trigger my hot key for Flatten Everything. Thanks.
|
|
|
|
|
|
#12 |
|
Senior Member
|
Hello, anyone could help me on this. Is there a way that strategy can access another strategy? Like for example I have two strategies then the first one have a realized profit of 1130 and the other one have 1140. Now I want the first one to access the realize profit of the second strategy and get the sum of it. Or there a way I can get the sum of this two? I have attached a sample image.
Last edited by luxurious_04; 02-16-2011 at 01:13 AM.
|
|
|
|
|
|
#13 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,414
Thanks: 252
Thanked 978 times in 961 posts
|
FlattenEverything will disable your strategy, so to have it trade again, you would need to restart it first.
A hotkey for FlattenEverything can be setup in NT7's hotkey manager - http://www.ninjatrader.com/support/h...ey_manager.htm Unfortunately NinjaScript strategies would not cross communicate, so you could not access the PnL of strategy A in strategy B - a workaround could be using txt files to 'globally' store the values for reference.
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#14 |
|
Senior Member
|
Hello Bertran, please give me a hint on how to save a value from strategy to a text file or excel and also how does strategy get or query value from a text file. By the way, is there a way to add all the value recorded in a list? How? Thank you.
|
|
|
|
|
|
#15 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,414
Thanks: 252
Thanked 978 times in 961 posts
|
You can for example take a look at this reference sample - http://www.ninjatrader.com/support/f...ead.php?t=3477
Bertrand
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| summary of "strategy realized" is not equal "account performance, total net profit"" | Fragolino | Miscellaneous Support | 1 | 02-19-2009 04:12 AM |
| Cumulated Profit vs Total Net Profit? | suedeuno | Strategy Development | 3 | 01-04-2009 08:40 AM |
| What's the easiest way to get the current Net Profit/Gross Profit? | tradefaz | General Programming | 2 | 08-25-2008 10:31 PM |
| Cumulative Profit Graph | CraigC | Automated Trading | 3 | 06-20-2008 11:27 PM |
| Cumulative Profit Calculation Error | whitmark | Miscellaneous Support | 1 | 03-07-2007 04:09 AM |