Reset Trailing Stop
Printed From: BullCharts Forum
Category: BullCharts
Forum Name: BullScript
Forum Discription: Technical discussion related specifically to the BullScript programming language.
URL: http://www.bullcharts.com.au/forum/forum_posts.asp?TID=579
Printed Date: 24 Apr 2025 at 2:00am Software Version: Web Wiz Forums 9.69 - http://www.webwizforums.com
Topic: Reset Trailing Stop
Posted By: kmuntz
Subject: Reset Trailing Stop
Date Posted: 22 Sep 2009 at 9:28pm
I am using the BullCharts indicator ATR Inital Stop (by Leon Wilson). This stop is a specified number of ATRs below the close. It can only rise, not fall ie. if today's calculation is less than the previous calculation then the previous calculation is used. I would like to modify this indicator so that when the stop is hit (close < stop value) the indicator resets - it recalculates to today's value. In other words it's as if the start date starts from the day the stop was hit. Does anyone have any idea how to do this in BullScript?
Here is the code (slightly simplified) that I want to modify: TDate:=InputDate("Date of trend", date(2004,6,25)); Value1:=Input("ATR Range X",4.5,1); Value2:=Input("ATR Periods",20,3);
HoldingDays:=BarsSince(OnOrSkipped(TDate)); Stop:=CLOSE-(Value1*ATR(Value2)); ValueB := If(Stop>PREV(undefined),Stop,If(Stop<=PREV(undefined),PREV(undefined),Stop*Holdingdays));
|
Replies:
Posted By: maximo
Date Posted: 22 Sep 2009 at 11:59pm
Hi kmuntz and welcome to the Forum. I have modified it to do that, though left the previous non retreating line in dotted, so both levels are visible. You can simply remove
the last 2 lines of code if you only want the (close < stop value) line.
[target =price]
TDate:= InputDate("Date of trend", date(2009,2,10));
Value1:= Input("ATR Range X",3,1);
Value2:= Input("ATR Periods",20,3);
HoldingDays:= BarsSince(OnOrSkipped(TDate));
Stop:= CLOSE-(Value1*ATR(Value2));
ValueB := If(Stop>PREV(undefined),Stop,If(Stop<=PREV(undefined),PREV(undefined),Stop*Holdingdays));
if (Close<ValueB or LLV(C,2)<ValueB,LLV(Stop,8),ValueB);
[linestyle =dotted]
ValueB;
|
Posted By: maximo
Date Posted: 06 Dec 2009 at 6:03pm
A simple more efficient version.
Mult:= Input("ATR Multiplier",2,1);
Nb:= Input("Nb Periods",14,1);
HH := Close-Mult*ATR(Nb);
[target =price; color=black; linestyle=solid;]
if (HH<prev and close>prev,prev,HH);
|
Posted By: kmuntz
Date Posted: 23 Dec 2009 at 3:28pm
I only just discovered this reply - many thanks it works well. I was having trouble coming to grips with the "prev" function at the time
|
|