Hi guys, I’m new here just tinkering around my setup until I have this problem.
I want to close out all short/long position when a condition is fulfilled and proceed with adding new long/short position at the same time. The problem is I have three different result when the code seemingly have the same logic. *or is it me?*
Below code give me below error when I want to prepare it for automated trading.
“Trading systems with orders that partially close a position cannot be sent to ProOrder”
This version 1 below gives me 400% return but code does not work as mentioned earlier.
IF c1 AND c2 AND c3 AND c4 AND c5 AND c6 AND c7 AND c8 THEN
BUY COUNTOFSHORTSHARES CONTRACT AT MARKET
BUY 5 CONTRACT AT MARKET
ENDIF
IF s1 AND s2 AND s3 AND s4 AND s5 AND s6 AND s7 AND s8 THEN
SELL COUNTOFLONGSHARES CONTRACT AT MARKET
SELLSHORT 5 CONTRACT AT MARKET
ENDIF
So I moved on to the version 2, the code works however it only give me 100% return.
IF c1 AND c2 AND c3 AND c4 AND c5 AND c6 AND c7 AND c8 THEN
BUY AT MARKET //to close out whatever short position i have
BUY 5 CONTRACT AT MARKET
ENDIF
IF s1 AND s2 AND s3 AND s4 AND s5 AND s6 AND s7 AND s8 THEN
SELL AT MARKET //to close out whatever long position i have
SELLSHORT 5 CONTRACT AT MARKET
ENDIF
So I went on with version 3, this code works as well but this time give me 300% return
IF c1 AND c2 AND c3 AND c4 AND c5 AND c6 AND c7 AND c8 THEN
IF (COUNTOFSHORTSHARES > 0) THEN
BUY AT MARKET //to close out whatever short position i have
ENDIF
BUY 5 CONTRACT AT MARKET
ENDIF
IF s1 AND s2 AND s3 AND s4 AND s5 AND s6 AND s7 AND s8 THEN
IF (COUNTOFLONGSHARES > 0) THEN
SELL AT MARKET //to close out whatever long position i have
ENDIF
SELLSHORT 5 CONTRACT AT MARKET
ENDIF
I like to be able to get back where i can have 400% return, but I do not understand why there are differences in the results from the three versions.
Appreciate it if any guru can help with this.
EJ
Found the solution. Replaced BUY AT MARKET with EXITSHORT. Still don’t understand the difference.
IF c1 AND c2 AND c3 AND c4 AND c5 AND c6 AND c7 AND c8 THEN
EXITSHORT AT MARKET//to close out whatever short position i have
BUY 5 CONTRACT AT MARKET
ENDIF
IF s1 AND s2 AND s3 AND s4 AND s5 AND s6 AND s7 AND s8 THEN
SELL AT MARKET //to close out whatever long position i have
SELLSHORT 5 CONTRACT AT MARKET
ENDIF
- To open a long position use BUY.
- To close a long position use SELL.
- To open a short position use SELLSHORT.
- To close a short position use EXITSHORT.
If you are long on the market then a SELLSHORT instruction will close all long positions.
If you are short on the market then a BUY instruction will close all short positions.
Partial closure of positions, for example: BUY 5 contracts then SELL 1 contract is possible only in backtesting. You cannot run a strategy live with partial closure at the moment in PRT.