Announcement
Collapse
No announcement yet.
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]
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.
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
-
Originally posted by NinjaTrader_ChelseaB View PostHello 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]
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.
I've too have been looking for more info on OIF prompting me to reply to you on this post. I've read a lot of the instructions on OIF but I'm no coder and some of the NT custom code partners havent responded. So I'll ask here:
Can a text command be written and sent to my NT8 appropriate directory that merely asks NT to either hit the F4 or F9 Hot keys which will initiate a BUY or SELL respectively? If executed the rest will be handled by my ATM and its embedded Stop Strategy/trailing instructions. My external app has all my triggering concurrent signals and, when fulfilled, is capable of generating a txt message to any directory on my computer; NT is on the same computer.
Basically I'm trying to devise a OIF poor man's algo to auto trade by putting my Red/Black chip down and letting the ATM do its thing..........Stick 2 Plan: my note to self above my monitor and stay out of the way!!!
Thanks for the advise in advance
BruceLast edited by trymph; 02-05-2024, 07:30 AM.
Comment
-
Hello Bruce,
This wouldn't be something that could be accomplished with OIF files.
With a NinjaScript Strategy or Indicator, you could use undocumented code to detect key presses and send an order.
This example may give you some ideas.
If your application is where you are triggering actions from keypresses, the application could copy an OIF file into the incoming directory..Chelsea B.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by M_ichel, Today, 04:47 PM
|
0 responses
5 views
0 likes
|
Last Post
by M_ichel
Today, 04:47 PM
|
||
Started by lucyhendricks, Today, 04:18 PM
|
0 responses
3 views
0 likes
|
Last Post Today, 04:18 PM | ||
Started by cmarkb, 05-08-2020, 09:42 AM
|
11 responses
737 views
0 likes
|
Last Post
by rafaelcoisa
Today, 03:47 PM
|
||
Started by reynoldsn, Today, 03:08 PM
|
1 response
3 views
0 likes
|
Last Post Today, 03:37 PM | ||
Started by RubenCazorla, 09-15-2022, 08:28 AM
|
4 responses
56 views
0 likes
|
Last Post Today, 03:02 PM |
Comment