ATR trailing stop HHV

Identifying resistance levels using the explorer has always been difficult. This is because support and resistance is easier to see visually on a chart than it is to explain in mathematical terms. My solution was to allow a little leeway in the formula which is explained below. As a result the search works quite well.

Please don’t be put off by all the details in this email, it’s not that complicated, in fact the entire process should take no longer than 5 minutes.

To add this search to your copy of MetaStock, open the explorer and click “new”.

Give your new exploration the name “Stocks near resistance level”

In the notes box type “Looking for stocks close to or touching resistance levels”.

Just like last week, we need to put some values in the alphabetical columns.

Again these codes are very simple, they tell MetaStock to return a value of “one” if a chart has had a peak at the same price level, or a value of “zero” if did not. This scan is using both a 10% and 15% zigzag to gauge where the peaks have occurred. As mentioned above, I have allowed a bit of leeway to this rule. I ask MetaStock to allow stocks to pass this filter if their peak is within 6% of a prior peak.

The next step is to copy and paste the following code into each of the alphabetical tabs, starting with column.

First type “Close” into the small “col. A Name” box. Then copy and paste the below formula into Column A:

Close

Then type “Ave Vol$” into the small “col. B Name” box. Then copy and paste the below formula into Column B:

Mov[CLOSE,100,S]*Mov[VOLUME,100,S]

Then type “10peak+2” into the small “col. C Name” box. Then copy and paste the below formula into Column C:

If[Peak[2,C,10] > HHV[CLOSE,100]*.96,1,0]

Then type “10peak+3” into the small “col. D Name” box. Then copy and paste the below formula into Column D:

If[Peak[3,C,10] > HHV[CLOSE,100]*.96,1,0]

Then type “10peak+4” into the small “col. E Name” box. Then copy and paste the below formula into Column E:

If[Peak[4,C,10] > HHV[CLOSE,100]*.96,1,0]

Then type “10peak-2” into the small “col. F Name” box. Then copy and paste the below formula into Column F:

If[Peak[2,C,10] < HHV[CLOSE,100]*1.04,1,0]

Type “10peak-3” into the small “col. G Name” box. Then copy and paste the below formula into Column G:

If[Peak[3,C,10] < HHV[CLOSE,100]*1.04,1,0] Type “15Peak+2” into the small “col. H Name” box. Then copy and paste the below formula into Column H: If[Peak[2,C,15] > HHV[CLOSE,100]*.97,1,0]

Type “15Peak+3” into the small “col. I Name” box. Then copy and paste the below formula into Column I:

If[Peak[3,C,15] > HHV[CLOSE,100]*.97,1,0]

Type “15Peak+4” into the small “col. J Name” box. Then copy and paste the below formula into Column J:

If[Peak[4,C,15] > HHV[CLOSE,100]*.97,1,0]

Type “15Peak-2” into the small “col. K Name” box. Then copy and paste the below formula into Column K:

If[Peak[2,C,10] < HHV[CLOSE,100]*1.03,1,0]

Type “15Peak-3” into the small “col. L Name” box. Then copy and paste the below formula into Column L:

If[Peak[3,C,15] < HHV[CLOSE,100]*1.03,1,0] Lastly copy and paste this into the filter box: CLOSE > HHV[CLOSE,100]*.96 AND colB>100000 AND colC+colD+colE+colF+colG=5 OR

CLOSE > HHV[CLOSE,100]*.96 AND colB>100000 AND colH+colI+colJ+colK+colL=5

So how does the scan work?

The alphabetical columns are going to calculate and display a value. The value will be either one or zero depending on whether we have a peak within 6% of the peak that took place before. Just like last week “one” means yes, and “zero” means no.

The filter simply says that we need three peaks to be within 6% of each other.

If you look at the formula, you will notice the values are either being multiplied by .97 or by 1.03. This is to allow the 6% tolerance. In other words it’s ok to be either 3% below or 3% above the previous value.

It’s easy to alter this tolerance, for example change the filter to:

If[Peak[1,C,15] > HHV[CLOSE,100]*.90,1,0]

This simply says that it’s ok to be 10% below the prior peak.

I was going through below pinescript code of ATR Trailing Stop loss indicator and was trying to code it in Python. I'm facing difficulty understanding below lines.

Prev = H,barssince[close>H and close>close[1]] TS = iff[cum[1] H and close>close[1],H,Prev]]

Value H gives you the highest value [highest[high-Mult*atr[Atr],Hhv]]. On next line, barsince function is giving the count of bars/candles when conditions were met.

What does the complete statement H,barssince signifies? I mean what value will be stored in Prev.

Also what cum[1] function does?

//@version=4 study["ATR Trailing Stoploss",overlay=true] Atr = 3 // input[defval=5,title="Atr Period",minval=1,maxval=500] Hhv= 10 // input[defval=10,title="HHV Period",minval=1,maxval=500] Mult= 2.5 // input[defval=2.5,title="Multiplier",minval=0.1] Barcolor=input[true,title="Barcolor"] H = highest[high-Mult*atr[Atr],Hhv] Prev = H,barssince[close>H and close>close[1]] TS = iff[cum[1] H and close>close[1],H,Prev]] Color=iff[close>TS,color.green,iff[close

Chủ Đề