sey eeet
sey eeet

Reputation: 258

How to draw lines and check the degrees between certain highs and lows

Hello I have this simple code that tells me the where are the lows and highs

pHigh = (high[1] > high[2]) and (high <= high[1] )
pLow = (low[1] < low[2]) and (low >= low[1] )
plotshape(pHigh, style=shape.triangledown, location=location.abovebar, offset = -1)
plotshape(pLow, style=shape.triangleup, location=location.belowbar, offset = -1)

Can you please let me know how can I do this:

For each pLow I want to consider the pHighs and pLows in front of it and compute the degree, then if the degrees are equal 50 I draw lines.

eg. lets say there is a plow at bar_index[100], then I want to compute the degree between the the highest phigh between 1) the plow[100] and phigh[i] (100>i>=0) and 2) lowest low between the phigh[100] and plows[k] (k<i and k<100 and it is moving forward basically).

If the degree between the lines for every three points (plow[100], phigh[i], plow[k]) are 50 I want to draw a line like what I showed in the fig.

As we move ahead, the highest high between the plow and phigh[i] and lowest low between the phigh[i] and plows (from i forward , ie plow[k]) should be considered for checking the degree.

when computing the degrees we only draw lines if the degree is equal to 50. otherwise we ignore. enter image description here enter image description here enter image description here enter image description here enter image description here

Upvotes: 0

Views: 287

Answers (1)

Danila Boichenko
Danila Boichenko

Reputation: 41

consider pHighs and pLows before them as follows:

//@version=5
indicator("My script")
fHigh(hi) =>
    pHigh = (hi[1] > hi[2]) and (hi <= hi[1])
fLow(lo) =>
    pLow = (lo[1] < lo[2]) and (lo >= lo[1])

plotshape(fHigh(high), style=shape.triangledown, location=location.abovebar, offset = -1, color = color.red)
plotshape(fLow(low), style=shape.triangleup, location=location.belowbar, offset = -1)


bool pLowHigh = na
bool pLowLow = na
if fLow(low)
    pLowLow := fLow(low[1])
if fHigh(high)
    pLowHigh:= fHigh(high[1])

But with this definition pHigh and pLow it is not possible to calculate the degree and make further calculations, because they series bool.

You need to change the initial calculation pHigh and pLow, for they return series float

Upvotes: 2

Related Questions