Trailing Stop Formula
Forums › ProRealTime English forum › ProBuilder support › Trailing Stop Formula
- This topic has 5 replies, 2 voices, and was last updated 7 years ago by Nicolas.
-
-
06/15/2017 at 7:48 AM #38315
I’m trying to write a trailing stop formula. I have managed to make it plot on the chart but I have a few questions.
- In PRT if I want to edit custom parameters like for instance the date or the ATR multiplier am I able to display that in the Price Settings screen alongside the width and style or do I have to got to Price Settings-Indicator -Modify Indicator to do that?
- How can I edit the formula so that if price closes below the trailing stop then the trailing stop will just stay at that current level and will not rise even if price keeps rising. (Its stops trailing and just goes horizontal at its current level)
- Is there a way to alter the date format so that it is DDMMYYYY
Thanks
1234567891011121314151617181920212223Once trailingstop=undefinedStartDate = 20120713 //YYYYMMDDEntryPrice = 22.64InitialATR = AverageTrueRange[10](close) * 2TrailATR = AverageTrueRange[10](close) * 3IF date = StartDate THENTrailingStop = EntryPrice - InitialATRENDIFIF close > TrailingStop THENNewTStop = close - TrailATRIF NewTStop > TrailingStop THENTrailingStop = NewTStopENDIFENDIFreturn TrailingStop COLOURED(255,0,0)as "ATR Trailing Stop"06/15/2017 at 8:43 AM #38316- You’ll always need to go into the indicator settings in order to change any parameter of a custom indicator
- Not sure to understand but you could “flag” a variable if the price crosses under the TrailingStop level and test if this flag is not true in your conditional statement to move your TS (lines 15 to 22)
- Not possible, the default date format is YYYYMMDD
1 user thanked author for this post.
06/15/2017 at 9:45 AM #38319I’ve tried a few things but I’m not great at loops
123If Close<TrailingStop THENTrailingStop = TrailingStop[1]ENDIFThat probably doesn’t work because it would only work until price closed back above the trailing stop.
I’m trying to make the stop stay horizontal like the green line that I have drawn on this chart.
06/15/2017 at 10:18 AM #38325Not tested, but this code should work as intended:
123456789101112131415161718192021222324Once trailingstop=undefinedStartDate = 20120713 //YYYYMMDDEntryPrice = 22.64InitialATR = AverageTrueRange[10](close) * 2TrailATR = AverageTrueRange[10](close) * 3IF date = StartDate THENTrailingStop = EntryPrice - InitialATRENDIF//test if close has touch the trailing stop lineif low crosses under trailingstop thenflag=1endifIF close > TrailingStop THENNewTStop = close - TrailATRIF NewTStop > TrailingStop and flag<>1 THENTrailingStop = NewTStopENDIFENDIFreturn TrailingStop COLOURED(255,0,0)as "ATR Trailing Stop"1 user thanked author for this post.
06/15/2017 at 11:32 AM #38337Thanks for that. I would never have got that !!
I’ve added a default “entryprice” so that if entryprice is left as zero then it will use the current bars close.
I’ve noticed that PRT doesn’t show the correct closing date for each weekly bar. The last 3 dates displayed are 5 June, 29 May and 22 May. If I set the trail startdate to those dates it wont plot. Why are the dates wrong? I have to go to a calendar to get the correct date for last Friday.
12345678910111213141516171819202122232425262728293031Once TrailingStop=undefinedStartDate = 20170519 //YYYYMMDD Enter Start DateEntryPrice = 0// Enter Entry Price - Leave as Zero to use closeif EntryPrice = 0 THENEntry = Close //Select your default entry priceElseEntry = EntryPriceENDIFInitialATR = AverageTrueRange[10](close) * 2TrailATR = AverageTrueRange[10](close) * 3IF date = StartDate THENTrailingStop = Entry - InitialATRENDIF//test if close has touch the trailing stop lineif close crosses under trailingstop thenflag=1endifIF close > TrailingStop THENNewTStop = close - TrailATRIF NewTStop > TrailingStop and flag<>1 THENTrailingStop = NewTStopENDIFENDIFreturn TrailingStop COLOURED(255,0,0)as "ATR Trailing Stop"06/15/2017 at 12:22 PM #38340 -
AuthorPosts
Find exclusive trading pro-tools on