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)
Code for Entering Orders with Profit Target and Stop Loss orders
I first did some diligence to see if there were any threads in the forum that could answer my question. Did not find any but I'll apologize in advance just in case I missed them.
I'm coding a strategy that places orders when a signal is triggered (not important how) and encountering an issue when I place my buy or sell limit orders using the EnterLongLimit() or EnterShortLimit() functions of Ninja, I saw that the software does not place the accompanying profit target or stop loss orders for my order that was just entered.
According to the Help guide, using the Managed Orders approach the above should occur automatically, however it is not.
I tried including the profit target and stop loss code in the Initialize section of the strategy (as per the manual) and when that didn't work, I moved them to the OnBarUpdate() section and that didn't work either.
Checked the Log tab in the Control Center and there are no entries. My entry orders are firing but they are not getting close out. The only thing that is closing them out is the system's Exit on Close automatic routines.
Hoping that someone can show how to resolve this issue or better yet send a code sample that works.
Thanks in advance,
Al G
Can you help answer these questions from other members on NexusFi?
Check your signal names for your entries and you stop/profit target. If they don't match then it won't work. Assign a variable to your signal name, then use the same variable in your entry orders and your stop loss and profit targets as well.
I also like to have my signal names be unique so they don't collide with potentially other orders, so I append CurrentBar. This is important if you are making multiple entries but you don't need it if you're only in one entry at a time.
Good suggestion on using the CurrentBar as the signal name! I tried it and it works!
However in my code I am making calls to the SetProfitTarget and SetStopLoss methods RIGHT BEFORE placing my entry order because I want to make sure the CurrentBar value is updated.
In other words if I move the statements into the Initialize() section, it doesn't appear that it will work since Initialize is only invoked once. Is this correct?
What would you suggest is the proper code implementation for this?