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!
See more
See less

Partner 728x90

Collapse

Questions After First Day Automated (Paper) Trading

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Questions After First Day Automated (Paper) Trading

    Hi,

    I put live an automated system today using Interactive Brokers (IB) Paper Trading and NT8, and have a bunch of questions from this first day that I'm hoping to ask for help with please (please let me know if I should break them into different tickets).

    1. Disconnected from IB > Failed to Reconnect > Locked out of IB account: I logged into Trader Workstation using my IB Paper Details, connected via Connections, set off a strategy across 50 instruments - it bought/sold various (e.g. established its working). After running ok for an hour I left it alone for the day then after regular hours I came back to my PC to find various errors and Interactive Brokers 'failed login' messages. NT showed the IB Paper connection as red, while IB Trader Workstation was showing 'failed login' and 'password reset' messages. Within connections I clicked to fully disconnect the (now not connected/red) IB Paper Account connection, then closed down Trader Workstation and opened it back up again. I tried to log back into IB Trader Workstation but it wouldn't let me ("Invalid username or password.") despite it 100% being the same password I'd used earlier. I needed to reset my IB password to get back in again. I contacted IB Support to try and see from their end what happened, but most likely the connection dropped with NT and repeated attempts to login probably locked the account (requiring password reset). How can I try to debug what happened here please so that it doesn't happen again? (the log info isn't clear when it tried to reconnect and how many times it attempted to)

    Code:
    2021-11-19 17:35:40:248|1|32|Order='1516746908/DU1529868' Name='ExitBuyLong_NewProfitStoploss1' New state='Accepted' Instrument='RIOT' Action='Sell' Limit price=0 Stop price=0 Quantity=688 Type='Market' Time in force=GTC Oco='' Filled=0 Fill price=0 Error='No error' Native error=''
    2021-11-19 17:36:10:142|1|2|My Paper Interactive Brokers: Primary connection=Connection lost, Price feed=Connected
    2021-11-19 19:28:13:231|1|16|NinjaScript strategy 'MyVolumeSRv1/238461238' submitting order
    2021-11-19 19:28:13:231|1|32|Order='2bc96a2667804804bccfb05b4 6285526/DU1529868' Name='ExitBuyLong_NewProfitStoploss1' New state='Rejected' Instrument='VIAC' Action='Sell' Limit price=0 Stop price=0 Quantity=744 Type='Market' Time in force=GTC Oco='' Filled=0 Fill price=0 Error='Unable to submit order' Native error='Order '2bc96a2667804804bccfb05b46285526' can't be submitted: account is not connected.'
    2021-11-19 19:28:13:231|0|32|DU1529868, Order '2bc96a2667804804bccfb05b46285526' can't be submitted: account is not connected. affected Order: Sell 744 Market
    2021-11-19 19:28:13:231|0|4|Strategy 'MyVolumeSRv1/238461238' submitted an order that generated the following error 'Unable to submit order'. Strategy has sent cancel requests, attempted to close the position and terminated itself.
    2021-11-19 19:28:13:232|1|4|Disabling NinjaScript strategy 'MyVolumeSRv1/238461238'
    2021-11-19 19:28:13:232|1|32|Order='1516746840/DU1529868' Name='Stop loss' New state='Accepted' Instrument='VIAC' Action='Sell' Limit price=0 Stop price=33.51 Quantity=744 Type='Stop Market' Time in force=GTC Oco='' Filled=0 Fill price=0 Error='Unable to cancel order' Native error='Unable to cancel order 1516746840: account is not connected.'
    2021-11-19 19:28:13:232|0|32|DU1529868, Unable to cancel order 1516746840: account is not connected. affected Order: Sell 744 StopMarket @ 33.51
    2021-11-19 19:28:13:234|1|32|Order='1516746840/DU1529868' Name='Stop loss' New state='Accepted' Instrument='VIAC' Action='Sell' Limit price=0 Stop price=33.51 Quantity=744 Type='Stop Market' Time in force=GTC Oco='' Filled=0 Fill price=0 Error='Unable to cancel order' Native error='Unable to cancel order 1516746840: account is not connected.'
    2021-11-19 19:28:13:234|0|32|DU1529868, Unable to cancel order 1516746840: account is not connected. affected Order: Sell 744 StopMarket @ 33.51
    2021-11-19 19:28:21:902|0|4|Strategy 'MyVolumeSRv1/238461238' submitted a cancellation request for Order ID 'orderId='1516746840' account='DU1529868' name='Stop loss' orderState=Accepted instrument='VIAC' orderAction=Sell orderType='Stop Market' limitPrice=0 stopPrice=33.51 quantity=744 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=708 time='2021-11-19 19:28:13' gtd='2099-12-01' statementDate='2021-11-19'' which has not been confirmed cancelled. Please check your account orders and positions.
    2021-11-19 19:47:51:994|0|2|My Paper Interactive Brokers: Lost or unable to establish communications with IB TWS/GW. Please verify TWS/GW is running on the target machine and try reconnecting or contact support if the issue persists. (Panic)
    2021-11-19 19:47:51:994|1|2|My Paper Interactive Brokers: Primary connection=Disconnecting, Price feed=Connected
    2021-11-19 19:47:52:016|1|2|My Paper Interactive Brokers: Primary connection=Disconnecting, Price feed=Disconnecting
    2021-11-19 19:47:52:033|1|2|My Paper Interactive Brokers: Primary connection=Disconnected, Price feed=Disconnected
    Please note, I've since realized that I was running version 8.0.24.3 and there's a later version (8.0.25.0) that I've now installed, but I'd still like to understand how to determine reconnection attempts so I can try to avoid locking the account in future if it happens again.

    2. I'd like to source my live data from IQFeed and place trades with Interactive Brokers. In the strategy pane I couldn't find how to achieve this, I could only select my IB 'account' and then the connection showed as 'My Paper Interactive Brokers'. Please could you advise how I can achieve this?

    3. I'm aiming to run my strategy across ~50 instruments, and using the strategy pane (no charts for computing efficiency). If I decide that I want to open up one of the instruments that a strategy is using on a chart, is this possible to do without affecting the trading? E.g. the strategy pane is showing stock ABC is up $1000, I want to check in on it to see what is happening and see on a chart why the position was entered (or why it hasn't stopped). I was nervous that opening ABC in a chart and applying the strategy may cause the system to think the strategy is running twice (and when exiting, it'd accidentally place two sales and inadvertently go short), so wondering the best way to do this please?

    4. Likely a silly question so apologies in advance. Today I went to the strategy pane, selected my strategy, selected my instrument list of 50 instruments, and it populated 50 rows in the strategy pane that I had to tick one by one to 'enable'. Am I doing this correctly? (it felt a bit odd that had to do this one by one but couldn't see how to do all in one). Similarly, lets say I want to end the day early, so need to disable all strategies and close all open positions. Is the correct process to A) untick the 'enabled' box one by one, then B) go to the Accounts Tab and 'Close All Selected Positions'?

    5a. I understand that getting the available Buying Power of an account is something akin to: "myBuyingPower = Account.Get(AccountItem.BuyingPower, Currency.UsDollar);"

    For backtesting I'm currently using "myBuyingPower = 50000;" - how can I code the strategy to detect if its in backtest or live mode please? E.g. I'm hoping to have something like:
    if (Live == true) myBuyingPower = Account.Get(AccountItem.BuyingPower, Currency.UsDollar);
    if (Live == false) myBuyingPower = 50000;

    5b. Is it possible to recreate/reflect Buying Power in the Strategy Analyzer backtesting for a basket of instruments? For example, in backtesting against a list of 50 instruments, to set the Buying Power at $50,000, then after 5x $10,000 positions are open by 10am, to have Buying Power updated to $0 so that a 6th position cannot be opened (as this is what would happen in a live trading environment). I haven't fully wrapped my head around whether Strategy Analyzer is running 50 independent strategies, or running 50 in parallel.

    Many thanks in advance

    ChainsawDR
    Attached Files
    Last edited by ChainsawDR; 11-21-2021, 10:42 PM.

    #2
    Hello ChainsawDR,

    Thank you for your post.

    Paper accounts with IB present a problem because TWS/Gateway 960.2g and later presents a pop-up when connecting to a paper account. This pop-up cannot be disabled and this interferes with the auto logon process. I could see this would also present an issue when trying to reconnect to the paper account when the connection is severed. Reconnecting manually should allow the strategy to continue.

    The connection status can be monitored using OnConnectionStatusUpdate: https://ninjatrader.com/support/help...atusupdate.htm

    To select your data to come from IQFeed, you will need to set this as your preferred connection type in Tools > Options > Market Data > expand the two sections for preferred connections at the top and select IQFeed as the provider for the required instrument type. The display in the strategies tab should still show the IB connection since that's the account selected for the strategy, but the data will then come from IQFeed.

    To enable multiple strategies simultaneously, you can click the first strategy in the list to select it, then hold the Shift key and click the last strategy in the list to select all strategies. Then right click > Enable and all strategies should be enabled at the same time.

    To check whether the strategy is being run in the Strategy Analyzer you can use IsInStrategyAnalyzer:



    Strategies run in a basket test are running individual instances of the strategy and are not all running in parallel, so you would not be able to adjust buying power based on how other instances of the strategy have behaved.

    Please let us know if we may be of further assistance to you.
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Thank you Kate, that's very comprehensive and helpful. I ran it with the live account and no disconnection issues, and you other responses helped resolve everything. Thanks again!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by LawrenHom, Today, 10:45 PM
      0 responses
      3 views
      0 likes
      Last Post LawrenHom  
      Started by love2code2trade, Yesterday, 01:45 PM
      4 responses
      28 views
      0 likes
      Last Post love2code2trade  
      Started by funk10101, Today, 09:43 PM
      0 responses
      7 views
      0 likes
      Last Post funk10101  
      Started by pkefal, 04-11-2024, 07:39 AM
      11 responses
      37 views
      0 likes
      Last Post jeronymite  
      Started by bill2023, Yesterday, 08:51 AM
      8 responses
      44 views
      0 likes
      Last Post bill2023  
      Working...
      X