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,
Last edited by aguison; June 23rd, 2013 at 07:26 PM.
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.
Last edited by shodson; June 24th, 2013 at 12:48 PM.
The following user says Thank You to shodson for this post: