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?
It seems a always loose profit bacuse tp/sl move too slow.
This system is wallstreet 15 min
StartPerCentLong = 0.6
StepPerCent = 30
BasePerCent = 0.2
PerCentInc = 0.1
Se attached picture how system got big gain MFE.
The 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.
I 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.
TIMEFRAME(15minutes)
Indicator1
Indicator2
Indicator3
Condition1
Condition2
Condition3
If ... THEN
Buy/SellShort
ENDIF
TIMEFRAME(1 minute)
Trailing system
I think that’s the mindset most use… A larger time frame for the signal and entry and a much smaller time frame for the trailing stop.
phoentzs
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
samsampop if you use TIMEFRAME(15 minutes, updateonclose) on a 1 min chart, it should give you the same result than TIMEFRAME(15 minutes, updateonclose) on a 15 min chart.
thanked this post
So 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) ).
thanked this post
What 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!
thanked this post
Bonjour Mr robertogozzi
merci 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 lire
merci 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.
@Marlaynicolas
Only 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 🙂
@Marlaynicolas
strategies 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.
Hi 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?
SPCL=0.65
SPCS=0.14
SPC=1.7
BPC=0.08
PCI=0.1
//------------------------------------------------------------------------------------------------------------------------------------------------
// Trailing Start
//------------------------------------------------------------------------------------------------------------------------------------------------
If trail then
DirectionSwitch = (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 Stop
StartPerCentShort = SPCS
StepPerCent = 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 BreakEven
PerCentInc = PCI // 0.1-1 PerCent increment after each StepSize chunk
//
TrailStartLong = (close / PipSize) * StartPerCentLong / 100 //use current price (CLOSE) for calculations
TrailStartShort = (close / PipSize) * StartPerCentShort / 100 //use current price (CLOSE) for calculations
StepSizeLong = TrailStartLong * StepPerCent / 100
StepSizeShort = TrailStartShort * StepPerCent / 100
//
RoundTO = -0.5 //-0.5 rounds always to Lower integer, +0.4 rounds always to Higher integer, 0 defaults PRT behaviour
PriceDistance = 8 * pipsize //7 minimun distance from current price
y1 = 0 //reset to 0
y2 = 0 //reset to 0
ProfitPerCent = BasePerCent //reset to desired default value
//PositionCount = 0
SellPrice = 0
SellPriceX = 0
ExitPrice = 9999999
ExitPriceX = 9999999
ELSE
//------------------------------------------------------
// --- 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 trailing
IF PositionPrice <> PositionPrice[1] AND (ExitPrice + SellPrice) <> 9999999 THEN //go on only if Trailing Stop had already started trailing
IF LongOnMarket THEN
q1 = PositionPrice + ((Close - PositionPrice) * ProfitPerCent) //calculate new SL
SellPriceX = 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 one
ELSIF ShortOnMarket THEN
r1 = PositionPrice - ((PositionPrice - Close) * ProfitPerCent) //calculate new SL
ExitPriceX = 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 one
ENDIF
ENDIF
// --- Update END
ENDIF
//
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 pips
IF x1 >= TrailStartLong THEN // go ahead only if N+ pips
Diff1 = abs(TrailStartLong - x1) //difference from current profit and TrailStart
Chunks1 = max(0,round((Diff1 / StepSizeLong) + RoundTO)) //number of STEPSIZE chunks
ProfitPerCent = BasePerCent + (BasePerCent * (Chunks1 * PerCentInc)) //compute new size of ProfitPerCent
ProfitPerCent = max(ProfitPerCent[1],min(100,ProfitPerCent)) //make sure ProfitPerCent doess not exceed 100%
y1 = max(x1 * ProfitPerCent, y1) //y1 = % of max profit
ENDIF
ELSIF 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 pips
IF x2 >= TrailStartShort THEN // go ahead only if N+ pips
Diff2 = abs(TrailStartShort - x2) //difference from current profit and TrailStart
Chunks2 = max(0,round((Diff2 / StepSizeShort) + RoundTO)) //number of STEPSIZE chunks
ProfitPerCent = BasePerCent + (BasePerCent * (Chunks2 * PerCentInc)) //compute new size of ProfitPerCent
ProfitPerCent = max(ProfitPerCent[1],min(100,ProfitPerCent)) //make sure ProfitPerCent doess not exceed 100%
y2 = max(x2 * ProfitPerCent, y2) //y2 = % of max profit
ENDIF
ENDIF
//------------------------------------------------------------------------------
// 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 THEN
SELL AT SellPrice STOP
ELSE
SELL AT SellPrice LIMIT
ENDIF
ELSE
//
//sell AT MARKET when EXITPRICE does not meet the broker's minimun distance from current price
//
SELL AT Market
ENDIF
ENDIF
IF 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 THEN
EXITSHORT AT ExitPrice STOP
ELSE
EXITSHORT AT ExitPrice LIMIT
ENDIF
ELSE
//
//ExitShort AT MARKET when EXITPRICE does not meet the broker's minimun distance from current price
//
EXITSHORT AT Market
ENDIF
ENDIF
Endif
Please post a working code with the details about the timeframe and istrument used and the candle where the incorrect trade started.
Hi @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.5
works
StepPerCent = 10
BasePerCent = 0.5
PerCentInc = 0.5
overshoots
StepPerCent = 25
BasePerCent = 0.5
PerCentInc = 0.2
works
StepPerCent = 10
BasePerCent = 0.5
PerCentInc = 0.2
overshoots
StepPerCent = 80
BasePerCent = 0.6
PerCentInc = 0.6
works
StepPerCent = 20
BasePerCent = 0.6
PerCentInc = 0.6
overshoots