Trailing Stop AFL

TJW

New Member
#1
Hi, could someone guide me to code to be able to reflect stops as follows:

1. The initial stop is just below the last significant trough.

2. Each time the price makes a new high for the trend by rising above
the last peak, the sell stop level for the whole position is trailed up to just
below the last significant confirmed trough

This is shown as per the attached.

Stop level.png

The idea is taken from Colin Nicholson's book Building Wealth in The Stock Market.

Any help will be appreciated.
 
#2
Hi

These Swing Highs and Lows don't declare themselves as hi/lo when they are being made, high/low is relative to the future price action that will follow this event.
Once you take this into account, you need to decide how many bars in your time frame you will wait to declare a new swing high/low.


Thanks
Happy :)
 

TJW

New Member
#3
Hi

These Swing Highs and Lows don't declare themselves as hi/lo when they are being made, high/low is relative to the future price action that will follow this event.
Once you take this into account, you need to decide how many bars in your time frame you will wait to declare a new swing high/low.


Thanks
Happy :)
Thanks for your consideration.

What I am looking at is to view a trend showing higher highs and higher lows. When that trend has presented I anticipate setting my trailing stop at the last low between to current high and the previous high.

As to coding, well I am fairly comfortable in setting a define period, but where the period is flexible I don't know how to approach the question.
 
#4
Many ways of doing that, all of them have issues . . . :)

Most of them looking into future . . .

Don't have time to go into it in detail here, but if you search you will find many many discussions on that here on the forum

anyway one of the commonly shared codes to find & mark PH/PL . . .

Code:
_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 
_SECTION_END();


_SECTION_BEGIN("Pivots");

GraphXSpace = 5; 
dist = 0.5*ATR(10); 

PH= ValueWhen(
(Ref(H,-2) > Ref(H, -4)) AND
(Ref(H,-2) > Ref(H, -3)) AND
(Ref(H,-2) > Ref(H, -1)) AND
(Ref(H,-2) > H), Ref(H,-2));

PL= ValueWhen(
(Ref(L,-2) <= Ref(L, -4)) AND
(Ref(L,-2) <= Ref(L, -3)) AND
(Ref(L,-2) <= Ref(L, -1)) AND
(Ref(L,-2) <= L), Ref(L,-2));


Plot(PH, "UpPivot", colorRed, styleStaircase,0,0,-2);
Plot(PL, "DownPivot",colorGreen, styleStaircase,0,0,-2);

/*
Plot(SelectedValue(PH), "",  colorRed, styleNoLabel|styleDashed,0,0,12);
Plot(SelectedValue(PL), "",colorGreen, styleNoLabel|styleDashed,0,0,12);

for (a=4;a<BarCount;a++)
{
if ((H[a-2] >= H[a-4]) AND
(H[a-2] >= H[a-3]) AND
(H[a-2] >= H[a-1]) AND
(H[a-2] >= H[a]))
PlotText("PH", a-2, H[a-2], colorGreen);

if ((L[a-2] <= L[a-4]) AND
(L[a-2] <= L[a-3]) AND
(L[a-2] <= L[a-1]) AND
(L[a-2] <= L[a]))
PlotText("PL", a-2, L[a-2]-dist[a-2], colorRed);
}
*/
_SECTION_END();

Thanks
Happy :)
 

Similar threads

Broker Special Offers

Intraday Higher Leverage

Save up to 90% in brokerage and get higher leverage for intraday trades.

Name:Phone:
Email:City:
State:
Are you a day trader?