Go Back   NinjaTrader Support Forum > NinjaTrader 8 > Strategy Development

Strategy Development Support for the development of custom automated trading strategies using NinjaScript.

NinjaTrader
Reply
 
Thread Tools Display Modes
Old 05-01-2018, 12:47 AM   #1
saltminer
Senior Member
 
Join Date: Apr 2008
Posts: 304
Thanks: 16
Thanked 9 times in 9 posts
Default AdoptAccountPosition

Hi,
I've been testing AdoptAccountPosition so that a strategy can recover from a stoppage.

When the strategy is stopped, it leaves a position in the account and working orders in the account. That's ok - the intention is that AdoptAccountPosition will be able to recover from this.

AdoptAccountPosition fails in this scenario.

It is only if no orders are active in the Account that AdoptAccountPosition successfully creates a virtual execution and gets the strategy in sync.

Note that these orders I am talking about here are from the strategy itself. Other orders (such as those manually placed) create a warning that the strategy cannot be started. I'm fine with that, but I do want the strategy to successfully sync when its own orders from earlier are still working in the account.

You can see the fail in the text below.

Over to you.
Thanks,
saltminer


Quote:
TestOrderRecoveryFromAccount state=Transition
ReportingAccountOrders for Sim101 with instrument='AUDUSD' account='Sim101' avgPrice=0.75306 quantity=10,000 marketPosition=Long statementDate='2018-04-30' versus strategy position instrument='AUDUSD' account='Sim101' avgPrice=0 quantity=0 marketPosition=Flat statementDate='2018-04-30'


DiscoveringAccountOrders for Sim101 with instrument='AUDUSD' account='Sim101' avgPrice=0.75306 quantity=10,000 marketPosition=Long statementDate='2018-04-30'
Sim101 found working order orderId='bf082caace724b02a13037ab7b90b9ae' account='Sim101' name='LS' orderState=Accepted instrument='AUDUSD' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=0.75266 quantity=10,000 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=1660 time='2018-05-01 16:25:01' gtd='2099-12-01' statementDate='2018-05-01'
Sim101 found working order orderId='f5466b8b22714dc4ae3e063c7f4ec2f5' account='Sim101' name='LT' orderState=Working instrument='AUDUSD' orderAction=Sell orderType='Limit' limitPrice=0.75346 stopPrice=0 quantity=10,000 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=1661 time='2018-05-01 16:25:01' gtd='2099-12-01' statementDate='2018-05-01'

Enabling NinjaScript strategy 'TestOrderRecoveryFromAccount/123813582' : On starting a real-time strategy - StartBehavior=AdoptAccountPosition EntryHandling=All entries EntriesPerDirection=1 StopTargetHandling=Per entry execution ErrorHandling=Stop strategy, cancel orders, close positions ExitOnSessionClose=True / triggering 30 seconds before close SetOrderQuantityBy=Default quantity ConnectionLossHandling=Recalculate DisconnectDelaySeconds=10 CancelEntriesOnStrategyDisable=False CancelExitsOnStrategyDisable=False Calculate=On each tick IsUnmanaged=False MaxRestarts=4 in 5 minutes

ReportingAccountOrders for Sim101 with instrument='AUDUSD' account='Sim101' avgPrice=0.75306 quantity=10,000 marketPosition=Long statementDate='2018-04-30' versus strategy position instrument='AUDUSD' account='Sim101' avgPrice=0 quantity=0 marketPosition=Flat statementDate='2018-04-30'
saltminer is offline  
Reply With Quote
Old 05-01-2018, 01:25 PM   #2
NinjaTrader_AlanP
NinjaTrader Customer Service
 
NinjaTrader_AlanP's Avatar
 
Join Date: Apr 2016
Location: Denver, CO
Posts: 2,674
Thanks: 223
Thanked 574 times in 553 posts
Default

Hello saltminer,

Thank you for your note.

Without the full code we're unable to test on our end.

If you'd like to upload the full code I can take a look and see if anything jumps out. Or if you'd prefer to email a copy, send to platformsupport[at]ninjatrader[dot]com with Attn: Alan P in the Subject line. Also within the email please include a link to this thread, and the files.

You may also be interested in the following link in our helpguide,
https://ninjatrader.com/support/help...ccountPosition

As well as a Adapt Account Position Strategy sample I have attached which will submit a PT and SL when started should the account/instrument the strategy was started on have an open position, say through a superdom trade. When you disable the strategy the PT and SL orders remain working, but when you reenable the strategy they are canceled.

I look forward to your reply.
NinjaTrader_AlanP is offline  
Reply With Quote
Old 05-02-2018, 12:58 PM   #3
saltminer
Senior Member
 
Join Date: Apr 2008
Posts: 304
Thanks: 16
Thanked 9 times in 9 posts
Default point proven

Hi Alan,
your example strategy demonstrates the problem perfectly.

I changed Calculate to OnEachTick and enhanced the print statements like this:


Print("PositionAccount:");
Print(State.ToString()+PositionsAccount[0].Quantity.ToString());
Print(PositionsAccount[0].MarketPosition.ToString());

Print("PositionStrategy:");
Print(State.ToString()+Positions[0].Quantity.ToString());
Print(Positions[0].MarketPosition.ToString());

Perform the following steps and you'll see AdoptAccountPosition fail.
  1. * Open a position manually
  2. * Enable the strategy. It correctly adopts the account position, and puts on some orders.
  3. * Disable the strategy.
  4. * Enable the strategy. The orders cancel, and the strategy fails to adopt the account position.

The first time you run the strategy (step 2) it prints out this:

PositionAccount:
Realtime10000
Long
PositionStrategy:
Realtime10000
Long

The second time you run the strategy (step 4) it prints out this:

PositionAccount:
Realtime10000
Long
PositionStrategy:
Realtime0
Flat

Regards,
saltminer
saltminer is offline  
Reply With Quote
Old 05-02-2018, 03:54 PM   #4
NinjaTrader_AlanP
NinjaTrader Customer Service
 
NinjaTrader_AlanP's Avatar
 
Join Date: Apr 2016
Location: Denver, CO
Posts: 2,674
Thanks: 223
Thanked 574 times in 553 posts
Default

Hello saltminer,

I am able to replicate and will follow up when I have more information.

Thank you for your patience.
NinjaTrader_AlanP is offline  
Reply With Quote
Old 05-17-2018, 07:28 PM   #5
saltminer
Senior Member
 
Join Date: Apr 2008
Posts: 304
Thanks: 16
Thanked 9 times in 9 posts
Default

Hi,
I'm in the middle of a project that is hinging on this feature. Do you have a timeline on a fix or even just news on this issue?
Thanks.

saltminer
saltminer is offline  
Reply With Quote
Old 05-18-2018, 10:24 AM   #6
NinjaTrader_PatrickH
NinjaTrader Customer Service
 
NinjaTrader_PatrickH's Avatar
 
Join Date: Jul 2011
Location: Denver, CO
Posts: 11,766
Thanks: 792
Thanked 2,034 times in 1,957 posts
Default

Hello saltminer,

Thank you for your response.

The fix is planned for implementation in the next release of NinjaTrader 8. I do not have a time frame for the release.

Please let me know if you have any questions.
NinjaTrader_PatrickH is offline  
Reply With Quote
Old 07-04-2018, 10:12 PM   #7
saltminer
Senior Member
 
Join Date: Apr 2008
Posts: 304
Thanks: 16
Thanked 9 times in 9 posts
Default any news?

Hi Patrick,
any idea when this fix might be coming? I have a paid project just circling the airport...
Thanks,
saltminer
saltminer is offline  
Reply With Quote
Old 07-05-2018, 06:23 AM   #8
NinjaTrader_PatrickH
NinjaTrader Customer Service
 
NinjaTrader_PatrickH's Avatar
 
Join Date: Jul 2011
Location: Denver, CO
Posts: 11,766
Thanks: 792
Thanked 2,034 times in 1,957 posts
Default

Hello saltminer,

Thank you for your post.

This matter was resolved in NinjaTrader 8.0.14.0. The ID for this item was 12795 which you can look up in the Release Notes at the following link: https://ninjatrader.com/support/help...s/8_0_14_2.htm

Please let me know if you have any questions.
NinjaTrader_PatrickH is offline  
Reply With Quote
Old 07-11-2018, 09:29 PM   #9
saltminer
Senior Member
 
Join Date: Apr 2008
Posts: 304
Thanks: 16
Thanked 9 times in 9 posts
Default

Hello Patrick,
the matter may have been "resolved", but unfortunately I don't believe that means "fixed".

When using AdoptAccountPosition now, strategies are not allowed to start if there are working orders in the Account. The following message is given:

<strategy name> could not be enabled because the ‘Start behavior’ parameter 'Adopt account position' requires that there are no working orders on this strategy's instrument(s) in 'Sim101'. Please cancel any working orders on the same account-instrument combo(s) first to be able to enable your strategy.

So this problem has not been fixed, merely avoided. This is unhelpful, as strategies will want to adopt both an Account Position and working orders.
Please put this issue back into your work queue for a proper fix.

saltminer
saltminer is offline  
Reply With Quote
Old 07-12-2018, 07:45 AM   #10
NinjaTrader_AlanP
NinjaTrader Customer Service
 
NinjaTrader_AlanP's Avatar
 
Join Date: Apr 2016
Location: Denver, CO
Posts: 2,674
Thanks: 223
Thanked 574 times in 553 posts
Default

Hello saltminer,

Are you suggesting that previous to the fix, you could have working orders on the account and start the strategy?

The issue you describe here was resolved, or fixed, was it not?
https://ninjatrader.com/support/foru...09&postcount=3

If no to question 1 and yes to question 2, then would you agree this is a feature request? "Allow strategies to adopt Account Position and working orders".

I look forward to your reply.
NinjaTrader_AlanP is offline  
Reply With Quote
Old 07-12-2018, 03:04 PM   #11
saltminer
Senior Member
 
Join Date: Apr 2008
Posts: 304
Thanks: 16
Thanked 9 times in 9 posts
Default

Hi,
of this list, #4 is now not possible. The strategy is not allowed to start with orders in the account.


* Open a position manually
* Enable the strategy. It correctly adopts the account position, and puts on some orders.
* Disable the strategy.
* Enable the strategy. The orders cancel, and the strategy fails to adopt the account position.

As a feature request "Allow strategies to adopt Account Position and working orders" might be overreaching. A properly coded strategy could find working orders in the Account and do stuff with them. However, we are now prevented from doing that.
The latest update was not a bugfix, but a bug firewalled away from the user.

So my feature request is "Reinstate the ability for a strategy using AdoptAccountPosition to be enabled while orders are active in the Account".

Thanks,
saltminer
saltminer is offline  
Reply With Quote
Old 07-12-2018, 03:50 PM   #12
NinjaTrader_AlanP
NinjaTrader Customer Service
 
NinjaTrader_AlanP's Avatar
 
Join Date: Apr 2016
Location: Denver, CO
Posts: 2,674
Thanks: 223
Thanked 574 times in 553 posts
Default

Hello saltminer,

I open a position, enable the strategy which submits PT/SL. Disable and Reenable the strategy, the orders are canceled and then resubmitted.

https://www.screencast.com/t/A5oMvYeDnhEF

Is this not the behavior you are seeing?

I look forward to your reply.
NinjaTrader_AlanP is offline  
Reply With Quote
Old 07-15-2018, 05:52 PM   #13
saltminer
Senior Member
 
Join Date: Apr 2008
Posts: 304
Thanks: 16
Thanked 9 times in 9 posts
Default

Hi Alan,
I recreated your test successfully. I also noted that if manual orders are placed in the account, the test is NOT successful. It seems only orders created by the strategy itself are allowed.
BUT, now try doing your test but additionally quitting NT8 and restarting with the open position and working orders, and try to enable the strategy. This would simulate a crash or computer restart or a weekend.
You aren't allowed to enable the strategy from the Control Centre (clicking the enable checkbox does nothing) and if you go to the chart to enable it the error message in the screenshot arrives, forbidding strategy startup.

saltminer
Attached Images
File Type: png Capture2.PNG (33.7 KB, 9 views)
saltminer is offline  
Reply With Quote
Old 07-16-2018, 11:25 AM   #14
NinjaTrader_AlanP
NinjaTrader Customer Service
 
NinjaTrader_AlanP's Avatar
 
Join Date: Apr 2016
Location: Denver, CO
Posts: 2,674
Thanks: 223
Thanked 574 times in 553 posts
Default

Hello saltminer,

Quote:
I also noted that if manual orders are placed in the account, the test is NOT successful.
It was not clear from your instructions that these were manually placed orders.

Quote:
Enable the strategy. It correctly adopts the account position, and puts on some orders.
This is expected behavior per the helpguide,

The account and instrument the strategy is started on must not have any working orders which were submitted outside of the strategy, or by another instance of the same strategy. If an order is detected, the strategy can not be started until these orders have been manually managed.
https://ninjatrader.com/support/help...ccountPosition

Would you agree the bug below was resolved?
https://ninjatrader.com/support/foru...09&postcount=3

Regarding restarting NinjaTrader and the strategy not enabling, I'm currently looking into this and will follow up when I have additional information.
NinjaTrader_AlanP is offline  
Reply With Quote
Old 07-16-2018, 01:42 PM   #15
NinjaTrader_AlanP
NinjaTrader Customer Service
 
NinjaTrader_AlanP's Avatar
 
Join Date: Apr 2016
Location: Denver, CO
Posts: 2,674
Thanks: 223
Thanked 574 times in 553 posts
Default

Hello saltminer,

I submitted a bug report for the behavior where after a NT restart the strategy will not start.
NinjaTrader_AlanP is offline  
Reply With Quote
The following user says thank you to NinjaTrader_AlanP for this post:
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
StartBehavior.AdoptAccountPosition behaviour question ours_solaire Strategy Development 3 09-26-2017 12:54 PM
Multiple Strategies Error with AdoptAccountPosition ak5745 Version 8 Beta 8 07-25-2016 01:18 PM
BarsSinceEntryExecution with AdoptAccountPosition ak5745 Version 8 Beta 16 03-02-2016 12:16 AM


All times are GMT -6. The time now is 02:49 AM.

Futures, foreign currency and options trading contains substantial risk and is not for every investor. An investor could potentially lose all or more than the initial investment. Risk capital is money that can be lost without jeopardizing ones financial security or lifestyle. Only risk capital should be used for trading and only those with sufficient risk capital should consider trading. Past performance is not necessarily indicative of future results. View Full Risk Disclosure.

CFTC Rules 4.41 - Hypothetical or Simulated performance results have certain limitations, unlike an actual performance record, simulated results do not represent actual trading. Also, since the trades have not been executed, the results may have under-or-over compensated for the impact, if any, of certain market factors, such as lack of liquidity. Simulated trading programs in general are also subject to the fact that they are designed with the benefit of hindsight. No representation is being made that any account will or is likely to achieve profit or losses similar to those shown.

This website is hosted and operated by NinjaTrader, LLC (“NT”), a software development company which owns and supports all proprietary technology relating to and including the NinjaTrader trading platform. NT is an affiliated company to NinjaTrader Brokerage (“NTB”), which is a NFA registered introducing broker (NFA #0339976) providing brokerage services to traders of futures and foreign exchange products. This website is intended for educational and informational purposes only and should not be viewed as a solicitation or recommendation of any product, service or trading strategy. No offer or solicitation to buy or sell securities, securities derivative or futures products of any kind, or any type of trading or investment advice, recommendation or strategy, is made, given, or in any manner endorsed by any NT affiliate and the information made available on this Web site is not an offer or solicitation of any kind. Specific questions related to a brokerage account should be sent to your broker directly. The content and opinions expressed on this website are those of the authors and do not necessarily reflect the official policy or position of NT or any of its affiliates. 

Vendors along with their websites, products and services, collectively referred to as (“Vendor Content”), are independent persons or companies that are in no manner affiliated with NT or any if its affiliates. NT or any of its affiliates are not responsible for, do not approve, recommend or endorse any Vendor Content referenced on this website and it’s your sole responsibility to evaluate Vendor Content. Please be aware that any performance information provided by a vendor should be considered hypothetical and must contain the disclosures required by NFA Rule 2-29(c). If you are interested in learning more about, or investigating the quality of, any such Vendor Content you must contact the vendor, provider or seller of such Vendor Content. No person employed by, or associated with, NT or any of its affiliates is authorized to provide any information about any such Vendor Content.