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.
//--------------LONG:
if (LongSetups AND LFiveDayCond55 AND NOT LongNoEntry AND NOT Events AND NOT Sun AND NOT Fri AND NOT LongOnMarket) then
ISL = 10000*(close-lowest[2](low) + LBuffer)
TradeRisk = pipvalue*ISL
ContractSize = 100/TradeRisk
BUY ContractSize SHARES AT market
// Stops and targets
SET STOP LOSS (close-lowest[2](low) + LBuffer)
SET TARGET PROFIT (close-lowest[2](low) + LBuffer)*2
ENDIF
Thank you.
Partial closure of positions is not allowed in real AutoTrading, only in bscktests.
I assume I could open two separate positions and manage them independently, right?
How do I do this? Just doubling the code? And how do I setup up the trailing stop?
You 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:
DEFPARAM CUMULATEORDERS = true
then 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.
Thank 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.
ProRealTime HAS this feature, unfortunately IG doesn’t!
But we do all hope this will be supported.
I see. Thank you for clarifying.
looks 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/
Thank 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.