Can we use different Stop Loss and/or targets for different positions
Forums › ProRealTime English forum › ProOrder support › Can we use different Stop Loss and/or targets for different positions
- This topic has 6 replies, 2 voices, and was last updated 4 years ago by Vonasi.
-
-
05/16/2020 at 6:27 AM #131843123456789101112131415161718DEFPARAM CumulateOrders = TrueIF b1 THENBUY Bet1 CONTRACT AT MARKETcurrentTarget = ProfitTargetcurrentStopLoss = StopLossENDIF// Stop e targetProfitCon = (high >= currentTarget)IF ProfitCon THENSELL AT MARKETENDIFLossCon = (close <= currentStopLoss)IF LossCon THENSELL AT MARKETENDIF
Dear All,
I was wondering whether we can attach different stop loss and targets to individual positions.
I’ve tried with the code attached and also using SET STOP and SET TARGET but proOrder uses the latest stop/limit condition for all the open positions.
Thank you,
Renzo
05/16/2020 at 7:17 AM #131846The answer is yes and no. PRT can handle partial position closure at different levels by using STOP and LIMIT orders but IG do not allow partial position closure via automated strategies so at the moment we can only do it in back tests and running a strategy live with real money or in demo is not possible.
https://www.prorealcode.com/documentation/stop-pending/
https://www.prorealcode.com/documentation/limit/
05/16/2020 at 7:23 AM #131848Thank You Vonasi,
I actually don’t want to close partial positions.
I would like to open a position with its own stop and limit and while still live open a new position with different stop and limit.
I understand that PRT applies the latest stop and limit to all the open positions. I would like to know whether there is a workaround.
Thanks
05/16/2020 at 7:51 AM #131850I actually don’t want to close partial positions.
I would like to open a position with its own stop and limit and while still live open a new position with different stop and limit.
You just described adding to a position and then partial closure of that combined position so you do want partial closure.
If you use SET STOP and SET TARGET instructions then whatever distance you choose will be applied to all opened positions from their entry price – so yes they will all have different closing prices but they cannot have different distances. You can do this in live trading.
If you use pending STOP and LIMIT orders then you can set orders at whatever price you like but you cannot use this in live trading unless you close all positions at the chosen price. In back testing you can close part of your combined position – but only in backtest.
05/17/2020 at 7:22 AM #131903Hi Vonasi,
I understand what you mean now.
Though, I’ve tried wit the code attached and it keep changing all the orders (limi and stop) to the latest values of my ProfitTarget and StopLoss.
Thank you for your kind help,
Renzo
1234567IF b1 THENBUY Bet1 CONTRACT AT MARKETcurrentTarget = ProfitTargetcurrentStopLoss = StopLossSELL Bet1 CONTRACT AT ProfitTarget LIMITSELL Bet1 CONTRACT AT S3 STOPENDIF05/17/2020 at 7:34 AM #13190405/17/2020 at 8:19 AM #131907When using pending STOP and LIMIT orders you must make sure that they are placed at every bar because they only last for one bar. In your code they are only placed at the entry bar.
Also unlike SET STOP and SET TARGET orders they require a price and not a distance.
We have to also consider that at the time we place our buy order we do not know the exact price that it will get filled at but after one bar we do.
If you want to control different positions with different levels then you will need different stop loss and take profit variables for each position. I haven’t ever bothered to code something like that because we can’t use it in real life because IG consider two positions of 1 to be one position of 2 and won’t let us close half of it using pending orders.
1234567891011121314IF not onmarket and b1 THENBUY Bet1 CONTRACT AT MARKETcurrentTarget = close + ProfitTargetcurrentStopLoss = close - StopLossSELL Bet1 CONTRACT AT ProfitTarget LIMIT //initial order based on closing price because we don't know what price we will get filled at.SELL Bet1 CONTRACT AT currentStopLoss STOP //initial order based on closing price because we don't know what price we will get filled at.ENDIFif onmarket thencurrentTarget = tradeprice + ProfitTargetcurrentStopLoss = tradeprice - StopLossSELL Bet1 CONTRACT AT ProfitTarget LIMIT //order at price calculated from the price our buy order got filled atSELL Bet1 CONTRACT AT currentStopLoss STOP //order at price calculated from the price our buy order got filled atendif -
AuthorPosts
Find exclusive trading pro-tools on