Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
I'm trying to code a strategy that stops trading that day if it loses too much that is backtester compatible. I found this thread over at [AUTOLINK]NinjaTrader[/AUTOLINK]'s support forum, but it's still wrong. I think I saw Big Mike in that thread over there as well, so I figured this would be the best place to ask.
Here's my code, but it doesn't seem to be working. Can anyone help?
Note: I'm speaking specifically about the backtester, the problem is that it acts as if the strategy ran straight through the entire backtesting period. So your cumulated profits are always rising, hopefully, and you can't find out what it is for the day.
I know it is possible to stop a strategy when a predefined profit/loss is hit, but is it possible to have NT flatten everything when a total profit or loss target is hit when running a strategy on two or more instruments? For example, when running two strategies and net profit for the two strategies hits $1000 or loss hits $400, all strategies are stopped.
You have to first tackle the task of getting the strategies to speak to one another. There are a lot of solutions to this, but the most promising looks to be this. Once you get that, you'd be looking to do the same thing I am asking. As far as my question goes, I'm mainly looking at it for backtesting purposes, I can make it work realtime quite easily, but in the backtester it totals them all over all the days, so it becomes slightly more complex.
Also, anyone know when NT7 is coming out? Is it ever?
Given that NT6.5 does keep totals of net trades across multiple instruments, hopefully NT7 may have the feature to close positions for individual instruments, groups of instruments and all instruments when specific targets for profit/loss are hit.
Here's some code I came up with from various samples to give me some peace of mind if you were to run your strategies unattended.
Nothing fancy, but it can be easily personalized with your own messages, input variables, etc.
Please test before using …
specifically this part...
Basically, you track the cumulative profit at the start of each session so that you can later eliminate it when you calculate the daily max profit/loss amounts.