No announcement yet.

How do I reverse a position in eSignal v12.7?

  • Filter
  • Time
  • Show
Clear All
new posts

  • How do I reverse a position in eSignal v12.7?

    Write something.
    Last edited by odgo; 09-07-2017, 03:42 AM.

  • #2
    Say I am long 2 contracts crude oil and I want to reverse that position and be short 1 contract crude oil. How would I accomplish this? In previous versions of eSignal (v10, v11 & earlier v12) I could place an order to sell 3 contracts which, when filled, would leave me short 1 contract. Problem solved! Now, however, any attempt to sell 3 contracts leads to a fatal blow-up in the EFS-AT script and generates an error message informing me that I am trying to cover a position that is larger than the position I actually own. But before blowing up, the EFS-AT actually sends the order (in my case) to Interactive Brokers and IB executes the order in routine fashion. Minimally, if eSignal identifies this order type for reversing positions as improper, it should blow up before transmitting the order. But more to the point, EFS-AT should not have trouble with this order. It is a single order that accomplishes my goal. Any other means that I can think of would require two separate orders, which is inefficient and possibly costly. (I am aware that the Trade Object includes a method Trade.reversePosition() to reverse positions, but this method requires that the reversed position be the same size as the original position).


    • #3
      Would this be in backtesting or in EFS Automation?

      Essentially the process is the same for both. First, you would close the LONG position then open the SHORT position.

      In backtesting, you would do this...

      PHP Code:
      // Close LONG
      Strategy.doSell("Long Exit"Strategy.LIMITStrategy.THISBARStrategy.ALLclose());

      // Open Short
      Strategy.doShort("Short Entry"Strategy.LIMITStrategy.THISBAR1close()); 
      In LIVE TRADING MODE, you would use the following commands. But you would need to develop "process control" to allow the live broker to complete these steps before moving onto the next step.

      PHP Code:
      // Close all open trades and positions for a trading symbol
      // whereas _Symbol represents the trading symbol and _Account represents the trading account

      // Remember, you have to wait for the broker to complete this request (which may take seconds or minutes to complete) before you can fire the new Short Entry order. You would setup a timer based process to wait 5~10 seconds (or until the broker reports that it is completely FLAT for that trading symbol), then end the checking process and move onto the new Short Entry trigger.

      // to Go Short, you would use...
      // whereas _TIF = 1 (or another valid Time In Force value) 
      If you need assistance in writing this type of project, let me know?

      Last edited by bmatheny; 10-10-2017, 09:20 AM.