BreakEven & Trailing Profit: complete function
Forums › ProRealTime English forum › ProOrder support › BreakEven & Trailing Profit: complete function
- This topic has 119 replies, 22 voices, and was last updated 7 months ago by robertogozzi.
Tagged: BreakEven, Profit, stop, trailing, trailingstop
-
-
02/15/2022 at 12:47 PM #188288
My guess is that you ran in to the same problem I did. If you have too high start, base and increase (in some combination), it becomes a trailing take profit after an increase.
Im running 3M timeframe. Is There a range a values thats i not should use i combination?
Would u like to give an example?
02/17/2022 at 1:55 PM #18839502/17/2022 at 2:49 PM #188398The trail has to move slowly enough to allow it, at least occasionally, to reach the target. It’s the only way you can offset the fact that it will also, occasionally, go all the way to the Stop.
If you want to take lots of small profits, you would have to have a fairly small SL … which means lots of small losses as well.
I find that Roberto’s trail generally moves more quickly and captures more MFE than most (compared to % or ATR), but it’s all in the settings.
You can make it go faster if you want, but you won’t necessarily get a better result.
02/25/2022 at 4:25 PM #188838I didn’t follow the discussion from the begining. I see from your 17 Feb. post that you’re running DJ on 15 min TF. If all your code is run on a 15 min chart then your Trailing System will update the SL/TP, etc. every 15 min… depending on the volatility, many things can happen in 15 min including losing all your profits or even worse going from +100pts to -100pts (on DJ it’s very easy). If this 15 min graph assumption is correct, then you might want to try to run your trailing system on 1 min TF and keep the rest on 15 min TF and put everything on 1 min chart. In this case, the Trailing System will update every minute and you can capture more profits before retracement.
Suggestion12345678910111213141516TIMEFRAME(15minutes)Indicator1Indicator2Indicator3Condition1Condition2Condition3If ... THENBuy/SellShortENDIFTIMEFRAME(1 minute)Trailing system02/25/2022 at 6:36 PM #18884402/28/2022 at 12:28 PM #189022phoentzs
Hello phoentzs
I’m keen to explore this notion further on PRT, I have used shorter timeframes on other platforms but not on PRT. My understanding though is that the timeframe that the algo runs on is the lowest you can go down to. So if it runs on a 15min chart then the algo cannot be 5 or 1 min. I find this frustrating as I’m forced to use other options which aren’t as good.
How do you solve for this please? Thanks very much
02/28/2022 at 12:33 PM #18902702/28/2022 at 12:43 PM #189031So if it runs on a 15min chart then the algo cannot be 5 or 1 min
15min, 5min, 3min and 1 min can be combined in the same Algo.
15min and 4 min cannot be combined in the same Algo … due to 15min not divisible by 4 (min) ).
1 user thanked author for this post.
02/28/2022 at 12:54 PM #189037What samsampop wants to achieve is to have a 15-minute chart displayed, with the strategy using ALSO 1-miute, or 5-minute, timeframes.
This is not possible as the PRT platform executes strategies when a bar closes, so it would still access the 1-minute or 5-minute code only once every 15 minutes!
1 user thanked author for this post.
05/17/2022 at 3:26 PM #193329Bonjour Mr robertogozzimerci pour votre création de break even que j’utilise dans mes algo.J’ai remarqué que lorsque mon trade est parti et qu’il arrive au TrailStart défini à 10 par exemple il redescend et mon stop n’ai pas monté. Est ce que c’est normal ? Je crois comprendre que le stop sera remonté à la cloture de la bougie avec votre formule c’est bien ca?Je voudrais pouvoir le déplacer en cours de bougie est ce possible parce que je m’aperçois que je rate beaucoup de tardes .Dans l’attente de vous liremerci encore.Hello Mr robertogozzi thank you for your creation of break even that I use in my algo. I noticed that when my trade left and it arrives at the TrailStart defined at 10 for example it goes down and my stop did not go up. Is it normal ? I understand that the stop will be raised to the close of the candle with your formula is that right? I would like to be able to move it during the candle, is this possible because I realize that I miss a lot of delays. Looking forward to reading from you, thank you again.
05/17/2022 at 3:38 PM #193331Only post in the language of the forumthat you are posting in. For example English only in the English speaking forums and French only in the French speaking forums,
Thank you 🙂
05/17/2022 at 3:41 PM #193332strategies are only executed at the closing of each candle, but you can take advantage of the Multi Time Frame support to use a lower TF, such as 5 minutes or 1 minute.
05/30/2022 at 8:00 AM #194169Hi Roberto.
This morning my SL was a secured win. Then market moved in a favoured direction and trailinprofit apered,but now SL is not secured win any more.
I would like SL to stay secured win. How can i do this?
12345SPCL=0.65SPCS=0.14SPC=1.7BPC=0.08PCI=0.1123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129//------------------------------------------------------------------------------------------------------------------------------------------------// Trailing Start//------------------------------------------------------------------------------------------------------------------------------------------------If trail thenDirectionSwitch = (LongOnMarket AND ShortOnMarket[1]) OR (LongOnMarket[1] AND ShortOnMarket) //True when there's been a change in the direction (likely to be due to a Stop & Reverse)//IF Not OnMarket OR DirectionSwitch THEN//// when NOT OnMarket or thare's been a change in direction, reset values to their default settings//StartPerCentLong = SPCL //0.25% to start triggering Trailing StopStartPerCentShort = SPCSStepPerCent = SPC //50% (of the 0.25% above) as a Trailing Step (set to 100 to make StepSize=TrailStart, set to 200 to make it twice TrailStart)BasePerCent = BPC //0.1-1 Profit percentage to keep when setting BreakEvenPerCentInc = PCI // 0.1-1 PerCent increment after each StepSize chunk//TrailStartLong = (close / PipSize) * StartPerCentLong / 100 //use current price (CLOSE) for calculationsTrailStartShort = (close / PipSize) * StartPerCentShort / 100 //use current price (CLOSE) for calculationsStepSizeLong = TrailStartLong * StepPerCent / 100StepSizeShort = TrailStartShort * StepPerCent / 100//RoundTO = -0.5 //-0.5 rounds always to Lower integer, +0.4 rounds always to Higher integer, 0 defaults PRT behaviourPriceDistance = 8 * pipsize //7 minimun distance from current pricey1 = 0 //reset to 0y2 = 0 //reset to 0ProfitPerCent = BasePerCent //reset to desired default value//PositionCount = 0SellPrice = 0SellPriceX = 0ExitPrice = 9999999ExitPriceX = 9999999ELSE//------------------------------------------------------// --- Update Stop Loss after accumulating new positions//------------------------------------------------------//PositionCount = max(PositionCount,abs(CountOfPosition))//// update Stop Loss only when PositionPrice has changed (actually when increased, we don't move it if there's been some positions exited)////IF PositionCount <> PositionCount[1] AND (ExitPrice + SellPrice)<>9999999 THEN //go on only if Trailing Stop had already started trailingIF PositionPrice <> PositionPrice[1] AND (ExitPrice + SellPrice) <> 9999999 THEN //go on only if Trailing Stop had already started trailingIF LongOnMarket THENq1 = PositionPrice + ((Close - PositionPrice) * ProfitPerCent) //calculate new SLSellPriceX = max(max(SellPriceX,SellPrice),q1)SellPrice = max(max(SellPriceX,SellPrice),PositionPrice + (y1 * pipsize)) //set exit price to whatever grants greater profits, comopared to the previous oneELSIF ShortOnMarket THENr1 = PositionPrice - ((PositionPrice - Close) * ProfitPerCent) //calculate new SLExitPriceX = min(min(ExitPriceX,ExitPrice),r1)ExitPrice = min(min(ExitPriceX,ExitPrice),PositionPrice - (y2 * pipsize)) //set exit price to whatever grants greater profits, comopared to the previous oneENDIFENDIF// --- Update ENDENDIF//IF LongOnMarket AND Close > (PositionPrice + (y1 * pipsize)) THEN //LONG positions//// compute the value of the Percentage of profits, if any, to lock in for LONG trades//x1 = (Close - PositionPrice) / pipsize //convert price to pipsIF x1 >= TrailStartLong THEN // go ahead only if N+ pipsDiff1 = abs(TrailStartLong - x1) //difference from current profit and TrailStartChunks1 = max(0,round((Diff1 / StepSizeLong) + RoundTO)) //number of STEPSIZE chunksProfitPerCent = BasePerCent + (BasePerCent * (Chunks1 * PerCentInc)) //compute new size of ProfitPerCentProfitPerCent = max(ProfitPerCent[1],min(100,ProfitPerCent)) //make sure ProfitPerCent doess not exceed 100%y1 = max(x1 * ProfitPerCent, y1) //y1 = % of max profitENDIFELSIF ShortOnMarket AND Close < (PositionPrice - (y2 * pipsize)) THEN //SHORT positions//// compute the value of the Percentage of profits, if any, to lock in for SHORT trades//x2 = (PositionPrice - Close) / pipsize //convert price to pipsIF x2 >= TrailStartShort THEN // go ahead only if N+ pipsDiff2 = abs(TrailStartShort - x2) //difference from current profit and TrailStartChunks2 = max(0,round((Diff2 / StepSizeShort) + RoundTO)) //number of STEPSIZE chunksProfitPerCent = BasePerCent + (BasePerCent * (Chunks2 * PerCentInc)) //compute new size of ProfitPerCentProfitPerCent = max(ProfitPerCent[1],min(100,ProfitPerCent)) //make sure ProfitPerCent doess not exceed 100%y2 = max(x2 * ProfitPerCent, y2) //y2 = % of max profitENDIFENDIF//------------------------------------------------------------------------------// manage actual Exit, if needed//------------------------------------------------------------------------------IF y1 THEN //Place pending STOP order when y1 > 0 (LONG positions)SellPrice = max(SellPrice,PositionPrice + (y1 * pipsize)) //convert pips to price//// check the minimun distance between ExitPrice and current price//IF abs(close - SellPrice) > PriceDistance THEN//// place either a LIMIT or STOP pending order according to current price positioning//IF close >= SellPrice THENSELL AT SellPrice STOPELSESELL AT SellPrice LIMITENDIFELSE////sell AT MARKET when EXITPRICE does not meet the broker's minimun distance from current price//SELL AT MarketENDIFENDIFIF y2 THEN //Place pending STOP order when y2 > 0 (SHORT positions)ExitPrice = min(ExitPrice,PositionPrice - (y2 * pipsize)) //convert pips to price//// check the minimun distance between ExitPrice and current price//IF abs(close - ExitPrice) > PriceDistance THEN//// place either a LIMIT or STOP pending order according to current price positioning//IF close <= ExitPrice THENEXITSHORT AT ExitPrice STOPELSEEXITSHORT AT ExitPrice LIMITENDIFELSE////ExitShort AT MARKET when EXITPRICE does not meet the broker's minimun distance from current price//EXITSHORT AT MarketENDIFENDIFEndif05/30/2022 at 2:31 PM #194195Please post a working code with the details about the timeframe and istrument used and the candle where the incorrect trade started.
09/21/2022 at 8:27 PM #201171Hi @robertogozzi,
Is there a formula of what StepPerCent, PerCentInc and BasePerCent can be max?
I’ve noticed that some combinations overshoots the price and becomes a target instead of a trailing stop.
StepPerCent = 50
BasePerCent = 0.5
PerCentInc = 0.5works
StepPerCent = 10
BasePerCent = 0.5
PerCentInc = 0.5overshoots
StepPerCent = 25
BasePerCent = 0.5
PerCentInc = 0.2works
StepPerCent = 10
BasePerCent = 0.5
PerCentInc = 0.2overshoots
StepPerCent = 80
BasePerCent = 0.6
PerCentInc = 0.6works
StepPerCent = 20
BasePerCent = 0.6
PerCentInc = 0.6overshoots
-
AuthorPosts
Find exclusive trading pro-tools on