Imbalances indicator

Category: Indicators By: Nicolas Created: October 12, 2023, 10:19 AM
October 12, 2023, 10:19 AM
Indicators
15 Comments

This code helps to visually identify and highlight certain “imbalances” in the price movement of an asset (like a stock or currency). Think of “imbalance” as sudden surges or drops in the asset’s price that can create potential buying or selling opportunities.

Here’s how it works:

  1. **Setting Up**:
    – `defparam drawonlastbaronly=true`: This means the indicator will only execute its calculations and drawings on the most recent data point or “bar” of the chart.
  2. . **Identifying Support**:- If the high price from 2 bars ago is less than the current low price, it’s considered a potential support level (a price level where the asset might stop falling and start rising). – This level is stored in a list for future reference.
  3.  **Identifying Resistance**: – If the current high price is less than the low price from 2 bars ago, it’s considered a potential resistance level (a price level where the asset might stop rising and start falling). – This level is also stored in a list for future reference.
  4. **Checking and Drawing Support Imbalances**: – For each identified potential support level, the code checks if the price ever fell below this level afterward. – If it did, a yellow rectangle is drawn from the bar where this support was identified to the bar where the price broke below this support. – If the price hasn’t gone below this support yet, the rectangle is drawn up to the most recent bar.
  5. **Checking and Drawing Resistance Imbalances**: – Similarly, for each potential resistance level, the code checks if the price ever rose above this level. – If it did, a cyan rectangle is drawn from the bar where this resistance was identified to the bar where the price broke above this resistance. – If the price hasn’t gone above this resistance yet, the rectangle is drawn up to the most recent bar.

In simpler terms:

This code visually highlights areas where there was a sudden change in the price movement, creating potential buying or selling opportunities. Yellow rectangles show where the price suddenly dropped, suggesting potential buying zones that are not filled (filled areas are in light green). Cyan rectangles show where the price surged, suggesting potential selling zones that are not filled yet (filled areas are in red). The rectangles help traders quickly spot these opportunities on their charts.

//PRC_Imbalances indicator
//12.10.2023
//Nicolas @ www.prorealcode.com
//Sharing ProRealTime knowledge

defparam drawonlastbaronly=true

REM Store support
IF high[2] < low THEN
  $support[i]= high[2]
 $bar[i]=barindex
 i=i+1
ENDIF

REM Store resistance
if high<low[2] then
 $res[y]= low[2]
 $resbar[y]=barindex
 y=y+1
endif

REM check support line
if islastbarupdate and i>1 then
 for j = i-1 downto 0 
  checklow = $support[j]
  bars = max(1,barindex-$bar[j])
  endbar=barindex
  for z = bars downto 1
   if low[z]<checklow then
    endbar=barindex[z]
    break
   endif
  next
  if endbar<barindex then
   drawrectangle($bar[j]-2,low[max(0,barindex-$bar[j])],endbar,$support[j]) coloured("crimson",50) bordercolor(0,0,0,0)
  ELSE
   drawrectangle($bar[j]-2,low[max(0,barindex-$bar[j])],barindex,$support[j]) coloured("yellow",50) bordercolor(0,0,0,0)
  endif
 next
endif

REM check resistance line
if islastbarupdate and y>1 then
 for j = y-1 downto 0
  checkhigh = $res[j]
  bars = max(1,barindex-$resbar[j])
  endbar=barindex
  for z = bars downto 1
   if high[z]>checkhigh then
    endbar=barindex[z]
    break
   endif
  next
  if endbar<barindex then
   drawrectangle($resbar[j]-2,high[max(0,barindex-$resbar[j])],endbar,$res[j]) coloured("lightgreen",50) bordercolor(0,0,0,0)
  ELSE
   drawrectangle($resbar[j]-2,high[max(0,barindex-$resbar[j])],barindex,$res[j]) coloured("cyan",50) bordercolor(0,0,0,0)
  endif
 next
endif

RETURN

Download
Filename: PRC_Imbalances-indicator-1.itf
Downloads: 396
Nicolas Master
I created ProRealCode because I believe in the power of shared knowledge. I spend my time coding new tools and helping members solve complex problems. If you are stuck on a code or need a fresh perspective on a strategy, I am always willing to help. Welcome to the community!
Author’s Profile

Comments

Logo Logo
Loading...