Announcement
Collapse
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
Partner 728x90
Collapse
NinjaTrader
Stop loss and take profit for orders with OIF files
Collapse
X
-
Stop loss and take profit for orders with OIF files
Hi there, I'm creating orders using OIF files and have no issues creating market orders. I'm wondering how I go about setting a stop and take profit on the market order. I would prefer to apply an ATM strategy but the quantity of the order will change so that won't work.Tags: None
-
Hello spondishy,
An Atm could be applied to the entry by specifying an Atm Strategy Template name and ID.
PLACE;<ACCOUNT>;<INSTRUMENT>;<ACTION>;<QTY>;<ORDER TYPE>;[LIMIT PRICE];[STOP PRICE];<TIF>;[OCO ID];[ORDER ID];[STRATEGY];[STRATEGY ID]
https://ninjatrader.com/support/help..._files_oif.htm
The quantity can be changed by supplying that same strategy ID.
CHANGE;;;;<QUANTITY>;;<LIMIT PRICE>;<STOP PRICE>;;;<ORDER ID>;;[STRATEGY ID]
However, a market order cannot be modified. You would need to place an additional order to change the position quantity.Chelsea B.NinjaTrader Customer Service
-
Thanks for the response. Unfortunately my stop changes depending on certain parameters, so I have a moving contract size and stop. So can I do this somehow.
1) Place order for x contracts (PLACE command)
2) Change order for stop loss (CHANGE command)
3) How would I set take profit?
Or am I missing something? I don't see how ATM strategies would work.
Comment
-
OK thanks. I don't see how this can work so can you help with the OIF files as I'm getting errors.
1) I create a market order. All good:
PLACE;Sim101;MNQ SEP23;BUY;1;MARKET;;5;DAY;7c656f58-83dc-40e2-87e4-fff6ccc59c7f;7c656f58-83dc-40e2-87e4-fff6ccc59c7f;;
2) I attempt to change the stop (with a new file)
CHANGE;;;;1;;;15200;;;7c656f58-83dc-40e2-87e4-fff6ccc59c7f;;
This gives an error in the logs. Order is in a terminated state so cannot be changed. And a file in the outgoing folder with contents of REJECTED;0;0
3) What would the OIF file look like to set the target profit? ThanksLast edited by spondishy; 07-06-2023, 01:37 PM.
Comment
-
Hello spondishy,
This would be the entry market order with the ID '7c656f58-83dc-40e2-87e4-fff6ccc59c7f'. The entry market order is not a stop order and cannot be modified.
The order ID of the entry is not the order ID of any stops or targets that get submitted from an Atm Strategy.
You would need the ID of the stop order to modify that stop order.
You can get this ID from the Orders tab of the Control Center.Chelsea B.NinjaTrader Customer Service
Comment
-
Hello spondishy,
This would be without using an Atm template? (An Atm template created in the SuperDOM or Chart Trader where be where you would set a number of ticks from entry for a stop and target)
It would not be possible to specify a number of ticks for a stop order and limit order when placing these with OIF. You would need to calculate this first and supply the exact prices for the stop price and limit price.
For example:
Code:PLACE;Sim101;AAPL;BUY;1;MARKET;;;GTC;;MYORDERID1;; PLACE;Sim101;AAPL;SELL;1;STOPMARKET;;191.31;GTC;MYOCOID1;MYORDERID2;; PLACE;Sim101;AAPL;SELL;1;LIMIT;192.81;0;GTC;MYOCOID1;MYORDERID3;;
Chelsea B.NinjaTrader Customer Service
Comment
-
Thanks for the response. So I've changed my oif files and partial success. I can place a MARKET order and LIMIT and see the position and order for the limit but there is no STOPMARKET order in the orders tab. Can you look through this file for me please? It looks like your file to me.
PLACE;Sim101;MNQ SEP23;BUY;1;MARKET;;;DAY;;6ca70fb0-5d3b-48d0-96c5-438fd1c5b9a9;
PLACE;Sim101;MNQ SEP23;SELL;1;STOPMARKET;0;15195.00;DAY;MYOCI1;d9ed 9994-df5f-47ed-9935-0c26bdb466eb;;
PLACE;Sim101;MNQ SEP23;SELL;1;LIMIT;15215.00;0;DAY;MYOCI1;3edc0ede-a291-40f4-8621-f6539d48b5d6;;
Comment
-
Hello spondishy,
The spaces were not intentional and were added by the forum. (It adds weird spaces every now and then)
I've put that in a code block so the spaces in the OCOID are removed, but it is still adding a weird invisible character to the beginning and end of some lines which need to be manually removed.
Video of testing the code as posted in post # 8, with slight modification for the stop price to be a valid price and removing the extra characters at the end of the lines.
https://drive.google.com/file/d/1SSj...w?usp=drivesdk
I am also attaching the OIF files, with all of the weird spaces and characters removed that the forum is injecting.Attached FilesChelsea B.NinjaTrader Customer Service
Comment
-
Hello spondishy,
Yes, the position will be in the position update file.
Below is a link to the help guide.
https://ninjatrader.com/support/help...ionUpdateFiles
This text file can be opened with Notepad which is installed with Windows by default.
Chelsea B.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by Dr Kerry, 11-27-2023, 04:22 AM
|
7 responses
54 views
0 likes
|
Last Post
![]()
by Dr Kerry
Today, 04:15 PM
|
||
Started by tkaboris, Yesterday, 01:10 PM
|
10 responses
43 views
0 likes
|
Last Post
|
||
Started by BIOK.NT, Today, 02:36 AM
|
3 responses
30 views
0 likes
|
Last Post
|
||
Started by haakonflaar, 11-24-2023, 06:51 PM
|
7 responses
37 views
0 likes
|
Last Post
|
||
Started by cbatson89, Today, 01:37 PM
|
7 responses
22 views
0 likes
|
Last Post
|
Comment