Creating a Price Touch Heatmap in ProBuilder

13 Mar 2024
0 comment
0 attachment

This ProBuilder script generates a heatmap that visualizes the frequency of price touches within a specified range and period on a trading chart. The heatmap’s color intensity increases with the frequency of price touches, providing a visual representation from black to red.


defparam drawonlastbaronly=true
Period = 120
step = 0.25

hh = Highest[Period](High)
ll = Lowest[Period](Low)
checkprice = ll

if islastbarupdate then
  ind=0 //reset index of array

  //get the price touch occurrences for each level
  while checkprice<=hh do
    touch=0 //reset price touch for this price level
    for i = 0 to period-1 do
      if high[i]>=checkprice and low[i]<=checkprice then
        touch=touch+1
    $hm[ind] = touch
    endif
    next

    //define color
    r = min($hm[ind]*10,255)

    //plot the result
    //drawtext($hm[ind],barindex+5,checkprice) coloured(r,0,0)
    drawtext("█",barindex+5,checkprice) coloured(r,0,0)
    checkprice=checkprice+step //increase price check for next round
    ind=ind+1 //increase array index
  wend
endif

return hh,ll

This script is designed to run on the last bar of the chart only, to ensure performance and relevance of the displayed data. Here's a breakdown of how the code works:

  • Initialization: Sets the script to execute only on the last bar and defines the period and step for the price range.
  • Calculating High and Low: Determines the highest and lowest prices over the specified period to set the range for the heatmap.
  • Heatmap Calculation: Iterates through each price level between the lowest and highest prices. For each level, it checks how many times the price has touched this level within the period.
  • Color Assignment: Assigns a color based on the frequency of touches. The color intensity (red component) increases with more touches, capped at a maximum value of 255.
  • Display: Uses a colored block character to visually represent the frequency at each price level on the chart.
  • Index Management: Manages an array index to store and retrieve the number of touches for each price level.

This heatmap can be a useful tool for traders to visualize significant price levels where the market has shown repeated interest over a given period.

Related Post

Check out this related content for more information:

https://www.prorealcode.com/topic/historique-des-prix/#post-193758

Visit Link
What is a Snippet? A snippet is a small, reusable chunk of code designed to solve specific tasks quickly. Think of it as a shortcut that helps you achieve your coding goals without reinventing the wheel. How to Use: Simply copy the snippet and paste it into your project where needed. Don't forget to tweak it to fit your context. Snippets are not just time-savers; they're also learning tools to help you become a more efficient coder.
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

Search Snippets

Showing some results...
Sorry, no result found!

Snippets Categories

global
33
indicator
132
strategy
171

Recent Snippets

How to Build a Step-Based Trailing Stop That Moves to Break-Even First
strategy
This snippet implements a step trailing stop that advances in fixed increments once price reaches predefined profit [...]
Utilizing Arrays to Track and Compare Indicator Values Within the Same Bar in ProBuilder
indicator
This ProBuilder code snippet demonstrates how to use arrays to compare the values of an indicator (RSI in this case) [...]
Calculating Break-Even Points in ProBuilder
strategy
This ProBuilder code snippet demonstrates how to calculate the break-even point for a trading position. The break-even [...]
Implementing Time and Day Restrictions in Trading Algorithms
strategy
This code snippet demonstrates how to set restrictions on trading activities based on specific days of the week and [...]
Implementing Partial Position Closure Based on Price Retracement in ProBuilder
strategy
This code snippet demonstrates how to partially close a trading position when the price retraces to a certain level in [...]
Logo Logo
Loading...