Red alert, stop trading

Discussion in 'Automated Trading' started by nooby_mcnoob, Feb 23, 2018.

  1. Hi,

    Let's say your algorithm goes haywire and starts doing crazy things, or the market is going crazy and your algorithm is responding in unexpected ways. Let's say you have multiple algorithms running with Interactive Brokers.

    You want to shut down all trading and liquidate. How would you do this? I know some brokers have the ability to disable trader IDs, so that's a good step 1 (not sure if Interactive Brokers has this). How would I liquidate as step 2?
  2. I have scripts that I can run to pause all trading (which wouldn't liquidate), another to close everything etc. That assumes the IB API and my execution code are still working.

    Next fail safe: If you are using the IB gateway and you can open a 'web trader' or TWS session then your IB gateway will stop working. Can be annoying, but an advantage here. Then I guess you manually close everything through the web trader.

    rtw likes this.
  3. I was actually thinking to do this exact thing. Low tech, but guaranteed to work... Thanks!
  4. Also I suppose you could also write a script to loop through positions and liquidate after logging into web trader.

    My worry is not being near a computer when the need hits so I think I will likely write such a thing and test it once in a while.
  5. My trading server is local so I can always pull the plug*, but if you're on some cloud machine you may not have this option...


    * it's under my desk and I have sometimes kicked it out accidentally, or one of my kids has decided their laptop needs plugging in instead....
    nooby_mcnoob likes this.
  6. Hah! This is exactly why I'm running in the cloud. My kids reboot my machine to play games on Windows all the time.

    There's a bunch of infrastructure I've already automated behind it so it's already on the cloud. I know I can reliably shut down the infrastructure with one command, analogous to your plug, I suppose the next thing is to reliably cancel any open orders, liquidate and lick my wounds (i.e., don't look at the account for a few days.)

    I'll do this manually for now until I am trading so many things that it becomes unwieldy.

    Is there a reason you don't run in the cloud already?
  7. DaveV


    IB TWS has a menu item that closes out all positions on the displayed tab. I am not sure, but this may work on the Open Positions Tab.
    nooby_mcnoob likes this.
  8. I verified this on TWS (desktop) but couldn't find it on the web version. Sadly looks like it's not possible from the browser, unless I missed it.
  9. Buy1Sell2


    Someone would be that over-leveraged that this type of fail-safe would be necessary?? If so, I recommend reexamining use of margin as your pre-trade safety valve.
  10. Imagine:

    1. You buy IBM at $100
    2. You enter a stop limit at $95
    3. It opens at $90..$88..$85
    4. Your stop may not fill (after all, you set a limit)

    And then imagine this happens in everything you're trading x 25.

    I see a fail safe as something let you trade again tomorrow in the event that you were drastically wrong in your expectations on how your algo performed. Not necessarily margin/leverage related.

    Above situation is completely unrelated, just thought I'd give an example.
    #10     Feb 23, 2018