Write something.
Announcement
Collapse
No announcement yet.
How do I reverse a position in eSignal v12.7?
Collapse
X
-
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).
-
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.LIMIT, Strategy.THISBAR, Strategy.ALL, close());
// Open Short
Strategy.doShort("Short Entry", Strategy.LIMIT, Strategy.THISBAR, 1, close());
PHP Code:// Close all open trades and positions for a trading symbol
Trade.closeAndCancelAll(_Symbol, _Account);
// 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...
Trade.sellMarket(_Symbol, _Contracts, null, null, _TIF, null, _Account, null);
// whereas _TIF = 1 (or another valid Time In Force value)
Last edited by bmatheny; 10-10-2017, 10:20 AM.
Comment
Comment