Hello,
Does anyone know how to scan the highest high and lowest low cycle frequency is getting shorter or longer? Please see attached picture.
I would like to find a timestamp (say X1, X2, X3,,,,,) for each highest high and lowest low. Then (X2 – X1) can tell us how long it took to make each price cycle. By comparing (X2 – X1) and (X3 – X2), I can say whether the price cycle is getting longer or shorter.
Regards,
Try this (not tested):
p = 40
x3 = highest[p](high)
x2 = highest[p](high[p])
x1 = highest[p](high[p * 2])
For i = (p*3)-1 downto (p*2)
if high[i] = x1 then
b1 = BarIndex[i]
Break
Endif
Next
For i = (p*2)-1 downto p
if high[i] = x2 then
b2 = BarIndex[i]
Break
Endif
Next
For i = p-1 downto 0
if high[i] = x3 then
b3 = BarIndex[i]
Break
Endif
Next
x1x2 = b2 - b1
x2x3 = b3 - b2
x = 0
If x1x2 > x2x3 then
x = 1
Elsif x1x2 < x2x3 then
x = 2
Endif
Screener[x](x as “1=x1x2, 2=x2x3")
The new instruction HighestBars could help in this case.
This is the code with the new instruction suggested by Nicolas:
p = 40
b3 = highestbars[p](high)
b2 = highestbars[p](high[p])
b1 = highestbars[p](high[p * 2])
x1x2 = b2 - b1
x2x3 = b3 - b2
x = 0
If x1x2 > x2x3 then
x = 1
Elsif x1x2 < x2x3 then
x = 2
Endif
Screener[x](x as “1=x1x2, 2=x2x3")
Thank you very much for your swift reply. I have been tucking to understand the following part of the previously mentioned solution by dissecting the last few days. However, I am still stuck with understanding the below:
b3 = highestbars[p](high) b2 = highestbars[p](high[p])
I understand “b3 = highestbars[p](high),” but I am not sure if I understand “b2 = highestbars[p](high[p]).” Why :[p](high[p]?” Why “p” in those two places?
In order to dissect and understand them on cash 500, ticker “SPTRD,” I program them to print out the code with two variable periods “p1” and “p2.”
p1=4
p2=4
b3 = highestbars[p1](high)
DRAWTEXT("#b3#", barindex, high+range*2, Dialog, Standard, 10) COLOURED(255,0,0)
b2 = highestbars[p1](high[p2])
//DRAWTEXT("#Hp2#", barindex, high+range*0.6, Dialog, Standard, 12)
DRAWTEXT("#b2#", barindex, high+range*1.4, Dialog, Standard, 12)COLOURED(0,0,0)
b1 = highestbars[p1](high[p2 * 2])
//x1x2 = b2 - b1
//x2x3 = b3 - b2
//x = 0
//If x1x2 > x2x3 then
//x = 1
//Elsif x1x2 < x2x3 then
//x = 2
//Endif
return
If anyone can possibly rephrase them in words, I would highly appreciate it very much.
This line will check a highest value among the latest p bars (from 0 to 39):
highestbars[p](high)
you need two prior additional ones to find all the three, one between bars 40-79 and the leftmost one between bars 80-119.
You can evaluate the expressions within brackets to check that.
p1=170
p2=170
pM1=170
Hip=211
b3 = highestbars[p1](high)
//DRAWTEXT("#b3#", barindex, high+range*2, Dialog, Standard, 10) COLOURED(255,0,0)
Hp2=high[p2]
b2 = highestbars[p1](high[p1])
//DRAWTEXT("#Hp2#", barindex, high+range*0.6, Dialog, Standard, 12)
//DRAWTEXT("#b2#", barindex, high+range*1.4, Dialog, Standard, 12)COLOURED(0,0,0)
b1 = highestbars[p1](high[p1 * 2])
//DRAWTEXT("#b1#", barindex, high+range*0.7, Dialog, Standard, 12)COLOURED(0,0,255)
x1x2 = b2 - b1
x2x3 = b3 - b2
x = 0
If x1x2 > x2x3 then
M1 = x1x2 - x2x3
HiM1=highest[pM1](M1)
DRAWTEXT("▇", barindex, 1.001*highest[Hip](high), Dialog, Standard, 12)COLOURED(0,0,255, 255*M1/HiM1)
x = 1
Elsif x1x2 < x2x3 then
M2 = -x1x2 + x2x3
HiM2=highest[pM1](M2)
DRAWTEXT("▇", barindex, 1.002*highest[Hip](high), Dialog, Standard, 12)COLOURED(0,0,0, 255*M2/HiM2)
x = 2
Endif
return