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
Once trailingstop=undefined
StartDate = 20120713 //YYYYMMDD
EntryPrice = 22.64
InitialATR = AverageTrueRange[10](close) * 2
TrailATR = AverageTrueRange[10](close) * 3
IF date = StartDate THEN
TrailingStop = EntryPrice - InitialATR
ENDIF
IF close > TrailingStop THEN
NewTStop = close - TrailATR
IF NewTStop > TrailingStop THEN
TrailingStop = NewTStop
ENDIF
ENDIF
return TrailingStop COLOURED(255,0,0)as "ATR Trailing Stop"
I’ve tried a few things but I’m not great at loops
If Close<TrailingStop THEN
TrailingStop = TrailingStop[1]
ENDIF
That 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.
Not tested, but this code should work as intended:
Once trailingstop=undefined
StartDate = 20120713 //YYYYMMDD
EntryPrice = 22.64
InitialATR = AverageTrueRange[10](close) * 2
TrailATR = AverageTrueRange[10](close) * 3
IF date = StartDate THEN
TrailingStop = EntryPrice - InitialATR
ENDIF
//test if close has touch the trailing stop line
if low crosses under trailingstop then
flag=1
endif
IF close > TrailingStop THEN
NewTStop = close - TrailATR
IF NewTStop > TrailingStop and flag<>1 THEN
TrailingStop = NewTStop
ENDIF
ENDIF
return TrailingStop COLOURED(255,0,0)as "ATR Trailing Stop"
Thanks 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.
Once TrailingStop=undefined
StartDate = 20170519 //YYYYMMDD Enter Start Date
EntryPrice = 0// Enter Entry Price - Leave as Zero to use close
if EntryPrice = 0 THEN
Entry = Close //Select your default entry price
Else
Entry = EntryPrice
ENDIF
InitialATR = AverageTrueRange[10](close) * 2
TrailATR = AverageTrueRange[10](close) * 3
IF date = StartDate THEN
TrailingStop = Entry - InitialATR
ENDIF
//test if close has touch the trailing stop line
if close crosses under trailingstop then
flag=1
endif
IF close > TrailingStop THEN
NewTStop = close - TrailATR
IF NewTStop > TrailingStop and flag<>1 THEN
TrailingStop = NewTStop
ENDIF
ENDIF
return TrailingStop COLOURED(255,0,0)as "ATR Trailing Stop"
You can use OpenDate too.