• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Fail-safe to closing position.

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

    Fail-safe to closing position.

    I need a Fail-safe to close all positions no matter what happened.
    Once the conditions are met, I would like the strategy to close, double
    check and keep trying until those positions are really close.

    Anything could fail: a broker could decline to close and there may be connection issue etc.

    Code:
    protected override void OnStateChange()
    {
         if (State == State.SetDefaults)     {         Slippage = 9999999999;     } }
    How could I strengthen the below Closing?
    Somehow these do not look enough.

    Code:
    protected override void OnBarUpdate()
    {    
                     if (
                        //condition is met
                        )
                    {
                    ExitLong(0,Quantity,"EURUSD","");
                    ExitShort(1,Quantity,"GBPUSD","");        
                    }  
    }

    #2
    Hello johnnybegoode,

    Generally, you would use the OnOrderUpdate and OnExecutionUpdate events to ensure your order's process through all the way if you are trying to ensure they worked. However, the situations you have highlighted (disconnect, rejected order) are generally items which are going to cause it to recalculate or stop the strategy.

    https://ninjatrader.com/support/help...=onorderupdate
    https://ninjatrader.com/support/help...ub=onexecution

    You can choose what happens for a disconnect in the options menu:
    https://ninjatrader.com/support/help...riptProperties

    This does not specifically help with controlling the position, but this is a decision you would need to make in contrast to how you have programmed the script. In most cases recalculate would be used, if you don't want anything to happen and just try to resume where it was you could use keep running. After the reconnect, you could check the order states, position, and other items you need to further control the strategy.
    For connection losses, you can also see the OnConnectionStatusUpdate override: https://ninjatrader.com/support/help...tusupdate.htm?zoom_highlightsub=connection

    Rejections will stop the strategy however you can add handling for this. it is generally not recommended as this will further complicate the logic needed but this is another option. The default handling is most often sufficient for most use cases, it entails that default behavior is to stop the strategy, cancel any remaining working orders, and then close any open positions managed by the strategy by submitting one "Close" order for each unique position.

    https://ninjatrader.com/support/help...ightsub=reject

    I look forward to being of further assistance.

    JesseNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by TikDaddy, Today, 02:08 PM
    3 responses
    10 views
    0 likes
    Last Post TikDaddy  
    Started by Brillo, Today, 01:52 PM
    1 response
    14 views
    0 likes
    Last Post NinjaTrader_Jim  
    Started by TazoTodua, 02-09-2018, 08:40 AM
    10 responses
    883 views
    0 likes
    Last Post NinjaTrader_JoshG  
    Started by TazoTodua, Yesterday, 04:35 AM
    6 responses
    18 views
    0 likes
    Last Post eDanny
    by eDanny
     
    Started by MattP, Today, 12:25 PM
    1 response
    10 views
    0 likes
    Last Post NinjaTrader_PatrickG  
    Working...
    X