![]() |
|
|||||||
| Strategy Development Support for the development of custom automated trading strategies using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Member
Join Date: Sep 2009
Posts: 51
Thanks: 0
Thanked 0 times in 0 posts
|
When I reverse position then NT's Internal Order Handling mechanism automaticaly closes my current position @ new position's entry price.
How can I close my current position @ another price, for example @ bar's open price? These are limit orders.
Last edited by Argo1; 09-12-2009 at 05:31 AM.
|
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: May 2008
Location: Denver, CO
Posts: 3,157
Thanks: 0
Thanked 3 times in 3 posts
|
Hello,
Are you talking about backtesting or in a live environment? Post your code so I see what you are doing currently. I'm not 100% sure what you are want and what is happening.
Ben
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Member
Join Date: Sep 2009
Posts: 51
Thanks: 0
Thanked 0 times in 0 posts
|
Backtesting. 1 day bars. Forex market.
I'm no longer using limit orders but stop orders. In brief: How to push NT to close long stop position at market price, not at entry price for reversal position, when reversing? Example: Day 1: I went long with EnterLongStop() method. Stop price=156.98. NT State=Filled. - That's OK. Day 2: There is a signal fo reversing position (from today's close price). 1) I try to open short position with EnterShortStop() method. Stop price=155.87. Output window: 2000-11-28 00:00:00 Entered internal PlaceOrder() method at 2000-11-28 00:00:00: Action=SellShort OrderType=Stop Quantity=0,1M LimitPrice=0 StopPrice=155,87 SignalName='MyEntryShort' FromEntrySignal='' 2) NT automatically tries to close my long position: 2000-11-28 00:00:00 OnOrderUpdate(): Order='NT-00011/Back101' Name='Close position' State=PendingSubmit Instrument='$GBPJPY' Action=Sell Limit price=0 Stop price=155,87 Quantity=0,1M Strategy='X' Type=Stop Tif=Gtc Oco='' Filled=0 Fill price=0 Token= 3) Close position's order is not going to "Filled" state because today is no market price for this: Prices for this day bar: O:156.73 H:157.14 L:155.96 C:156.07 Stop price for close position is: 155.87. Day 3: Today close long order and open short stop order are cancelled because of expiration. Prices for this day bar: O:157.28 H:160.74 L:157.23 C:160.43 What I want to have is that NT could close my long position at market price, not at stop price from new short order when I reverse market position. Long position should be closed at open price for day 3.
Last edited by Argo1; 09-13-2009 at 11:19 AM.
|
|
|
|
|
|
#4 |
|
NinjaTrader Customer Service
Join Date: May 2008
Location: Denver, CO
Posts: 3,157
Thanks: 0
Thanked 3 times in 3 posts
|
Hello,
Why don't you use ExitLong(), which uses a market sell order? Then enter in the other direction. The internal reversal logic that comes into play when you try to go both ways in the market is not something you can change. It is hard coded in the orders.
Ben
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Member
Join Date: Sep 2009
Posts: 51
Thanks: 0
Thanked 0 times in 0 posts
|
I tried ExitLong() before, but it doesn't work well:
It closes long at day 3. open price - this is good, but it does not opens short position after this. I put ExitLong() in OnBarUpdate(). Maybe I should put it elsewhere? |
|
|
|
|
|
#6 |
|
Member
Join Date: Sep 2009
Posts: 51
Thanks: 0
Thanked 0 times in 0 posts
|
This is log for this "reversal" day:
Code:
Cancelled custom managed order at 2000-11-28 00:00:00: Order='NT-00009/Back101' Name='MyTargetLong' State=Working Instrument='$GBPJPY' Action=Sell Limit price=159,98 Stop price=0 Quantity=0,1M Strategy='X' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='02cf63bf921841819c803a6e43e64e15' Gtd='2099-12-01 00:00:00' 2000-11-28 00:00:00 Entered internal PlaceOrder() method at 2000-11-28 00:00:00: Action=Sell OrderType=Market Quantity=0 LimitPrice=0 StopPrice=0 SignalName='' FromEntrySignal='' 2000-11-28 00:00:00 Entered internal PlaceOrder() method at 2000-11-28 00:00:00: Action=SellShort OrderType=Stop Quantity=0,1M LimitPrice=0 StopPrice=155,87 SignalName='MyEntryShort' FromEntrySignal='' 2000-11-28 00:00:00 OnOrderUpdate(): Order='NT-00009/Back101' Name='MyTargetLong' State=PendingCancel Instrument='$GBPJPY' Action=Sell Limit price=159,98 Stop price=0 Quantity=0,1M Strategy='X' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='02cf63bf921841819c803a6e43e64e15' Gtd='2099-12-01 00:00:00' 2000-11-28 00:00:00 OnOrderUpdate(): Order='NT-00009/Back101' Name='MyTargetLong' State=Cancelled Instrument='$GBPJPY' Action=Sell Limit price=159,98 Stop price=0 Quantity=0,1M Strategy='X' Type=Limit Tif=Gtc Oco='' Filled=0 Fill price=0 Token='02cf63bf921841819c803a6e43e64e15' Gtd='2099-12-01 00:00:00' 2000-11-28 00:00:00 OnOrderUpdate(): Order='NT-00010/Back101' Name='Sell' State=PendingSubmit Instrument='$GBPJPY' Action=Sell Limit price=0 Stop price=0 Quantity=0 Strategy='X' Type=Market Tif=Gtc Oco='' Filled=0 Fill price=0 Token='4d7ce5d907e64efaa81bb4455143af21' Gtd='2099-12-01 00:00:00' 2000-11-28 00:00:00 OnOrderUpdate(): Order='NT-00010/Back101' Name='Sell' State=Accepted Instrument='$GBPJPY' Action=Sell Limit price=0 Stop price=0 Quantity=0 Strategy='X' Type=Market Tif=Gtc Oco='' Filled=0 Fill price=0 Token='4d7ce5d907e64efaa81bb4455143af21' Gtd='2099-12-01 00:00:00' 2000-11-28 00:00:00 OnOrderUpdate(): Order='NT-00010/Back101' Name='Sell' State=Working Instrument='$GBPJPY' Action=Sell Limit price=0 Stop price=0 Quantity=0 Strategy='X' Type=Market Tif=Gtc Oco='' Filled=0 Fill price=0 Token='4d7ce5d907e64efaa81bb4455143af21' Gtd='2099-12-01 00:00:00' 2000-11-28 00:00:00 OnOrderUpdate(): Order='NT-00010/Back101' Name='Sell' State=Filled Instrument='$GBPJPY' Action=Sell Limit price=0 Stop price=0 Quantity=0,1M Strategy='X' Type=Market Tif=Gtc Oco='' Filled=100000 Fill price=156,14 Token='4d7ce5d907e64efaa81bb4455143af21' Gtd='2099-12-01 00:00:00' 2000-11-28 00:00:00 OnExecution(): Execution='NT-00007' Instrument='$GBPJPY' Account='Back101' Name='Sell' Exchange=Default Price=156,14 Quantity=0,1M Market position=Short Commission=0 Order='NT-00010' Time='2000-11-29 00:00:00' Multiplier=1E-05 2000-11-28 00:00:00 OnPositionUpdate(): Instrument='$GBPJPY' Account='Back101' Avg price=0 Quantity=0 Market position=Flat There is "Entered internal PlaceOrder() method at 2000-11-28 00:00:00: Action=SellShort" but nothing more this day nor next day.
Last edited by Argo1; 09-13-2009 at 12:35 PM.
|
|
|
|
|
|
#7 |
|
Member
Join Date: Sep 2009
Posts: 51
Thanks: 0
Thanked 0 times in 0 posts
|
Is it possible that NT can't process these two orders: ExitLong() and EnterShortStop() on the same bar?
Last edited by Argo1; 09-13-2009 at 11:57 AM.
|
|
|
|
|
|
#8 |
|
NinjaTrader Customer Service
Join Date: May 2008
Location: Denver, CO
Posts: 3,157
Thanks: 0
Thanked 3 times in 3 posts
|
Hello,
Are you backtesting? If so, everything is done on bar close. Also the code iterates in OnBarUpdate() only when an new bar comes in/closes. This may be what is causing the issue for you.
Ben
NinjaTrader Customer Service |
|
|
|
|
|
#9 |
|
Member
Join Date: Sep 2009
Posts: 51
Thanks: 0
Thanked 0 times in 0 posts
|
It is backtesting on daily bars. There are bars after day 3.
Normally, when I reverse position using only EnterShortStop() method (without ExitLong()) then NT automatically closes long and opens short on the same bar. NT disallows manual execution both ExitLong() and EnterShortStop() orders on the same bar? |
|
|
|
|
|
#10 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
|
Argo1,
That is correct. In backtesting this happens because it does not realize these were actually placed in the same bar to go together. You will need to use the Enter() directly to get the reversal on the same bar.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#11 |
|
Member
Join Date: Sep 2009
Posts: 51
Thanks: 0
Thanked 0 times in 0 posts
|
Thanks, Josh.
Thus, answer for my post #1 question is: it's impossible ? |
|
|
|
|
|
#12 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
|
Correct. From a backtesting scenario that would be the case.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#13 |
|
Member
Join Date: Sep 2009
Posts: 51
Thanks: 0
Thanked 0 times in 0 posts
|
Ok, thank you.
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Sounds & position close w/strategy on | nicknamed | Suggestions And Feedback | 2 | 05-20-2009 06:03 AM |
| Line From Previous Day Close | cre8it8 | Indicator Development | 4 | 04-17-2009 04:32 PM |
| Auto Reverse Option on Chart Trader | aslane | Automated Trading | 1 | 04-03-2009 09:59 AM |
| Best way to reverse a position? | Idruna | Strategy Development | 10 | 09-24-2008 10:17 PM |
| Previous Day's Close, High, Low | Billy Valentine | General Programming | 2 | 04-13-2008 04:36 PM |