Bar by Bar Trailing Stop
Forums › ProRealTime English forum › ProOrder support › Bar by Bar Trailing Stop
- This topic has 7 replies, 3 voices, and was last updated 1 year ago by Ringo.
-
-
06/18/2023 at 11:51 AM #216413
Hello,
I am trading only stocks and I try to add a bar by bar trailing stop to my position.
At the moment the stop managment looks like this: Entry / SL 20cents / Move SL to Break Even when position is up 25 cents / Take profit at +32 cents
I would like to replace the Take profit with a BbB trailing stop, means when the current bar closes on a new 5 period high, the stop goes under this closed bar.
Code:
// Stops und Targets: Legen Sie hier schützende Stops und Profit Targets fest
SET STOP LOSS 0.20
SET TARGET PROFIT 0.32IF LONGONMARKET THEN
IF HIGH-Tradeprice >= 0.25 THEN
SET STOP BREAKEVEN
ENDIF
ENDIFThanks for help
Regards André
06/18/2023 at 12:54 PM #216415Hi, Try this trailing stop…
Trailing Stop1234567891011121314151617181920212223242526StopLoss = 23 //StopLoss sizeTrailingStopStart = 0 //Trailing Stop start at X points in profitbuystoploss = close-StopLoss*pointsizesellstoploss = close+StopLoss*pointsizeif not onmarket thenibuystoploss=buystoplossisellstoploss=sellstoplossendifif longonmarket then//checking and adjusting stoplossif close-tradeprice>=trailingstopstart*pointsize thenibuystoploss = max(ibuystoploss,high-(stoploss+trailingstopstart)*pointsize)endif//set the stoploss levelsell at ibuystoploss stopendifif shortonmarket then//checking and adjusting stoplossif tradeprice-close>=trailingstopstart*pointsize thenisellstoploss = min(isellstoploss,low+(stoploss+trailingstopstart)*pointsize)endif//set the stoploss levelexitshort at isellstoploss stopendif1 user thanked author for this post.
06/18/2023 at 2:18 PM #21641806/18/2023 at 5:57 PM #216424without the Breakeven Term it must be like this:
BbB= High[0]-Low[0] + 0.01
// Stops und Targets: Legen Sie hier schützende Stops und Profit Targets fest
SET STOP LOSS 0.20IF LONGONMARKET AND Close[0] > Highest[5] (High[1]) THEN
Set Stop Price High[0] – BbB
ENDIFIF SHORTONMARKET AND Close[0] < Lowest[5] (Low[1]) THEN
Set Stop Price Low[0] + BbB
ENDIF06/19/2023 at 12:48 AM #216429Try appending these lines to your code:
1234567891011121314IF Not OnMarket THENStopPrice = 0ELSEIF PositionPerf > 0 THENIF LongOnMarket THENIF close > high[1] THENStopPrice = max(StopPrice,low)SET STOP PRICE StopPriceENDIFENDIFENDIFENDIFgraphonprice TradePricegraphonprice StopPrice coloured("Red")1 user thanked author for this post.
06/19/2023 at 6:31 AM #216433Hi
I’ve modified the original trailing stop to your terms…
Ringo TSL1234567891011121314151617181920212223242526272829StopLoss= xSLif not onmarket thenbuystoploss = close-StopLosssellstoploss = close+StopLossibuystoploss=buystoplossisellstoploss=sellstoplossendifif longonmarket then//checking and adjusting stoplossif High>Highest[5](High[1]) and High>High[1] thenibuystoploss = (Highest[5](High[1])-StopLoss)endifendifif shortonmarket then//checking and adjusting stoplossif Low<Lowest[5](Low[1]) and Low < Low[1] thenisellstoploss = (Lowest[5](Low[1])+StopLoss)endifendif//set the stoploss levelsell at ibuystoploss stopexitshort at isellstoploss stopGraphOnPrice Highest[5](High[1]) coloured("red")GraphOnPrice Lowest[5](Low[1]) coloured("Blue")1 user thanked author for this post.
06/19/2023 at 2:42 PM #21647611/04/2023 at 9:39 PM #223209Hello,
following question regarding my code for a BE and then trailing stop:
The code works fine so far. But I have the problem, that , if condition 2 is fullfilled and it comes to a trailing stop, the first BE +0,01 Stop also remains in the system. How can I delete the first BE +0,01 stop, after condition 2 is fullfilled?
Thanks for help
//Manage Long Position / BE Stop / Bar by Bar Trail Outside Candle
IF LONGONMARKET THEN
//Breakeven SL at +0,20
IF StopPrice = 0 AND High – TRADEPRICE >= 0.20 THEN
StopPrice = TRADEPRICE +0.01
ENDIF
//Bar by Bar Trail Outside Candle
IF StopPrice > 0 AND Close > Highest[5] (High[1]) THEN
StopPrice = Low -0.01
ENDIF
ENDIF -
AuthorPosts
Find exclusive trading pro-tools on