Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Order Handling - Risk

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

    Order Handling - Risk

    Hello,

    I have the following question concerning risk in trading. Hope this is the right place as it has nothing to do with a strategy. If in a script strategy for exits instead of setprofittarget one uses conditions then one can run into severe problems when pc is frozen or internet connection is interrupted - because when during this difficulties the stop was hit on exchange then there is no more position but when pc starts running again and conditions for exits are true then the script strategy will execute the exit, with the result that there is a new position. Is this understanding correct?

    But when using setprofittarget for exits can this same situation as described above happen to run in an opposite position? Meaning when pc works again, in the meantime during internet outage stop was hit, but pc still shows stop and target from setstoploss and setprofittarget. This setstoploss and setprofittarget shown on my pc only (should) mirroring orders from exchange but will not cause an exit, they do not call any action? Yes/No? (So these orders are shown on my pc untill new connected maybe?) Hope could describe the 2 differences in behavior from my understanding.

    PS: I´m using NinjatraderBrokerage with continuum but this should not be important for that question (its not about "where do your orders reside" )

    Thank you!
    Tony
    Last edited by tonynt; 04-30-2021, 06:37 AM. Reason: inaccurate translation

    #2
    Hello tonynt,

    Thank you for your post.

    What happens in a disconnect situation or when a strategy is restarted after stopping would depend on both your Disconnection settings in Tools > Options > Strategies > Expand the On Connection Loss section, as well as potentially the selected start behavior for the strategy.

    Where your orders reside can have some impact on this.

    If you have the number of disconnect seconds set to a very high number, and have Keep Running selected for the Connection Loss handling, the strategy will keep running on reconnect as if no disconnection occurred. Generally as soon as you'd reconnect if the orders are on the broker's servers (as they would be using NinjaTrader Continuum, you'd get an update regarding the position and prior orders being closed. The strategy would then re-enter on the next entry signal.



    If the strategy is disabled during the connection loss, what happens when it is re-enabled would depend on the Start behavior for the strategy.

    In the historical data the conditions in the script will be run as a backtest and have historical results before real-time data processing and real-time order submissions begin.

    Depending on your settings, the script will either not try and match any previous made orders made by the script on a previous run (Wait until flat), or will attempt to resume and try and match previously made orders (Immediately submit) with the orders it calculates in historical data.

    If the settings are setup to resume and have the calculated historical orders match the previously made real-time orders, when orders are matched, these will still show in the real-time strategy performance as real-time (as these orders were made in real-time and by being matched are resumed).

    NinjaTrader can try and resume your strategies when you restart them.


    To do this, you will need to enable the following option before starting a new instance of a strategy:
    • Right-click the chart and select Strategies or right-click the Strategies tab of the Control Center and select New Strategy...
    • Select the strategy from the Available list (in the Chart Strategies window click the New button to add an instance of the strategy)
    • In the parameters on the right, set 'Start behavior' to 'Immediately submit, synchronize account' (or 'Immediately submit')
    • After running your strategy, be sure to save your workspace when you shutdown NinjaTrader


    Below is a link to the help guide on Syncing Account Positions. Please see the section 'Immediately submit, synchronize account'
    http://ninjatrader.com/support/helpG...hronizeAccount

    Further, below is a public link to a forum post about startup behavior.
    https://ninjatrader.com/support/foru...776#post528776

    With these options the following will happen when the strategy resumes. (From the help guide on Immediately submit, synchronize account):

    This combination should be used when you want to begin trading your strategy off a flat state with minimal user interaction to sync your Account Position prior to start.
    • When your strategy starts it will check for any active orders previously generated by the strategy on your account. Any active orders on the account previously generated by the strategy that does not match* an active strategy order will be cancelled. Should the strategy be unable to cancel and receive confirmation on the cancellation of these orders within 40 seconds the strategy will not start and an alert will be issued.
    • The matching active orders on the account will then be mapped to the active strategy orders. These orders will be resumed properly.
      After the strategy is successful in cancelling any orders necessary, any remaining active strategy orders that cannot be successfully paired will be submitted live and the strategy will then try to sync your Account Position to your Strategy Position. On multi-instrument strategies it will perform this check for all instruments used by the strategy.

      (It would be recommended to disable the Tools > Options > Strategies > NinjaScript > 'Cancel entry orders / Cancel exit orders when strategy is disabled' so that these remain in a working state so these can be resumed (should they not fill while the strategy is disabled))
    • If the Account Position matches your Strategy Position, no reconciliatory order will be submitted. The strategy will then begin managing your Strategy Position immediately.
    • If the Account Position does not match your Strategy Position, NinjaTrader will submit a market order(s) to reconcile the Account Position to match your Strategy Position. The strategy will then begin managing your Strategy Position immediately.

      * A previously generated order is considered to match an active strategy order when the order action, order type, quantity, limit price, and stop price are exactly identical.


    As mentioned in the help guide, if the historical orders do not match real-time orders made previously they are cancelled.

    If you want to ensure that your strategy resumes the previously placed orders and positions with the 'Immediately submit' setup, you will need to ensure that the historical trades match the real time trades.

    Adding intra-bar granularity can help with this.

    When in historical data, only the Open, High, Low, an Close will be available and there will be no intra-bar data. Intra-bar granularity adds a second data series such as a 1 tick series so that the strategy has finer granularity in the historical data in between the OHLC of the primary series. This allows for more accurate trades.

    If the strategy was running in real-time with Calculate set to 'On price change' or 'On each tick', it would be recommended to enable TickReplay so that any indicators that may have been updating in real-time and whom's values are used in conditions that trigger orders can also update historically for each tick or price change.

    Below is a link to an official reference sample that demonstrates how to add intra-bar granularity.
    http://www.ninjatrader.com/support/f...ead.php?t=6652

    Also, here is a link to the differences on real-time vs backtest (historical).
    http://ninjatrader.com/support/helpG...ime_vs_bac.htm

    As well as a link to the help guide on the AddDataSeries() method.
    http://ninjatrader.com/support/helpG...dataseries.htm

    A link to the help guide on BarsInProgress.
    http://ninjatrader.com/support/helpG...inprogress.htm

    And a link to the help guide on Multi-Time Frame & Instruments. Please see the section 'How Bar Data is Referenced', and 'Accessing the Price Data in a Multi-Bars NinjaScript'.
    http://ninjatrader.com/support/helpG...nstruments.htm

    And a link to another forum post that describes intra-bar granularity with a 1 tick series, TickReplay, and High Order Fill resolution in more detail.
    https://ninjatrader.com/support/foru...297#post491297

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

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by inanazsocial, Today, 01:15 AM
    1 response
    5 views
    0 likes
    Last Post NinjaTrader_Jason  
    Started by rocketman7, Today, 02:12 AM
    0 responses
    10 views
    0 likes
    Last Post rocketman7  
    Started by dustydbayer, Today, 01:59 AM
    0 responses
    1 view
    0 likes
    Last Post dustydbayer  
    Started by trilliantrader, 04-18-2024, 08:16 AM
    5 responses
    23 views
    0 likes
    Last Post trilliantrader  
    Started by Davidtowleii, Today, 12:15 AM
    0 responses
    3 views
    0 likes
    Last Post Davidtowleii  
    Working...
    X