Thanks
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
Buy long, reverse to short, reverse again to long
Collapse
X
-
Buy long, reverse to short, reverse again to long
It doesn't seem like this should be very difficult. So far i'm just trying to get it to work without adding in the indicators or anything. Just a simple framework to start with for backtesting the Eminis. It seems like I should just be able to, for example, buy long at the open of the day, set an ExitLongLimit(1, limit) and EnterShortStop(1, stop), then if the Limit hits, it's done, but if the stop hits it enters a new Limit and Stop following the same rules. I can do it if I just use EnterLong() and EnterShort() with the "if" rules determining what happens. But then I can only use (i think) the close of the bar, and I only have 1 minute data. I want it to exit the trade at exactly the stop price, and enter the next trade at that same price (I can figure slippage/spread separately if need be). When I program the above, it works some days and not others. There are some days were it doesn't even exit the first trade, just holds it until the end of the day. Can anyone provide a quick and simple example of doing this? I'm not on the right computer, but I can post the code I have and the results later if it's helpful.
ThanksTags: None
-
nebeno,
You can have ExitLongLimit and ExitLongStop running at the same time. You cannot have limit and stop working in opposite market directions though. Reason is because EnterShortLimit/Stop will reverse any long position it sees first. When you have ExitLongLimit with EnterShortStop it does not know if it should reverse or not depending on if that ExitLongLimit hits or not. Instead you should just program the logic to place in one order at a time. Whichever the price is closest to, use that order.Josh P.NinjaTrader Customer Service
Comment
-
Josh
I am trying to implement a stop and reverse strategy and am facing a similar problem. I am using a combination of EnterLongStop, ExitLongStop, EnterShortStop and ExitShortStop. From what I understand, EnterLongStop will first cancel any short position and then enter long because of which the NT Internal Order Handling Rules rejects other orders. This is all during backtesting.
(1) Is there a lower level API available which provides more fine-grain control and bypasses NT's interpretation of the orders? My strategy is not a true Stop and Reverse, in the sense that the closing order and the reverse order may not happen at the same time in some cases.
(2) Also is there a better way of dynamically updating stop levels instead of cancelling the existing order and then sending a new order?
(3) It is also not clear to me how to construct OCO Orders via the Strategy Engine.
---------------------
I also noticed that the sequence in which NT is processing the calls for order handling is not what I would expect.
I have a EnterShortStop order active. I want to change that to EnterLongStop and first call the CancelOrder on the IOrder returned by EnterShortStop method. I then call the EnterLongStop function. All is happening in a function call made on the OnBarUpdate method (backtesting).
Note that in Bar 9, I first cancel the short order entry before adding the EnterLongStop order. But NT rejects the LongStop because it has not yet processed the cancel request for the EnterShortStop. NT Trace is in italics.
12/17/2009 10:41:16 AM Entered internal PlaceOrder() method at 12/17/2009 10:41:16 AM: Action=SellShort OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=73.58 SignalName='' FromEntrySignal=''
8: Short Entry Order Sell Stop at 73.58envHigh = 73.63; envLow = 73.58; slope = 0.0421428571428493
9: Cancelling Short Entry Order
12/17/2009 10:42:17 AM Entered internal PlaceOrder() method at 12/17/2009 10:42:17 AM: Action=Buy OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=73.62 SignalName='' FromEntrySignal=''
12/17/2009 10:42:17 AM Ignored PlaceOrder() method at 12/17/2009 10:42:17 AM: Action=Buy OrderType=Stop Quantity=1 LimitPrice=0 StopPrice=73.62 SignalName=Buy' FromEntrySignal='' Reason='An Enter() method to submit an entry order has been ignore. Please search on the term 'Internal Order Handling Rules' in the Help Guide for detailed explanation.'
9: Long Entry Order Buy Stop at 73.62envHigh = 73.62; envLow = 73.57; slope = -0.0128571428571007
12/17/2009 10:42:17 AM Cancelled expired order: BarsInProgress=0: Order='NT-00000/Back101' Name='Sell short' State=Working Instrument='CL 02-10' Action=SellShort Limit price=0 Stop price=73.58 Quantity=1 Strategy='RegEnvRangeStopBased' Type=Stop Tif=Gtc Oco='' Filled=0 Fill price=0 Token='4f2bb380c8cd450487435f9d376a0a75' Gtd='12/1/2099 12:00:00 AM'Last edited by aviat72; 12-18-2009, 03:33 AM.
Comment
-
To clarify, sending in a Enter() does not cancel orders in the opposite direction. It only closes positions in the opposite direction first.
1. NT7 will provide lower level control.
2. Just call Exit() with the new stop price. It will amend your current order.
3. This is done via your own code. When you receive a filled state in one, send a cancel in the other. For ExitLongLimit()/ExitLongStop(). Once the position is closed by either of them, the other will auto cancel when it can't find a position to close any more.Josh P.NinjaTrader Customer Service
Comment
-
I have been waiting patiently for a few weeks now .
I want to use the slow period to do a lot of new development and NT7 has a lot of architectural changes and features not available in NT6.5 which I do need.
So if you can let me download whatever the latest version of the Beta is, it will really help. I could have used this weekend to get things going.
I am still pushing my comfort zone with the features which NT has and really do not care about bugs in the system. The features which I can target are important for me.
Comment
-
Ben:
After doing some more research, it is clear that there is very little value for me to develop my stuff based on NT6.5 with NT7 right around the corner. Stuff like bypassing internal order handling, multi-instrument indicators etc. are almost a must have for me. So please do try and get me in the Beta.
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by slightly, Today, 12:49 AM
|
0 responses
2 views
0 likes
|
Last Post
by slightly
Today, 12:49 AM
|
||
Started by sdauteuil, 09-23-2021, 10:16 AM
|
4 responses
1,208 views
0 likes
|
Last Post Yesterday, 11:41 PM | ||
Started by agclub, 04-21-2024, 08:57 PM
|
5 responses
34 views
0 likes
|
Last Post
by agclub
Yesterday, 09:47 PM
|
||
Started by ESHunter, Yesterday, 08:06 PM
|
2 responses
18 views
0 likes
|
Last Post
by ESHunter
Yesterday, 09:27 PM
|
||
Started by ETFVoyageur, 05-07-2024, 07:05 PM
|
19 responses
150 views
0 likes
|
Last Post
by ETFVoyageur
Yesterday, 09:14 PM
|
Comment