trailing stops to all positions after they hit a combined profit?
Forums › ProRealTime English forum › ProOrder support › trailing stops to all positions after they hit a combined profit?
- This topic has 6 replies, 3 voices, and was last updated 5 years ago by bartjawien.
Tagged: trailingstop
-
-
04/17/2019 at 9:23 AM #96661
Hey guys. I’m keen to understand how to reset or add new trailing stops to all positions that are running after they hit a combined profit margin. Here is a some code in working with;
123456789//Max profit variableMaxProfit=3500 //Max profit allowed (in money)// Test the current floating profit and close orders if neededFloatingProfit = (((close-positionprice)*pointvalue)*countofposition)/pipsize //actual trade gainsif FloatingProfit>=MaxProfit thenSET STOP $TRAILING 500endifWill the Set Stop apply a $500 Trailing Stop all positions?
04/18/2019 at 8:21 AM #96742No. Because the stop will only be in place when FloatingProfit equals 3500 exactly. A very rare thing I imagine. You need to set a flag when price >= 3500 and then only have the trailing stop in operation if that flag is set. Otherwise the trailing stop only works if price goes from >= all the way down to your stop price in one bar. Reset the flag to zero if price falls below your stop level.
04/24/2019 at 3:43 PM #97056Thanks @Vonasi,
Here’s a real snippet I’m testing at the moment across a few pairs and it seems to work sometimes and not others – what am I getting wrong?
1234567891011121314// test the current floating profit and close orders if neededFloatingProfit = (((close-positionprice)*pointvalue)*countofposition)/pipsize //actual trade gainsif FloatingProfit > 1500 and floatingprofit <2500 thenSET STOP PTRAILING 10endifif FloatingProfit > 2501 and floatingprofit <5000 thenSET STOP PTRAILING 5endifif FloatingProfit > 5001 and floatingprofit <8000 thenSET STOP PTRAILING 4endifif FloatingProfit > 8001 thenSET STOP PTRAILING 3endifI’ve been monitoring it on the AUD/USD and it triggered fine. However, miss fires on the USD/CAD. Could it not be converting to the AUD for the total gain for all running positions? I’m expecting the FloatingProfit to be calculated in AUD for all open position for that individual system …
Keen to hear your thoughts guys.
04/24/2019 at 3:53 PM #97057The pointvalue instruction, use to calculate the floating profit, is in the currency of the current instrument, not in the currency of your account, because there is no way to get it through code. You’ll have to make a conversion yourself in the code for that.
04/24/2019 at 4:13 PM #97061Thanks again,
So the code looks correct?
The instrument I’ve been testing on is the USD/CAD where the system calculates the gain for open positions in CAD. Do you mean I’ll have to code a conversation back into AUD which what I believe you’re saying?
As for the terminology for the system ‘latent gain’ and ‘today gain’ I’m not looking to calculate the total latent gain for the system for all time.
All I’m looking to test is:
My system opens short and long position, and if the combined open and running positions hit a certain value a trailing stop is activated for all running positions. If the positions are then stopped-out because the market reversed — next time the system opens a new set of positions the floatingprofit will start from zero.
Apologies if I’m not explaining myself properly.
Thoughts?
05/13/2019 at 11:14 PM #98409Hey @Nicolas – I’ve been testing the above and recently found a flaw in my code;
1234567891011// test the current floating profit and close orders if neededFloatingProfit = (((close-positionprice)*pointvalue)*countofposition)/pipsize //actual trade gainsif FloatingProfit > 50 and floatingprofit <150 thenSET STOP PTRAILING 4endifif FloatingProfit > 151 and floatingprofit <250 thenSET STOP PTRAILING 2endifif FloatingProfit > 251 thenSET STOP PTRAILING 1endifOne of these functions is calculating the total gain value for the system rather than only the current open positions;
(close-positionprice)*pointvalue)*countofposition)/pipsize
The solution or advice I’m looking for is to find a way to reset the floatingprofit at each new position open. Is there a function to do this?
Would this work … subtracting the system profit using strategyprofit function from the total accumalative floatingprofit:
FloatingProfit = Strategyprofit – (((close-positionprice)*pointvalue)*countofposition)/pipsize //actual open trade gains
Thanks in advance.
Bart
05/13/2019 at 11:54 PM #98410Sorry –
Would this work … subtracting the system profit using strategyprofit function from the total accumalative floatingprofit:
FloatingProfit = Strategyprofit – (((close-positionprice)*pointvalue)*countofposition)/pipsize //actual open trade gains
Sorry – should be the otherway around;
FloatingProfit = ((((close-positionprice)*pointvalue)*countofposition)/pipsize) – Strategyprofit //actual open trade gains
-
AuthorPosts
Find exclusive trading pro-tools on