EXITING LONG AND SHORT POSITIONS
Forums › ProRealTime English forum › ProOrder support › EXITING LONG AND SHORT POSITIONS
- This topic has 15 replies, 3 voices, and was last updated 2 years ago by egyptiantrader.
-
-
09/20/2021 at 8:37 PM #178002
I’m trying to work out the best wat to exit from long and short positions, there seems to be multiple ways to do this and when I back test they produce wildly different results.
To enter a short position I can use SELL or SELLSHORT (which one is best)
Once I’m in a short position I can use BUY OR EXIT SHORT
IF c4 THEN
EXITSHORT AT MARKET
ENDIFor
IF c4 THEN
BUY AT MARKET
ENDIFAlso when I add SHORTONMARKET when using the BUY command to exit a short position this changes the back test result massively when I’d expect it to be the same?
IF c4 AND SHORTONMARKET THEN
BUY AT MARKET
ENDIFI must be be missing something about these commands? Please can someone explain.
09/20/2021 at 9:00 PM #178003- BUY opens a Long position
- SELL exits a Long position
- SELLSHORT opens a Short position
- EXITSHORT exits a Short position
you have no choice.
1 user thanked author for this post.
09/20/2021 at 9:13 PM #178005Thank you.
Why can’t I use BUY to exit a short position? Isn’t this the same as EXIT SHORT? I now it produces some very different results
09/20/2021 at 10:29 PM #178006You can’t because each one of the above keywords is devoted to only one task.
1 user thanked author for this post.
09/21/2021 at 3:51 AM #178007Why can’t I use BUY to exit a short position? Isn’t this the same as EXIT SHORT? I now it produces some very different results
Hi – You sure can, but you’d have to know what you are doing, hence keep track of your current positions very well. Thus, if you are 1 Long, you can SellShort 1 and end up with 0. But if the same SellShort 1 command runs into the situation that you don’t have a position, the result will be 1 short.
Similarly, if you have 1 Long and SellShort 2, you end up with 1 short.1IF c4 AND SHORTONMARKET THENNow you’ll understand why this makes a vast difference, and why you should always precede your Buy / Sell commands with determining the current situation (If LongOnMarket – If ShortOnMarket).
Also notice that
1Sell at Marketand
1ExitShort at Marketthus without a quantity, exit the whatever position regardless. You would normally use those, but still first would need to wonder (appropriate If) whether you have the position of concern (Long vs Short respectively).
Peter
1 user thanked author for this post.
09/21/2021 at 6:14 AM #178009“if you have 1 Long and SellShort 2, you end up with 1 short“
no, you will end up with 2 short positions. Sellshort when a long position is open (as well as Buy when a short position is open) will do a Stop & Reverse, so:
- the open position is entirely closed
- the new position is entirely opened
no math is done on the different positions.
1 user thanked author for this post.
09/21/2021 at 8:29 AM #178035Thanks guys. I’ve still got a lot of learning to do.
09/21/2021 at 8:41 AM #178041“if you have 1 Long and SellShort 2, you end up with 1 short“ no, you will end up with 2 short positions. Sellshort when a long position is open (as well as Buy when a short position is open) will do a Stop & Reverse, […]
Hi Roberto – Interesting. So you are saying that if I have 1 Long and virtually sell 2, I end up with 2 Short ? Thus my transaction of 2 ends up as a transaction with 3 ? It would be a largest bug ever, so that can’t be what you mean.
You are correct on your #1 and #2 and about the “no math”.09/21/2021 at 8:42 AM #178042Thanks guys. I’ve still got a lot of learning to do.
No worries. Me too. 🙂
1 user thanked author for this post.
09/21/2021 at 8:48 AM #178045If you are Long with 1 position and want to go short with 2, then you’ll end up being short with 2.
Why 3?
If you are already Short 1 position and SELLSHORT 2 positions, then you will end up with 3 positions (provided DEFPARAM CumulateOrders = TRUE).09/21/2021 at 9:35 AM #17805209/21/2021 at 9:52 AM #178054I think this is what IG enables you to do with multiple strategies with opposite positions opened, you can enable to group them (for a given instrument), thus they will do some math.
This is not the case with PRT, as opposite positions cannot be opened.
Try this:1234567891011a = 1 + (Day MOD 4 = 0)b = 1 + (Day MOD 5 <> 0)Sma = average[100,0](close)IF close CROSSES OVER Sma THENBUY a CONTRACTS AT MarketELSIF close CROSSES UNDER Sma THENSELLSHORT b CONTRACTS AT MarketENDIFgraph CountOfPositiongraph agraph b09/21/2021 at 10:42 AM #178060This is not the case with PRT, as opposite positions cannot be opened.
Correct, but opposite positions are not in order (they are not the subject).
I made an example too, which is hopefully the most clear for everybody.
1234567891011121314151617181920212223// Demonstration of Long 1 vs SellShort 2.Defparam Preloadbars = 20 // Otherwise the first trade is outside of the chart.If BarIndex > 20 then // For better visibility in the left hand side of the chart.Once BoughtOnce = 0 // We do it one time only, for clarity.IF Not BoughtOnce and NOT LongOnMarket thenBUY 100 CONTRACTS AT MARKET// This one (in green) shows one bar only because at the next bar we'll sell it via Short 2.BoughtOnce = 1ENDIFIf LongOnMarket then // So this too will occur one time only.SELLShort 2 Contracts AT MARKET// These two (in red) stay Short forever because we don't Exit them.ENDIFGraph countoflongshares coloured(0,255,0,255) // Green.Graph countofshortshares coloured(255,0,0,255) // Red.Endif09/21/2021 at 10:58 AM #178065I’m on IG so maybe this was causing some of my problems with results all over with small changes to the code that I expected not to make any difference?
09/21/2021 at 3:20 PM #178070FYI, the result on IG is exactly the same (the previous was IB) :
1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on