[e2] Drawing Library :: Horizontal Ray

Library "e2hray"
A drawing library that contains the hray() function, which draws a horizontal ray/s with an initial point determined by a specified condition. It plots a ray until it reached the price. The function let you control the visibility of historical levels and setup the alerts.

hray(condition, level, color, extend, hist_lines, alert_message, alert_delay, style, hist_style, width, hist_width)
    condition: Boolean condition that defines the initial point of a ray
    level: Ray price level.
    color: Ray color.
    extend: (optional) Default value true, current ray levels extend to the right, if false - up to the current bar.
    hist_lines: (optional) Default value true, shows historical ray levels that were revisited, default is dashed lines. To avoid alert problems set to 'false' before creating alerts.
    alert_message: (optional) Default value string(na), if declared, enables alerts that fire when price revisits a line, using the text specified
    alert_delay: (optional) Default value int(0), number of bars to validate the level. Alerts won't trigger if the ray is broken during the 'delay'.
    style: (optional) Default value 'line.style_solid'. Ray line style.
    hist_style: (optional) Default value 'line.style_dashed'. Historical ray line style.
    width: (optional) Default value int(1), ray width in pixels.
    hist_width: (optional) Default value int(1), historical ray width in pixels.
  Returns: void

 • Example 1. Single horizontal ray from the dynamic input.
indicator("hray() example :: Dynamic input ray", overlay = true)
import e2e4mfck/e2hray/1 as e2draw
inputTime = input.time(timestamp("20 Jul 2021 00:00 +0300"), "Date", confirm = true)
inputPrice = input.price(54, 'Price Level', confirm = true)
e2draw.hray(time == inputTime, inputPrice, color.blue, alert_message = 'Ray level re-test!') 
var label mark = label.new(inputTime, inputPrice, 'Selected point to start the ray', xloc.bar_time)

 • Example 2. Multiple horizontal rays on the moving averages cross.
indicator("hray() example :: MA Cross", overlay = true)
import e2e4mfck/e2hray/1 as e2draw
float sma1 = ta.​sma​(close, 20)
float sma2 = ta.​sma​(close, 50)
bullishCross = ta.crossover( sma1, sma2)
bearishCross = ta.crossunder(sma1, sma2)
plot(sma1, 'sma1', color.purple)
plot(sma2, 'sma2', color.blue)

// 1a. We can use 2 function calls to distinguish long and short sides.
e2draw.hray(bullishCross, sma1, color.green, alert_message = 'Bullish Cross Level Broken!', alert_delay = 10)
e2draw.hray(bearishCross, sma2, color.red,   alert_message = 'Bearish Cross Level Broken!', alert_delay = 10)  

// 1b. Or a single call for both.
// e2draw.hray(bullishCross or bearishCross, sma1, bullishCross ? color.green : color.red) 

 • Example 3. Horizontal ray at the all time highs with an alert.
indicator("hray() example :: ATH", overlay = true)
import e2e4mfck/e2hray/1 as e2draw
var float ​ath​ = 0, ​ath​ := math.max(high, ​ath​)
bool newAth = ta.change(​ath​)
e2draw.hray(​nz​(newAth[1]), high[1], color.orange, alert_message = 'All Time Highs Tested!', alert_delay = 10)

Release Notes: v2
- xloc context switched from 'bar_index' to 'time'.
- alert_delay should be declared in minutes instead of bars.
- deep history reference bug fixed.

Pisces swimming through the river
All their life against the stream
Searching for a hook to catch on
And see their sun beam
Then suffocate in painful tortures
On cutting tables of callous men
Under a knife of handsome butchers
Emeralds are ripped away
Pine library

In true TradingView spirit, the author has published this Pine code as an open-source library so that other Pine programmers from our community can reuse it. Cheers to the author! You may use this library privately or in other open-source publications, but reuse of this code in a publication is governed by House Rules.


The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.

Want to use this library?

Copy the following line and paste it in your script.