This code snippet demonstrates how to identify and visually represent swing highs and swing lows in a trading chart using the ProBuilder programming language. These indicators are useful for traders to understand potential reversal points in the market.
xPeriod = 20
If High[1] = Highest[xPeriod](High) and High[2] < High[1] and High < High[1] then
SwingHigh = High[1]
DrawArrowUP(BarIndex-1,High[1]+10) Coloured(0,255,0)
DrawText("#SwingHigh#", BarIndex-1, High[1]+30,Dialog,Bold,15) Coloured(0,255,0)
EndIf
If Low[1] = Lowest[xPeriod](Low) and Low[2] > Low[1] and Low > Low[1] then
SwingLow = Low[1]
DrawArrowDown(BarIndex-1,Low[1]-10) Coloured(255,0,0)
DrawText("#SwingLow#", BarIndex-1, Low[1]-30,Dialog,Bold,15) Coloured(255,0,0)
EndIf
Return
The code snippet above is structured to detect and mark swing highs and swing lows based on the price movements over a specified period. Here’s a step-by-step explanation:
xPeriod is set to 20, which defines the number of bars (or periods) to look back to find the highest high and the lowest low.High[1]) equals the highest high of the last 20 bars (Highest[xPeriod](High)) and if it is greater than the highs of the bars immediately before and after it. If true, it marks this as a swing high.Low[1]) is the lowest of the past 20 bars and is lower than the lows of the bars immediately before and after it.This implementation can be particularly useful for traders looking to automate the detection of potential pivot points in price charts, aiding in decision-making processes related to entries and exits in trades.
Check out this related content for more information:
https://www.prorealcode.com/topic/text-above-candles/#post-200655
Visit Link