How to scale out of a position in two steps?
Forums › ProRealTime English forum › ProOrder support › How to scale out of a position in two steps?
- This topic has 8 replies, 3 voices, and was last updated 5 years ago by
Sascha.
-
-
09/21/2020 at 8:29 PM #144915
Hi,
How can I scale out of a position in two steps? I want to sell the first half of my position at two times my initial risk and the second half I want to sell if I have two closes below the 8 Exponential Moving Average. The basic code (only part of the entire code) I want this two step exit apply to is below.
12345678910111213//--------------LONG:if (LongSetups AND LFiveDayCond55 AND NOT LongNoEntry AND NOT Events AND NOT Sun AND NOT Fri AND NOT LongOnMarket) thenISL = 10000*(close-lowest[2](low) + LBuffer)TradeRisk = pipvalue*ISLContractSize = 100/TradeRiskBUY ContractSize SHARES AT market// Stops and targetsSET STOP LOSS (close-lowest[2](low) + LBuffer)SET TARGET PROFIT (close-lowest[2](low) + LBuffer)*2ENDIFThank you.
09/21/2020 at 9:12 PM #144919Partial closure of positions is not allowed in real AutoTrading, only in bscktests.
1 user thanked author for this post.
09/21/2020 at 9:23 PM #14492009/21/2020 at 9:59 PM #144923You can accumulate positions (going the same directions), but you cannot keep them separate.
There can only be one SL and one TP.
The price is only one, POSITIONPRICE, an average price of the different TradePrices.
To accumulate positions you need to use:
1DEFPARAM CUMULATEORDERS = truethen simply execute as many BUY or SELLSHORT you need.
Countofposition will return the positive number of Long positions or the negative number of Short positions accumulated so far. You can use ABS() to make all of them positive.
09/21/2020 at 11:09 PM #144926Thank you!
So it looks like the only way to create what I want (to optimize the profit ) is to have two separate accounts, one in which I use a fixed price target for the first position, and a second account where I can use a trailing stop loss.
I hope ProRealTime will add this feature in future.
09/22/2020 at 12:35 AM #144930ProRealTime HAS this feature, unfortunately IG doesn’t!
But we do all hope this will be supported.
09/22/2020 at 12:51 AM #14493309/22/2020 at 9:07 AM #144957looks like the only way to create what I want
You can run 2 separate identical Algos on the same IG Account.
If you are clever enough at coding you likely could use ‘simulated trades’ to determine when the conditions in your first post are met and so have each Algo react accordingly?
https://www.prorealcode.com/blog/learning/how-to-improve-a-strategy-with-simulated-trades-1/
09/22/2020 at 1:15 PM #144988Thank you GraHal! I’ll take a look at the article.
The challenge is that it’s hard to know when a market is going to trend in a strong way so that a trailing stop loss is better to maximize profit, or when the market is just moving the average move and a fixed profit target is better.
Another idea I had yesterday night is simply to have two separate identical Algos running in the same account with each having half the position size and one is having a fixed profit target and the other is using a trailing stop loss.
1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on