ProRealCode - Trading & Coding with ProRealTime™
Hello, I’m new to ProRealTime and already see how powerful it is. I’d like help creating a breakout screener to find symbols that may be ready to break out. Maybe such an indicator already exists or something close that I can build on.
Goal: detect setups where price forms equal swing highs or lows (potential breakout zones).
This would be used for stocks.
Requirements:
There could be 3 or even more equal swings, which I would want to screen for, but for now just start with 2My goal is to automatically identify symbols on the chart that have unbroken equal highs or lows, which could signal potential future breakouts if the setup is valid — without manually checking too many symbols on a such small timeframe.
This is how pattern look like visually what screener must find ( attached screenshots)
N = 0.02 * Pipsize
Peak1 = (high[3] > high[4]) AND (high[4] > high[5]) AND (high[5] > high[6])
Peak2 = (high < high[1]) AND (high[1] < high[2]) AND (high[2] < high[3])
Peak = Peak1 AND Peak2
PeakSignal = 0
IF Peak THEN
PeakHigh = high[3]
PeakhBar = BarIndex[3*2]
IF round(abs(PeakHigh - PeakHigh[1]),2) <= N THEN
PeakSignal = max(PeakHigh,PeakHigh[1])
ENDIF
ENDIF
Trough1 = (low[3] < low[4]) AND (low[4] < low[5]) AND (low[5] < low[6])
Trough2 = (low > low[1]) AND (low[1] > low[2]) AND (low[2] > low[3])
Trough = Trough1 AND Trough2
TroughSignal = 0
IF Trough THEN
TroughLow = low[3]
TroughBar = BarIndex[3*2]
IF round(abs(TroughLow - TroughLow[1]),2) <= N THEN
TroughSignal = min(TroughLow,TroughLow[1])
ENDIF
ENDIF
IF PeakSignal THEN
DrawArrowDOWN(BarIndex[3],PeakSignal + Range[2]) coloured("Red")
DrawSegment(BarIndex,PeakSignal,PeakhBar,PeakSignal) style(line,2) coloured("Red")
ELSIF TroughSignal THEN
DrawArrowUP(BarIndex[3],TroughSignal - Range[2]) coloured("Green")
DrawSegment(BarIndex,TroughSignal,TroughBar,TroughSignal) style(line,2) coloured("Green")
ENDIF
RETURN
please check whether the arrows are plotted correctly.
This is the screener:
N = 0.02 * Pipsize
Peak1 = (high[3] > high[4]) AND (high[4] > high[5]) AND (high[5] > high[6])
Peak2 = (high < high[1]) AND (high[1] < high[2]) AND (high[2] < high[3])
Peak = Peak1 AND Peak2
Signal = 0
IF Peak THEN
PeakHigh = high[3]
IF round(abs(PeakHigh - PeakHigh[1]),2) <= N THEN
Signal = 2
ENDIF
ENDIF
Trough1 = (low[3] < low[4]) AND (low[4] < low[5]) AND (low[5] < low[6])
Trough2 = (low > low[1]) AND (low[1] > low[2]) AND (low[2] > low[3])
Trough = Trough1 AND Trough2
IF Trough THEN
TroughLow = low[3]
IF round(abs(TroughLow - TroughLow[1]),2) <= N THEN
Signal = 1
ENDIF
ENDIF
SCREENER[Signal AND (high <> low)](Signal AS "1=Up,2=Down")
Hello, thanks for your reply.
I first tried the indicator, but most of the time it doesn’t show anything on the chart. I even select charts with equal highs or lows on purpose, but the indicator doesn’t detect them. It only shows levels occasionally, and when it does, they don’t look correct or make sense. ( i atached screnshot)
I also tried the screener. Sometimes it finds one or two stocks, but I’m scanning all NASDAQ stocks — so that can’t be right, since there should always be some stocks with equal highs or lows.
so something wrong with indicator and screener.
I’m also not a professional programmer, and when I code I usually do it with the help of Claude. That’s how I was able to create indicators in TradingView, but i have limitations with TV, so this is why i try to use PRT here. To see if I can create screener there.
I would send a little longe explanation about what is my requirements, maybe someone can help here:
Understood: your core goal is only the screener.
Here is a very short spec you can paste that focuses purely on the screener side.
Goal
Create a ProScreener that, on a 1‑minute timeframe, finds symbols which today have at least one unbroken equal swing high or equal swing low at exact 1‑cent precision.
Swing logic (inside screener)
Equal highs / equal lows (strict 1 cent)
Unbroken condition (up to “now”)
What the screener should return
For each symbol, the screener should:
How dificult to create such screener in ProRealTime – or is it even possible?
It is possible.
A swing is made by the current bar reversing the direction, while the prior bar was in the opposite direction and one of the two swing bars must have hit a N-period highest/lowest price. If you do not agree with this, please specify it.
As to “Equal high: at least 2 swing highs today with the same rounded high” (the other way round, as well) do you mean the two swing highs/lows should be consecutive?
As to “After the last swing high that formed that level“, that level is the CLOSE, or else?
This is below the first draft to find and plot the segments between equal rounded price only in the current day.
Now I have to detect the breakout above or below to unset those segments.
The below code version plot segments between 2 tops or 2 bottoms only if price hasn’t breakout yet.
Please confirm the tops and bottoms detection before going further.
defparam drawonlastbaronly=false
if day<>day[1] or intradaybarindex=0 then
unset($peak)
unset($peakbar)
unset($trough)
unset($troughbar)
i=0
j=0
endif
Peak1 = (high[3] > high[4]) AND (high[3] > high[5]) AND (high[3] > high[6])
Peak2 = (high[3] > high[2]) AND (high[3] > high[1]) AND (high[3] > high[0])
Peak = Peak1 AND Peak2
if peak then
// drawpoint(barindex[3],high[3],2) coloured("cyan")
$peak[i]=high[3]
$peakbar[i]=barindex[3]
i=i+1
endif
Trough1 = (low[3] < low[4]) AND (low[3] < low[5]) AND (low[5] < low[6])
Trough2 = (low[3] < low[2]) AND (low[3] < low[1]) AND (low[3] < low[0])
Trough = Trough1 AND Trough2
if Trough then
//drawpoint(barindex[3],low[3],2) coloured("crimson")
$trough[j]=low[3]
$troughbar[j]=barindex[3]
j=j+1
endif
if islastbarupdate then
if i>0 then
for k = 0 to i-1 do
drawpoint($peakbar[k], $peak[k],2) coloured("cyan")
for l = 0 to i-1 do
if $peakbar[l]<>$peakbar[k] then
diff = abs(round($peak[l],2) - round($peak[k],2))
if diff = 0 then //equal price
//find breakout
period = max(1,max($peakbar[l],$peakbar[k]) - min($peakbar[l],$peakbar[k]))
decay = max(1,barindex-max($peakbar[l],$peakbar[k]))
hh = highest[period](high)[decay]
//drawpoint(max($peakbar[l],$peakbar[k]),hh,5) coloured("green")
if hh<=max($peak[l],$peak[k]) then //no breakout at that time
drawsegment($peakbar[l],$peak[l], $peakbar[k], $peak[k]) coloured("cyan")
endif
endif
endif
next
next
endif
if j>0 then
for k = 0 to j-1 do
drawpoint($troughbar[k], $trough[k],2) coloured("crimson")
for l = 0 to i-1 do
if $troughbar[l]<>$troughbar[k] then
diff = abs(round($trough[l],2) - round($trough[k],2))
if diff = 0 then //equal price
//find breakout
period = max(1,max($troughbar[l],$troughbar[k]) - min($troughbar[l],$troughbar[k]))
decay = max(1,barindex-max($troughbar[l],$troughbar[k]))
ll = lowest[period](low)[decay]
if ll>=min($trough[l],$trough[k]) then //no breakout at that time
drawsegment($troughbar[l],$trough[l], $troughbar[k], $trough[k]) coloured("crimson")
endif
endif
endif
next
next
endif
endif
return //period, decay coloured("orange")
Please note that the points and segments are plotted only for the current day. So if any tops or bottoms are not equal (rounded 2 digits) during the day, nothing is plotted. If you have any valid examples please post them.
Hi Roberto,
Thanks for confirming it’s possible!
Regarding your questions:
1- Swing definition: Your definition isn’t quite what I need. I want a 3-left/3-right pattern where:
There is no matter direction of candle, close green or red – doesn’t matter. only highs and lows matter.
2- No consecutive swings: the equal swing highs/lows do not need to be consecutive. They can occur anywhere during today’s session.
3- The level is the actual high/low of candles , not the close. So:
I will try explain in simpler words, maybe it would be more helpful for me ( to clarify, and for you guys that are helping me)
1- so first is needed is to corectly identify swings( or pivot points) – there is indicator in Tradingview that is great for that it’s called “Pivots Points High Low” and is ideal for identification swings. In the setting I can chose how much left and right i want it to identify swings- i choose 3 and send screnshot how it looks
This indicator is excatly how i want swing to be identified
here is code:
here is code
//@version=6
indicator("Pivot Points High Low", shorttitle="Pivots HL", overlay=true, max_labels_count=500)
lengthGroupTitle = "LENGTH LEFT / RIGHT"
colorGroupTitle = "Text Color / Label Color"
leftLenH = input.int(title="Pivot High", defval=10, minval=1, inline="Pivot High", group=lengthGroupTitle)
rightLenH = input.int(title="/", defval=10, minval=1, inline="Pivot High", group=lengthGroupTitle)
textColorH = input(title="Pivot High", defval=color.black, inline="Pivot High", group=colorGroupTitle)
labelColorH = input(title="", defval=color.white, inline="Pivot High", group=colorGroupTitle)
leftLenL = input.int(title="Pivot Low", defval=10, minval=1, inline="Pivot Low", group=lengthGroupTitle)
rightLenL = input.int(title="/", defval=10, minval=1, inline="Pivot Low", group=lengthGroupTitle)
textColorL = input(title="Pivot Low", defval=color.black, inline="Pivot Low", group=colorGroupTitle)
labelColorL = input(title="", defval=color.white, inline="Pivot Low", group=colorGroupTitle)
ph = ta.pivothigh(leftLenH, rightLenH)
pl = ta.pivotlow(leftLenL, rightLenL)
drawLabel(_offset, _pivot, _style, _color, _textColor) =>
if not na(_pivot)
label.new(bar_index[_offset], _pivot, str.tostring(_pivot, format.mintick), style=_style, color=_color, textcolor=_textColor)
drawLabel(rightLenH, ph, label.style_label_down, labelColorH, textColorH)
drawLabel(rightLenL, pl, label.style_label_up, labelColorL, textColorL)
2- then i want to know ( screener/indicator to identify) is there on chart a pivot points at the same price (2 swings at the same price)
here on chart of AAPLE there is 2 examples of this
(attached screnshot with orange circles)
3- Next filter is I want to see only equal swings that price is not broke, or not crossed yet.
As you can see equal highs at price 279.05 that was identified previously, price already crossed.
but there is on today chart is equal swing lows at 278.50 that are unbroken/uncrossed.
And that is main goal, i want screener to screen for stocks that :
Hope this makes more sense.
Thank you guys for helping, didn’t saw this much help in other community before.
This pivot code reflects exactly how are detected pivots in the code of my previous post. It is just basic Williams Fractals. Did you try it? The same exact levels as your examples were detected. I bet we are near of what you expect?
So if i’m not wrong, we want to give alerts if screener detect an unbroken 2 points high or low (examples attached with dotted line in cyan), Apple and Bank Of America. Right?
Hi Nicolas,
Thanks for your reply.
The “points and segments only for the current day” part is perfect – that’s exactly what I wanted and where i had problems previously
I’ve attached more screenshots, especially for AAPL. I’m a bit confused by the red/blue dots that mark swings: in some places where the 3‑left / 3‑right rule should give a swing, there is no dot. I tried to explain this directly on the chart.
So I’m not sure whether: the indicator is missing some valid swings, or it just does’nt draw them ?
My questions:
And there is also a correctly identified lines, but i see that some of them alreay broken.
So again
Yes- your last answer is exactly correct
On your last screenshots you can see that the indicator missed some swings on both tickers It doesn’t identify all swings as the TradingView indicator I showed you, so there is a clear difference in swing detection between the two.
For me it doesn’t matter will it draw dots on swings or not.
The main thing is that when they turn out to be the same equal , he doesn’t miss them.
There was indeed a small error in finding the low points in the last code. Please understand that this indicator is a proof of concept and not a finished product, given the complexity of the request and our own interpretation in logic code. I understand that the points are not important to you; they are simply a visual aid to help us understand and debug. Without these points, how would we have known that they were missing swing lows?
Below is the latest version. Here I’ve plotted all the detections. However, only the thresholds that haven’t been crossed since their detection are shown as a dotted line up to the current bar. Is this work for you? If so, I’ll consider creating a version compatible with the screener, and then the screener itself.
defparam drawonlastbaronly=false
if day<>day[1] or intradaybarindex=0 then
unset($peak)
unset($peakbar)
unset($trough)
unset($troughbar)
i=0
j=0
endif
Peak1 = (high[3] > high[4]) AND (high[3] > high[5]) AND (high[3] > high[6])
Peak2 = (high[3] > high[2]) AND (high[3] > high[1]) AND (high[3] > high[0])
Peak = Peak1 AND Peak2
if peak then
// drawpoint(barindex[3],high[3],2) coloured("cyan")
$peak[i]=high[3]
$peakbar[i]=barindex[3]
i=i+1
endif
Trough1 = (low[3] < low[4]) AND (low[3] < low[5]) AND (low[3] < low[6])
Trough2 = (low[3] < low[2]) AND (low[3] < low[1]) AND (low[3] < low[0])
Trough = Trough1 AND Trough2
if Trough then
//drawpoint(barindex[3],low[3],2) coloured("crimson")
$trough[j]=low[3]
$troughbar[j]=barindex[3]
j=j+1
endif
if islastbarupdate then
if i>0 then
for k = 0 to i-1 do
drawpoint($peakbar[k], $peak[k],2) coloured("cyan")
for l = 0 to i-1 do
if $peakbar[l]<>$peakbar[k] then
diff = abs(round($peak[l],2) - round($peak[k],2))
if diff = 0 then //equal price
//find breakout
period = max(1,max($peakbar[l],$peakbar[k]) - min($peakbar[l],$peakbar[k]))
decay = max(1,barindex-max($peakbar[l],$peakbar[k]))
hh = highest[period](high)[decay]
if hh<=max($peak[l],$peak[k]) then //no breakout at that time
drawsegment($peakbar[l],$peak[l], $peakbar[k], $peak[k]) coloured("cyan")
currPeriod = max(1,barindex-max($peakbar[l],$peakbar[k]))
currHH = highest[currPeriod](high)
//test if no broken since (real time)
if currHH<=max($peak[l],$peak[k]) then //no breakout since
drawsegment($peakbar[l],$peak[l], barindex, $peak[l]) coloured("cyan") style(dottedline4)
endif
endif
endif
endif
next
next
endif
if j>0 then
for k = 0 to j-1 do
drawpoint($troughbar[k], $trough[k],2) coloured("crimson")
for l = 0 to i-1 do
if $troughbar[l]<>$troughbar[k] then
diff = abs(round($trough[l],2) - round($trough[k],2))
if diff = 0 then //equal price
//find breakout
period = max(1,max($troughbar[l],$troughbar[k]) - min($troughbar[l],$troughbar[k]))
decay = max(1,barindex-max($troughbar[l],$troughbar[k]))
ll = lowest[period](low)[decay]
if ll>=min($trough[l],$trough[k]) then //no breakout at that time
drawsegment($troughbar[l],$trough[l], $troughbar[k], $trough[k]) coloured("crimson")
currPeriod = max(1,barindex-max($peakbar[l],$peakbar[k]))
currLL = lowest[currPeriod](low)
//test if no broken since (real time)
if currLL>=min($trough[l],$trough[k]) then //no breakout since
drawsegment($troughbar[l],$trough[l], barindex, $trough[l]) coloured("crimson") style(dottedline4)
endif
endif
endif
endif
next
next
endif
endif
return
“only the thresholds that haven’t been crossed since their detection are shown as a dotted line up to the current bar.” this is working super well, perfect idea !
I checked some charts and see why it dont identify all swings.
There may be on chart 2-3 consecutive candles with the same high/low- and they are no detecred as swing.
nothing will explain it better than some screenshots. So I have atached what I mean
After that, yes it’s perfectly work as needed. no way to do it better, and no need
Indeed, swing trades are not usually validated if one of the surrounding candlesticks is equal. I understood that you wanted this in your last message, but I was waiting for you to bring it up before modifying the code. Below is the version that allows it:
defparam drawonlastbaronly=false
if day<>day[1] or intradaybarindex=0 then
unset($peak)
unset($peakbar)
unset($trough)
unset($troughbar)
i=0
j=0
endif
Peak1 = (high[3] >= high[4]) AND (high[3] > high[5]) AND (high[3] > high[6])
Peak2 = (high[3] >= high[2]) AND (high[3] > high[1]) AND (high[3] > high[0])
Peak = Peak1 AND Peak2
if peak then
// drawpoint(barindex[3],high[3],2) coloured("cyan")
$peak[i]=high[3]
$peakbar[i]=barindex[3]
i=i+1
endif
Trough1 = (low[3] <= low[4]) AND (low[3] < low[5]) AND (low[3] < low[6])
Trough2 = (low[3] <= low[2]) AND (low[3] < low[1]) AND (low[3] < low[0])
Trough = Trough1 AND Trough2
if Trough then
//drawpoint(barindex[3],low[3],2) coloured("crimson")
$trough[j]=low[3]
$troughbar[j]=barindex[3]
j=j+1
endif
if islastbarupdate then
if i>0 then
hhcount=0
for k = 0 to i-1 do
drawpoint($peakbar[k], $peak[k],2) coloured("cyan")
for l = 0 to i-1 do
if $peakbar[l]<>$peakbar[k] then
diff = abs(round($peak[l],2) - round($peak[k],2))
if diff = 0 then //equal price
//find breakout
period = max(2,max($peakbar[l],$peakbar[k]) - min($peakbar[l],$peakbar[k]))
decay = max(1,barindex-max($peakbar[l],$peakbar[k]))
hh = highest[period](high)[decay]
if hh<=max($peak[l],$peak[k]) then //no breakout at that time
drawsegment($peakbar[l],$peak[l], $peakbar[k], $peak[k]) coloured("cyan")
currPeriod = max(2,barindex-max($peakbar[l],$peakbar[k]))
currHH = highest[max(1,currPeriod)](high)
//test if no broken since (real time)
if currHH<=max($peak[l],$peak[k]) then //no breakout since
drawsegment($peakbar[l],$peak[l], barindex, $peak[l]) coloured("cyan") style(dottedline4)
//drawtext("!",$peakbar[l],$peak[l]+averagetruerange[14], dialog,bold, 22)
hhcount=hhcount+1
endif
endif
endif
endif
next
next
endif
if j>0 then
llcount=0
for k = 0 to j-1 do
drawpoint($troughbar[k], $trough[k],2) coloured("crimson")
for l = 0 to i-1 do
if $troughbar[l]<>$troughbar[k] then
diff = abs(round($trough[l],2) - round($trough[k],2))
if diff = 0 then //equal price
//find breakout
period = max(2,max($troughbar[l],$troughbar[k]) - min($troughbar[l],$troughbar[k]))
decay = max(1,barindex-max($troughbar[l],$troughbar[k]))
ll = lowest[period](low)[decay]
if ll>=min($trough[l],$trough[k]) then //no breakout at that time
drawsegment($troughbar[l],$trough[l], $troughbar[k], $trough[k]) coloured("crimson")
currPeriod = max(2,barindex-max($peakbar[l],$peakbar[k]))
currLL = lowest[currPeriod](low)
//test if no broken since (real time)
if currLL>=min($trough[l],$trough[k]) then //no breakout since
drawsegment($troughbar[l],$trough[l], barindex, $trough[l]) coloured("crimson") style(dottedline4)
llcount=llcount+1
endif
endif
endif
endif
next
next
endif
endif
return hhcount as "unbroken highs count", llcount as "unbroken lows count"
I see with new code, that when these surrounding candles are equal, the indicator thinks they are 2 separate swings and draws a line purely from this 2candles high, which is not entirely correct.
This actually remains one swing, just formed by several consecutive candles.
Everything else works perfectly.
Screener breakout swing tie highs and lows in 1 min
This topic contains 30 replies,
has 3 voices, and was last updated by
Nicolas
9 hours, 24 minutes ago.
| Forum: | ProScreener: Market Scanners & Detection |
| Language: | English |
| Started: | 10/15/2025 |
| Status: | Active |
| Attachments: | 38 files |
The information collected on this form is stored in a computer file by ProRealCode to create and access your ProRealCode profile. This data is kept in a secure database for the duration of the member's membership. They will be kept as long as you use our services and will be automatically deleted after 3 years of inactivity. Your personal data is used to create your private profile on ProRealCode. This data is maintained by SAS ProRealCode, 407 rue Freycinet, 59151 Arleux, France. If you subscribe to our newsletters, your email address is provided to our service provider "MailChimp" located in the United States, with whom we have signed a confidentiality agreement. This company is also compliant with the EU/Swiss Privacy Shield, and the GDPR. For any request for correction or deletion concerning your data, you can directly contact the ProRealCode team by email at privacy@prorealcode.com If you would like to lodge a complaint regarding the use of your personal data, you can contact your data protection supervisory authority.