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)
Hey I am working an an automated strategy and hoping to become an Elite member on this site should the strategy work.
I am wondering if it is possible to write a piece of code that is a profit target like order that turns into a trailing stop should the price of the instrument meet the profit target. What I hope to do with this is maximize the profitability of each position. I have done some back tests and found that sometimes the price continues to fall after the profit target is met and the position is closed.
In other words instead of having the activated profit target close the position, it turns into a trailing stop where the initial profit target number becomes the top of the trailing stop.
Currently I have this code and I hope that its possible to simply switch the profit target line with the described action.
Broker: TD Ameritrade (soon to be Schwab) & NinjaTrader
Trading: The indexes, ES, YM, NQ & RTY
Posts: 171 since Aug 2012
Thanks Given: 216
Thanks Received: 157
I'm not sure if I remember the correct combination but I believe that the SetStopLoss and the SetTrailingStop can't be used at the same time and I think that's what you're really wanting to do.
What you can do is to use code to inspect the price, if the target is reached, then change your trailing stop variable value to the target - x ticks (for a long) so it doesn't close immediately when hitting the target. Then on each tick update, check if the price hits the stop and exit your position. You will not be able to do this in the strategy back tester since it only triggers the on bar update at the close of the bar not on each tick, but you'll get a close approximation if your time frame or tick count is low.