real_time_candlesIntroduction
The Real-Time Candles Library provides comprehensive tools for creating, manipulating, and visualizing custom timeframe candles in Pine Script. Unlike standard indicators that only update at bar close, this library enables real-time visualization of price action and indicators within the current bar, offering traders unprecedented insight into market dynamics as they unfold.
This library addresses a fundamental limitation in traditional technical analysis: the inability to see how indicators evolve between bar closes. By implementing sophisticated real-time data processing techniques, traders can now observe indicator movements, divergences, and trend changes as they develop, potentially identifying trading opportunities much earlier than with conventional approaches.
Key Features
The library supports two primary candle generation approaches:
Chart-Time Candles: Generate real-time OHLC data for any variable (like RSI, MACD, etc.) while maintaining synchronization with chart bars.
Custom Timeframe (CTF) Candles: Create candles with custom time intervals or tick counts completely independent of the chart's native timeframe.
Both approaches support traditional candlestick and Heikin-Ashi visualization styles, with options for moving average overlays to smooth the data.
Configuration Requirements
For optimal performance with this library:
Set max_bars_back = 5000 in your script settings
When using CTF drawing functions, set max_lines_count = 500, max_boxes_count = 500, and max_labels_count = 500
These settings ensure that you will be able to draw correctly and will avoid any runtime errors.
Usage Examples
Basic Chart-Time Candle Visualization
// Create real-time candles for RSI
float rsi = ta.rsi(close, 14)
Candle rsi_candle = candle_series(rsi, CandleType.candlestick)
// Plot the candles using Pine's built-in function
plotcandle(rsi_candle.Open, rsi_candle.High, rsi_candle.Low, rsi_candle.Close,
"RSI Candles", rsi_candle.candle_color, rsi_candle.candle_color)
Multiple Access Patterns
The library provides three ways to access candle data, accommodating different programming styles:
// 1. Array-based access for collection operations
Candle candles = candle_array(source)
// 2. Object-oriented access for single entity manipulation
Candle candle = candle_series(source)
float value = candle.source(Source.HLC3)
// 3. Tuple-based access for functional programming styles
= candle_tuple(source)
Custom Timeframe Examples
// Create 20-second candles with EMA overlay
plot_ctf_candles(
source = close,
candle_type = CandleType.candlestick,
sample_type = SampleType.Time,
number_of_seconds = 20,
timezone = -5,
tied_open = true,
ema_period = 9,
enable_ema = true
)
// Create tick-based candles (new candle every 15 ticks)
plot_ctf_tick_candles(
source = close,
candle_type = CandleType.heikin_ashi,
number_of_ticks = 15,
timezone = -5,
tied_open = true
)
Advanced Usage with Custom Visualization
// Get custom timeframe candles without automatic plotting
CandleCTF my_candles = ctf_candles_array(
source = close,
candle_type = CandleType.candlestick,
sample_type = SampleType.Time,
number_of_seconds = 30
)
// Apply custom logic to the candles
float ema_values = my_candles.ctf_ema(14)
// Draw candles and EMA using time-based coordinates
my_candles.draw_ctf_candles_time()
ema_values.draw_ctf_line_time(line_color = #FF6D00)
Library Components
Data Types
Candle: Structure representing chart-time candles with OHLC, polarity, and visualization properties
CandleCTF: Extended candle structure with additional time metadata for custom timeframes
TickData: Structure for individual price updates with time deltas
Enumerations
CandleType: Specifies visualization style (candlestick or Heikin-Ashi)
Source: Defines price components for calculations (Open, High, Low, Close, HL2, etc.)
SampleType: Sets sampling method (Time-based or Tick-based)
Core Functions
get_tick(): Captures current price as a tick data point
candle_array(): Creates an array of candles from price updates
candle_series(): Provides a single candle based on latest data
candle_tuple(): Returns OHLC values as a tuple
ctf_candles_array(): Creates custom timeframe candles without rendering
Visualization Functions
source(): Extracts specific price components from candles
candle_ctf_to_float(): Converts candle data to float arrays
ctf_ema(): Calculates exponential moving averages for candle arrays
draw_ctf_candles_time(): Renders candles using time coordinates
draw_ctf_candles_index(): Renders candles using bar index coordinates
draw_ctf_line_time(): Renders lines using time coordinates
draw_ctf_line_index(): Renders lines using bar index coordinates
Technical Implementation Notes
This library leverages Pine Script's varip variables for state management, creating a sophisticated real-time data processing system. The implementation includes:
Efficient tick capturing: Samples price at every execution, maintaining temporal tracking with time deltas
Smart state management: Uses a hybrid approach with mutable updates at index 0 and historical preservation at index 1+
Temporal synchronization: Manages two time domains (chart time and custom timeframe)
The tooltip implementation provides crucial temporal context for custom timeframe visualizations, allowing users to understand exactly when each candle formed regardless of chart timeframe.
Limitations
Custom timeframe candles cannot be backtested due to Pine Script's limitations with historical tick data
Real-time visualization is only available during live chart updates
Maximum history is constrained by Pine Script's array size limits
Applications
Indicator visualization: See how RSI, MACD, or other indicators evolve in real-time
Volume analysis: Create custom volume profiles independent of chart timeframe
Scalping strategies: Identify short-term patterns with precisely defined time windows
Volatility measurement: Track price movement characteristics within bars
Custom signal generation: Create entry/exit signals based on custom timeframe patterns
Conclusion
The Real-Time Candles Library bridges the gap between traditional technical analysis (based on discrete OHLC bars) and the continuous nature of market movement. By making indicators more responsive to real-time price action, it gives traders a significant edge in timing and decision-making, particularly in fast-moving markets where waiting for bar close could mean missing important opportunities.
Whether you're building custom indicators, researching price patterns, or developing trading strategies, this library provides the foundation for sophisticated real-time analysis in Pine Script.
Implementation Details & Advanced Guide
Core Implementation Concepts
The Real-Time Candles Library implements a sophisticated event-driven architecture within Pine Script's constraints. At its heart, the library creates what's essentially a reactive programming framework handling continuous data streams.
Tick Processing System
The foundation of the library is the get_tick() function, which captures price updates as they occur:
export get_tick(series float source = close, series float na_replace = na)=>
varip float price = na
varip int series_index = -1
varip int old_time = 0
varip int new_time = na
varip float time_delta = 0
// ...
This function:
Samples the current price
Calculates time elapsed since last update
Maintains a sequential index to track updates
The resulting TickData structure serves as the fundamental building block for all candle generation.
State Management Architecture
The library employs a sophisticated state management system using varip variables, which persist across executions within the same bar. This creates a hybrid programming paradigm that's different from standard Pine Script's bar-by-bar model.
For chart-time candles, the core state transition logic is:
// Real-time update of current candle
candle_data := Candle.new(Open, High, Low, Close, polarity, series_index, candle_color)
candles.set(0, candle_data)
// When a new bar starts, preserve the previous candle
if clear_state
candles.insert(1, candle_data)
price.clear()
// Reset state for new candle
Open := Close
price.push(Open)
series_index += 1
This pattern of updating index 0 in real-time while inserting completed candles at index 1 creates an elegant solution for maintaining both current state and historical data.
Custom Timeframe Implementation
The custom timeframe system manages its own time boundaries independent of chart bars:
bool clear_state = switch settings.sample_type
SampleType.Ticks => cumulative_series_idx >= settings.number_of_ticks
SampleType.Time => cumulative_time_delta >= settings.number_of_seconds
This dual-clock system synchronizes two time domains:
Pine's execution clock (bar-by-bar processing)
The custom timeframe clock (tick or time-based)
The library carefully handles temporal discontinuities, ensuring candle formation remains accurate despite irregular tick arrival or market gaps.
Advanced Usage Techniques
1. Creating Custom Indicators with Real-Time Candles
To develop indicators that process real-time data within the current bar:
// Get real-time candles for your data
Candle rsi_candles = candle_array(ta.rsi(close, 14))
// Calculate indicator values based on candle properties
float signal = ta.ema(rsi_candles.first().source(Source.Close), 9)
// Detect patterns that occur within the bar
bool divergence = close > close and rsi_candles.first().Close < rsi_candles.get(1).Close
2. Working with Custom Timeframes and Plotting
For maximum flexibility when visualizing custom timeframe data:
// Create custom timeframe candles
CandleCTF volume_candles = ctf_candles_array(
source = volume,
candle_type = CandleType.candlestick,
sample_type = SampleType.Time,
number_of_seconds = 60
)
// Convert specific candle properties to float arrays
float volume_closes = volume_candles.candle_ctf_to_float(Source.Close)
// Calculate derived values
float volume_ema = volume_candles.ctf_ema(14)
// Create custom visualization
volume_candles.draw_ctf_candles_time()
volume_ema.draw_ctf_line_time(line_color = color.orange)
3. Creating Hybrid Timeframe Analysis
One powerful application is comparing indicators across multiple timeframes:
// Standard chart timeframe RSI
float chart_rsi = ta.rsi(close, 14)
// Custom 5-second timeframe RSI
CandleCTF ctf_candles = ctf_candles_array(
source = close,
candle_type = CandleType.candlestick,
sample_type = SampleType.Time,
number_of_seconds = 5
)
float fast_rsi_array = ctf_candles.candle_ctf_to_float(Source.Close)
float fast_rsi = fast_rsi_array.first()
// Generate signals based on divergence between timeframes
bool entry_signal = chart_rsi < 30 and fast_rsi > fast_rsi_array.get(1)
Final Notes
This library represents an advanced implementation of real-time data processing within Pine Script's constraints. By creating a reactive programming framework for handling continuous data streams, it enables sophisticated analysis typically only available in dedicated trading platforms.
The design principles employed—including state management, temporal processing, and object-oriented architecture—can serve as patterns for other advanced Pine Script development beyond this specific application.
------------------------
Library "real_time_candles"
A comprehensive library for creating real-time candles with customizable timeframes and sampling methods.
Supports both chart-time and custom-time candles with options for candlestick and Heikin-Ashi visualization.
Allows for tick-based or time-based sampling with moving average overlay capabilities.
get_tick(source, na_replace)
Captures the current price as a tick data point
Parameters:
source (float) : Optional - Price source to sample (defaults to close)
na_replace (float) : Optional - Value to use when source is na
Returns: TickData structure containing price, time since last update, and sequential index
candle_array(source, candle_type, sync_start, bullish_color, bearish_color)
Creates an array of candles based on price updates
Parameters:
source (float) : Optional - Price source to sample (defaults to close)
candle_type (simple CandleType) : Optional - Type of candle chart to create (candlestick or Heikin-Ashi)
sync_start (simple bool) : Optional - Whether to synchronize with the start of a new bar
bullish_color (color) : Optional - Color for bullish candles
bearish_color (color) : Optional - Color for bearish candles
Returns: Array of Candle objects ordered with most recent at index 0
candle_series(source, candle_type, wait_for_sync, bullish_color, bearish_color)
Provides a single candle based on the latest price data
Parameters:
source (float) : Optional - Price source to sample (defaults to close)
candle_type (simple CandleType) : Optional - Type of candle chart to create (candlestick or Heikin-Ashi)
wait_for_sync (simple bool) : Optional - Whether to wait for a new bar before starting
bullish_color (color) : Optional - Color for bullish candles
bearish_color (color) : Optional - Color for bearish candles
Returns: A single Candle object representing the current state
candle_tuple(source, candle_type, wait_for_sync, bullish_color, bearish_color)
Provides candle data as a tuple of OHLC values
Parameters:
source (float) : Optional - Price source to sample (defaults to close)
candle_type (simple CandleType) : Optional - Type of candle chart to create (candlestick or Heikin-Ashi)
wait_for_sync (simple bool) : Optional - Whether to wait for a new bar before starting
bullish_color (color) : Optional - Color for bullish candles
bearish_color (color) : Optional - Color for bearish candles
Returns: Tuple representing current candle values
method source(self, source, na_replace)
Extracts a specific price component from a Candle
Namespace types: Candle
Parameters:
self (Candle)
source (series Source) : Type of price data to extract (Open, High, Low, Close, or composite values)
na_replace (float) : Optional - Value to use when source value is na
Returns: The requested price value from the candle
method source(self, source)
Extracts a specific price component from a CandleCTF
Namespace types: CandleCTF
Parameters:
self (CandleCTF)
source (simple Source) : Type of price data to extract (Open, High, Low, Close, or composite values)
Returns: The requested price value from the candle as a varip
method candle_ctf_to_float(self, source)
Converts a specific price component from each CandleCTF to a float array
Namespace types: array
Parameters:
self (array)
source (simple Source) : Optional - Type of price data to extract (defaults to Close)
Returns: Array of float values extracted from the candles, ordered with most recent at index 0
method ctf_ema(self, ema_period)
Calculates an Exponential Moving Average for a CandleCTF array
Namespace types: array
Parameters:
self (array)
ema_period (simple float) : Period for the EMA calculation
Returns: Array of float values representing the EMA of the candle data, ordered with most recent at index 0
method draw_ctf_candles_time(self, sample_type, number_of_ticks, number_of_seconds, timezone)
Renders custom timeframe candles using bar time coordinates
Namespace types: array
Parameters:
self (array)
sample_type (simple SampleType) : Optional - Method for sampling data (Time or Ticks), used for tooltips
number_of_ticks (simple int) : Optional - Number of ticks per candle (used when sample_type is Ticks), used for tooltips
number_of_seconds (simple float) : Optional - Time duration per candle in seconds (used when sample_type is Time), used for tooltips
timezone (simple int) : Optional - Timezone offset from UTC (-12 to +12), used for tooltips
Returns: void - Renders candles on the chart using time-based x-coordinates
method draw_ctf_candles_index(self, sample_type, number_of_ticks, number_of_seconds, timezone)
Renders custom timeframe candles using bar index coordinates
Namespace types: array
Parameters:
self (array)
sample_type (simple SampleType) : Optional - Method for sampling data (Time or Ticks), used for tooltips
number_of_ticks (simple int) : Optional - Number of ticks per candle (used when sample_type is Ticks), used for tooltips
number_of_seconds (simple float) : Optional - Time duration per candle in seconds (used when sample_type is Time), used for tooltips
timezone (simple int) : Optional - Timezone offset from UTC (-12 to +12), used for tooltips
Returns: void - Renders candles on the chart using index-based x-coordinates
method draw_ctf_line_time(self, source, line_size, line_color)
Renders a line representing a price component from the candles using time coordinates
Namespace types: array
Parameters:
self (array)
source (simple Source) : Optional - Type of price data to extract (defaults to Close)
line_size (simple int) : Optional - Width of the line
line_color (simple color) : Optional - Color of the line
Returns: void - Renders a connected line on the chart using time-based x-coordinates
method draw_ctf_line_time(self, line_size, line_color)
Renders a line from a varip float array using time coordinates
Namespace types: array
Parameters:
self (array)
line_size (simple int) : Optional - Width of the line, defaults to 2
line_color (simple color) : Optional - Color of the line
Returns: void - Renders a connected line on the chart using time-based x-coordinates
method draw_ctf_line_index(self, source, line_size, line_color)
Renders a line representing a price component from the candles using index coordinates
Namespace types: array
Parameters:
self (array)
source (simple Source) : Optional - Type of price data to extract (defaults to Close)
line_size (simple int) : Optional - Width of the line
line_color (simple color) : Optional - Color of the line
Returns: void - Renders a connected line on the chart using index-based x-coordinates
method draw_ctf_line_index(self, line_size, line_color)
Renders a line from a varip float array using index coordinates
Namespace types: array
Parameters:
self (array)
line_size (simple int) : Optional - Width of the line, defaults to 2
line_color (simple color) : Optional - Color of the line
Returns: void - Renders a connected line on the chart using index-based x-coordinates
plot_ctf_tick_candles(source, candle_type, number_of_ticks, timezone, tied_open, ema_period, bullish_color, bearish_color, line_width, ema_color, use_time_indexing)
Plots tick-based candles with moving average
Parameters:
source (float) : Input price source to sample
candle_type (simple CandleType) : Type of candle chart to display
number_of_ticks (simple int) : Number of ticks per candle
timezone (simple int) : Timezone offset from UTC (-12 to +12)
tied_open (simple bool) : Whether to tie open price to close of previous candle
ema_period (simple float) : Period for the exponential moving average
bullish_color (color) : Optional - Color for bullish candles
bearish_color (color) : Optional - Color for bearish candles
line_width (simple int) : Optional - Width of the moving average line, defaults to 2
ema_color (color) : Optional - Color of the moving average line
use_time_indexing (simple bool) : Optional - When true the function will plot with xloc.time, when false it will plot using xloc.bar_index
Returns: void - Creates visual candle chart with EMA overlay
plot_ctf_tick_candles(source, candle_type, number_of_ticks, timezone, tied_open, bullish_color, bearish_color, use_time_indexing)
Plots tick-based candles without moving average
Parameters:
source (float) : Input price source to sample
candle_type (simple CandleType) : Type of candle chart to display
number_of_ticks (simple int) : Number of ticks per candle
timezone (simple int) : Timezone offset from UTC (-12 to +12)
tied_open (simple bool) : Whether to tie open price to close of previous candle
bullish_color (color) : Optional - Color for bullish candles
bearish_color (color) : Optional - Color for bearish candles
use_time_indexing (simple bool) : Optional - When true the function will plot with xloc.time, when false it will plot using xloc.bar_index
Returns: void - Creates visual candle chart without moving average
plot_ctf_time_candles(source, candle_type, number_of_seconds, timezone, tied_open, ema_period, bullish_color, bearish_color, line_width, ema_color, use_time_indexing)
Plots time-based candles with moving average
Parameters:
source (float) : Input price source to sample
candle_type (simple CandleType) : Type of candle chart to display
number_of_seconds (simple float) : Time duration per candle in seconds
timezone (simple int) : Timezone offset from UTC (-12 to +12)
tied_open (simple bool) : Whether to tie open price to close of previous candle
ema_period (simple float) : Period for the exponential moving average
bullish_color (color) : Optional - Color for bullish candles
bearish_color (color) : Optional - Color for bearish candles
line_width (simple int) : Optional - Width of the moving average line, defaults to 2
ema_color (color) : Optional - Color of the moving average line
use_time_indexing (simple bool) : Optional - When true the function will plot with xloc.time, when false it will plot using xloc.bar_index
Returns: void - Creates visual candle chart with EMA overlay
plot_ctf_time_candles(source, candle_type, number_of_seconds, timezone, tied_open, bullish_color, bearish_color, use_time_indexing)
Plots time-based candles without moving average
Parameters:
source (float) : Input price source to sample
candle_type (simple CandleType) : Type of candle chart to display
number_of_seconds (simple float) : Time duration per candle in seconds
timezone (simple int) : Timezone offset from UTC (-12 to +12)
tied_open (simple bool) : Whether to tie open price to close of previous candle
bullish_color (color) : Optional - Color for bullish candles
bearish_color (color) : Optional - Color for bearish candles
use_time_indexing (simple bool) : Optional - When true the function will plot with xloc.time, when false it will plot using xloc.bar_index
Returns: void - Creates visual candle chart without moving average
plot_ctf_candles(source, candle_type, sample_type, number_of_ticks, number_of_seconds, timezone, tied_open, ema_period, bullish_color, bearish_color, enable_ema, line_width, ema_color, use_time_indexing)
Unified function for plotting candles with comprehensive options
Parameters:
source (float) : Input price source to sample
candle_type (simple CandleType) : Optional - Type of candle chart to display
sample_type (simple SampleType) : Optional - Method for sampling data (Time or Ticks)
number_of_ticks (simple int) : Optional - Number of ticks per candle (used when sample_type is Ticks)
number_of_seconds (simple float) : Optional - Time duration per candle in seconds (used when sample_type is Time)
timezone (simple int) : Optional - Timezone offset from UTC (-12 to +12)
tied_open (simple bool) : Optional - Whether to tie open price to close of previous candle
ema_period (simple float) : Optional - Period for the exponential moving average
bullish_color (color) : Optional - Color for bullish candles
bearish_color (color) : Optional - Color for bearish candles
enable_ema (bool) : Optional - Whether to display the EMA overlay
line_width (simple int) : Optional - Width of the moving average line, defaults to 2
ema_color (color) : Optional - Color of the moving average line
use_time_indexing (simple bool) : Optional - When true the function will plot with xloc.time, when false it will plot using xloc.bar_index
Returns: void - Creates visual candle chart with optional EMA overlay
ctf_candles_array(source, candle_type, sample_type, number_of_ticks, number_of_seconds, tied_open, bullish_color, bearish_color)
Creates an array of custom timeframe candles without rendering them
Parameters:
source (float) : Input price source to sample
candle_type (simple CandleType) : Type of candle chart to create (candlestick or Heikin-Ashi)
sample_type (simple SampleType) : Method for sampling data (Time or Ticks)
number_of_ticks (simple int) : Optional - Number of ticks per candle (used when sample_type is Ticks)
number_of_seconds (simple float) : Optional - Time duration per candle in seconds (used when sample_type is Time)
tied_open (simple bool) : Optional - Whether to tie open price to close of previous candle
bullish_color (color) : Optional - Color for bullish candles
bearish_color (color) : Optional - Color for bearish candles
Returns: Array of CandleCTF objects ordered with most recent at index 0
Candle
Structure representing a complete candle with price data and display properties
Fields:
Open (series float) : Opening price of the candle
High (series float) : Highest price of the candle
Low (series float) : Lowest price of the candle
Close (series float) : Closing price of the candle
polarity (series bool) : Boolean indicating if candle is bullish (true) or bearish (false)
series_index (series int) : Sequential index identifying the candle in the series
candle_color (series color) : Color to use when rendering the candle
ready (series bool) : Boolean indicating if candle data is valid and ready for use
TickData
Structure for storing individual price updates
Fields:
price (series float) : The price value at this tick
time_delta (series float) : Time elapsed since the previous tick in milliseconds
series_index (series int) : Sequential index identifying this tick
CandleCTF
Structure representing a custom timeframe candle with additional time metadata
Fields:
Open (series float) : Opening price of the candle
High (series float) : Highest price of the candle
Low (series float) : Lowest price of the candle
Close (series float) : Closing price of the candle
polarity (series bool) : Boolean indicating if candle is bullish (true) or bearish (false)
series_index (series int) : Sequential index identifying the candle in the series
open_time (series int) : Timestamp marking when the candle was opened (in Unix time)
time_delta (series float) : Duration of the candle in milliseconds
candle_color (series color) : Color to use when rendering the candle
Utility
iteratorThe "Iterator" library is designed to provide a flexible way to work with sequences of values. This library offers a set of functions to create and manage iterators for various data types, including integers, floats, and more. Whether you need to generate an array of values with specific increments or iterate over elements in reverse order, this library has you covered.
Key Features:
Array Creation: Easily generate arrays of integers or floats with customizable steps, both inclusive and exclusive of the end values.
Flexible Iteration: Includes methods to iterate over arrays of different types, such as booleans, integers, floats, strings, colors, and drawing objects like lines and labels.
Reverse Iteration: Support for reverse iteration, giving you control over the order in which elements are processed.
Automatic Loop Control: One of the key advantages of this library is that when using the .iterate() method, it only loops over the array when there are values present. This means you don’t have to manually check if the array is populated before iterating, simplifying your code and reducing potential errors.
Versatile Use Cases: Ideal for scenarios where you need to loop over an array without worrying about empty arrays or checking conditions manually.
This library is particularly useful in cases where you need to perform operations on each element in an array, ensuring that your loops are efficient and free from unnecessary checks.
Library "iterator"
The "iterator" library provides a versatile and efficient set of functions for creating and managing iterators.
It allows you to generate arrays of integers or floats with customizable steps, both inclusive and exclusive of the end values.
The library also includes methods for iterating over various types, including booleans, integers, floats, strings, colors,
and drawing objects like lines and labels. With support for reverse iteration and flexible customization options.
iterator(stop, start, step)
Creates an array of integers from start to stop with a specified step, excluding the stop value.
Parameters:
stop (int) : The end value of the iterator, exclusive.
start (int) : The starting value of the iterator. Default is 0.
step (int) : The increment value for each step in the iterator. Default is 1. Must be greater than 0.
Returns: An array of integers incremented by the step value from start to stop. Will return and empty array if start = stop.
iterator(stop, start, step)
Creates an array of floats from start to stop with a specified step, excluding the stop value.
Parameters:
stop (float) : The end value of the iterator, exclusive.
start (float) : The starting value of the iterator. Default is 0.
step (float) : The increment value for each step in the iterator. Default is 1. Must be greater than 0.
Returns: An array of floats incremented by the step value from start to stop. Will return and empty array if start = stop.
iterator_inclusive(stop, start, step)
Creates an array of integers from start to stop with a specified step, including the stop value.
Parameters:
stop (int) : The end value of the iterator, inclusive.
start (int) : The starting value of the iterator. Default is 0.
step (int) : The increment value for each step in the iterator. Default is 1. Must be greater than 0.
Returns: An array of integers incremented by the step value from start to stop, including the stop value.
iterator_inclusive(stop, start, step)
Creates an array of floats from start to stop with a specified step, including the stop value.
Parameters:
stop (float) : The end value of the iterator, inclusive.
start (float) : The starting value of the iterator. Default is 0.
step (float) : The increment value for each step in the iterator. Default is 1. Must be greater than 0.
Returns: An array of floats incremented by the step value from start to stop, including the stop value.
itr(stop, start, step)
Creates an array of integers from start to stop with a specified step, excluding the stop value.
Parameters:
stop (int) : The end value of the iterator, exclusive.
start (int) : The starting value of the iterator. Default is 0.
step (int) : The increment value for each step in the iterator. Default is 1. Must be greater than 0.
Returns: An array of integers incremented by the step value from start to stop.
itr(stop, start, step)
Creates an array of floats from start to stop with a specified step, excluding the stop value.
Parameters:
stop (float) : The end value of the iterator, exclusive.
start (float) : The starting value of the iterator. Default is 0.
step (float) : The increment value for each step in the iterator. Default is 1. Must be greater than 0.
Returns: An array of floats incremented by the step value from start to stop.
itr_in(stop, start, step)
Creates an array of integers from start to stop with a specified step, including the stop value.
Parameters:
stop (int) : The end value of the iterator, inclusive.
start (int) : The starting value of the iterator. Default is 0.
step (int) : The increment value for each step in the iterator. Default is 1. Must be greater than 0.
Returns: An array of integers incremented by the step value from start to stop, including the stop value.
itr_in(stop, start, step)
Creates an array of floats from start to stop with a specified step, including the stop value.
Parameters:
stop (float) : The end value of the iterator, inclusive.
start (float) : The starting value of the iterator. Default is 0.
step (float) : The increment value for each step in the iterator. Default is 1. Must be greater than 0.
Returns: An array of floats incremented by the step value from start to stop, including the stop value.
method iterate(self, reverse)
Creates an iterator array for the indices of ana array, with an option to reverse the order.
Namespace types: array
Parameters:
self (array) : The array to iterate over.
reverse (bool) : A boolean flag indicating whether to reverse the iterator order. Default is false.
Returns: An array of integers representing the indices of the array. The order can be reversed if specified.
method iterate(self, reverse)
Creates an iterator array for the indices of ana array, with an option to reverse the order.
Namespace types: array
Parameters:
self (array) : The array to iterate over.
reverse (bool) : A boolean flag indicating whether to reverse the iterator order. Default is false.
Returns: An array of integers representing the indices of the array. The order can be reversed if specified.
method iterate(self, reverse)
Creates an iterator array for the indices of ana array, with an option to reverse the order.
Namespace types: array
Parameters:
self (array) : The array to iterate over.
reverse (bool) : A boolean flag indicating whether to reverse the iterator order. Default is false.
Returns: An array of integers representing the indices of the array. The order can be reversed if specified.
method iterate(self, reverse)
Creates an iterator array for the indices of ana array, with an option to reverse the order.
Namespace types: array
Parameters:
self (array) : The array to iterate over.
reverse (bool) : A boolean flag indicating whether to reverse the iterator order. Default is false.
Returns: An array of integers representing the indices of the array. The order can be reversed if specified.
method iterate(self, reverse)
Creates an iterator array for the indices of ana array, with an option to reverse the order.
Namespace types: array
Parameters:
self (array) : The array to iterate over.
reverse (bool) : A boolean flag indicating whether to reverse the iterator order. Default is false.
Returns: An array of integers representing the indices of the array. The order can be reversed if specified.
method iterate(self, reverse)
Creates an iterator array for the indices of ana array, with an option to reverse the order.
Namespace types: array
Parameters:
self (array) : The array to iterate over.
reverse (bool) : A boolean flag indicating whether to reverse the iterator order. Default is false.
Returns: An array of integers representing the indices of the array. The order can be reversed if specified.
method iterate(self, reverse)
Creates an iterator array for the indices of ana array, with an option to reverse the order.
Namespace types: array
Parameters:
self (array) : The array to iterate over.
reverse (bool) : A boolean flag indicating whether to reverse the iterator order. Default is false.
Returns: An array of integers representing the indices of the array. The order can be reversed if specified.
method iterate(self, reverse)
Creates an iterator array for the indices of ana array, with an option to reverse the order.
Namespace types: array
Parameters:
self (array) : The array to iterate over.
reverse (bool) : A boolean flag indicating whether to reverse the iterator order. Default is false.
Returns: An array of integers representing the indices of the array. The order can be reversed if specified.
method iterate(self, reverse)
Creates an iterator array for the indices of ana array, with an option to reverse the order.
Namespace types: array
Parameters:
self (array) : The array to iterate over.
reverse (bool) : A boolean flag indicating whether to reverse the iterator order. Default is false.
Returns: An array of integers representing the indices of the array. The order can be reversed if specified.
method iterate(self, reverse)
Creates an iterator array for the indices of ana array, with an option to reverse the order.
Namespace types: array
Parameters:
self (array) : The array to iterate over.
reverse (bool) : A boolean flag indicating whether to reverse the iterator order. Default is false.
Returns: An array of integers representing the indices of the array. The order can be reversed if specified.
method iterate(self, reverse)
Creates an iterator array for the indices of ana array, with an option to reverse the order.
Namespace types: array
Parameters:
self (array) : The array to iterate over.
reverse (bool) : A boolean flag indicating whether to reverse the iterator order. Default is false.
Returns: An array of integers representing the indices of the array. The order can be reversed if specified.
method iterate(self, reverse)
Creates an iterator array for the indices of ana array, with an option to reverse the order.
Namespace types: array
Parameters:
self (array) : The array to iterate over.
reverse (bool) : A boolean flag indicating whether to reverse the iterator order. Default is false.
Returns: An array of integers representing the indices of the array. The order can be reversed if specified.
ColourUtilitiesLibrary "ColourUtilities"
Utility functions for colour manipulation
adjust_colour(rgb, desaturation_amount, transparency_amount)
to reduce saturation or increase transparency of an RGB colour
Parameters:
rgb (color)
desaturation_amount (float) : 0 means no desaturation (colours remains as-is), and 1 means full desaturation (colour turns grey). Can also be used inversely with negative numbers
transparency_amount (float) : How much more transparent the default transparency should become. E.g. with a value of 0.5, a transparency of 0 becomes 50 and 40 becomes 70. A value of 1 makes it fully transparent, en -1 fully opaque.
Returns: color with adjusted saturation and transparency
method apply_default_palette(self, palette_name)
Some nice looking colour palettes, consisting of 6 gradient colours, are already defined here and can be quickly applied to the Palette class
Namespace types: Palette
Parameters:
self (Palette)
palette_name (string) : Currently there are 4 6-coloured palettes available: "GYTS flux signal", "GYTS purple", "GYTS flux filter" and "GYTS maroon"
Returns: None, as it populates the Palette class with pre-defined colours
method get_colour(self, colour_no, transparency)
Retrieves colour from the palette and possibly changes transparency if set
Namespace types: Palette
Parameters:
self (Palette)
colour_no (int) : from the palette
transparency (int) : to possibly change the default transparency of the palette
Returns: colour
method get_dynamic_colour(self, x, mid_point, colour_lb, colour_ub, trend_lookback, use_rate)
Retrieves a colour based on strength and direction of the passed series
Namespace types: Palette
Parameters:
self (Palette)
x (float) : the input data series
mid_point (float) : value as a cutoff point where the bullish/bearish colour scenario
colour_lb (float) : value (lower bound) where to apply the bearish colour at full strength
colour_ub (float) : value (upper bound) where to apply the bullish colour at full strength
trend_lookback (int) : how much bars back to check if there was a consistent move into a certain direction, otherwise a the neutral colour from the centre of the palette will be used.
use_rate (bool) : whether to use the rate (proportional difference with previous `x` value) or the input series `x` directly
Returns: colour
Palette
Fields:
transparency (series__integer)
palette (array__color)
fast_utilsLibrary "fast_utils"
This library contains my favourite functions. Will be updated frequently
count_int_digits()
Count int digits in number
Returns: : number of int digits in number
count_float_digits()
Count float digits in number
Returns: : number of float digits in number
stringify()
Convert values in array or matrix into string values
Returns: : array or matrix of string values
arrcompare()
Compare values in arrays
Returns: : bool value
arrdedup()
Remove duplicate values in array
Returns: : array without duplicates
ResInMins()
Converts current resolution in minutes
Returns: : return float number of minuted
MultOfRes(res, mult)
Convert current float TF in minutes to target string TF in "timeframe.period" format.
Parameters:
res : : current resolution in minutes
mult : : Multiple of current TF to be calculated.
Returns: : timeframe format string
columnsLibrary "columns"
Error Tolerant Matrix Setter/Getter Operations. Easy ways to add/remove items into start and end of Columns as well as arrays to grow and shrink matrix.
if mismatched sizes occur the typified NA value will be there to prevent catastrophic crashing.
Rows and Columns are split into 2 libraries due to limitations on number of exports as well as ease of style (columns.shift(), rows.pop() )
pop(_matrix)
do pop last Column off of matrix
Parameters:
_matrix : Matrix To Edit
Returns: Array of Last Column, removing it from matrix
shift(_matrix)
do shift the first Column off of matrix
Parameters:
_matrix : Matrix To Edit
Returns: Array of First Column, removing it from matrix
get(_matrix, _clmnNum)
retrieve specific Column of matrix
Parameters:
_matrix : Matrix To Edit
_clmnNum : Column being Targeted
Returns: Array of selected Column number, leaving in place
push(_matrix, _clmnNum, _item)
add single item onto end of Column
Parameters:
_matrix : Matrix To Edit
_clmnNum : Column being Targeted
_item : Item to Push on Column
Returns: shifted item from Column start
push(_matrix, _array)
add single item onto end of matrix
Parameters:
_matrix : Matrix To Edit
_array : Array to Push on Matrix
Returns: Void
unshift(_matrix, _clmnNum, _item)
slide single item into start of Column remove last
Parameters:
_matrix : Matrix To Edit
_clmnNum : Column being Targeted
_item : Item to Unshift on Column
Returns: popped item from Column end
unshift(_matrix, _array)
add single item into first Column of matrix
Parameters:
_matrix : Matrix To Edit
_array : Array to unshift into Matrix
Returns: Void
set(_matrix, _clmnNum, _array)
replace an array to an existing Column
Parameters:
_matrix : Matrix To Edit
_clmnNum : Column being Targeted
_array : Array to place in Matrix
Returns: Column that was replaced
insert(_matrix, _clmnNum, _array)
insert an array to a new Column
Parameters:
_matrix : Matrix To Edit
_clmnNum : Column being Targeted
_array : Array to place in Matrix
Returns: void
slideDown(_matrix, _array)
add single item onto end of Column
Parameters:
_matrix : Matrix To Edit
_array : Array to push to Matrix
Returns: shifted first Column
slideUp(_matrix, _array)
add single item onto end of Column
Parameters:
_matrix : Matrix To Edit
_array : Array to unshift to Matrix
Returns: poppeed last Column
pullOut(_matrix, _clmnNum)
add single item onto end of Column
Parameters:
_matrix : Matrix To Edit
_clmnNum : Column being Targeted
Returns: removed selected Column
rowsLibrary "rows"
Error Tolerant Matrix Setter/Getter Operations. Easy ways to add/remove items into start and end of rows as well as arrays to grow and shrink matrix.
if mismatched sizes occur the typified NA value will be there to prevent catastrophic crashing.
columns and rows are split into 2 libraries due to limitations on number of exports as well as ease of style (columns.shift(), rows.pop() )
pop(_matrix)
do pop last row off of matrix
Parameters:
_matrix : Matrix To Edit
Returns: Array of Last row, removing it from matrix
shift(_matrix)
do shift the first row off of matrix
Parameters:
_matrix : Matrix To Edit
Returns: Array of First row, removing it from matrix
get(_matrix, _rowNum)
retrieve specific row of matrix
Parameters:
_matrix : Matrix To Edit
_rowNum : Row being Targeted
Returns: Array of selected row number, leaving in place
push(_matrix, _rowNum, _item)
add single item onto end of row
Parameters:
_matrix : Matrix To Edit
_rowNum : Row being Targeted
_item : Item to Push on Row
Returns: shifted item from row start
push(_matrix, _array)
add single item onto end of matrix
Parameters:
_matrix : Matrix To Edit
_array : Array to Push on Matrix
Returns: Void
unshift(_matrix, _rowNum, _item)
slide single item into start of row remove last
Parameters:
_matrix : Matrix To Edit
_rowNum : Row being Targeted
_item : Item to Unshift on Row
Returns: popped item from row end
unshift(_matrix, _array)
add single item into first row of matrix
Parameters:
_matrix : Matrix To Edit
_array : Array to unshift into Matrix
Returns: Void
set(_matrix, _rowNum, _array)
replace an array to an existing row
Parameters:
_matrix : Matrix To Edit
_rowNum : Row being Targeted
_array : Array to place in Matrix
Returns: row that was replaced
insert(_matrix, _rowNum, _array)
insert an array to a new row
Parameters:
_matrix : Matrix To Edit
_rowNum : Row being Targeted
_array : Array to place in Matrix
Returns: void
slideDown(_matrix, _array)
add single item onto end of row
Parameters:
_matrix : Matrix To Edit
_array : Array to push to Matrix
Returns: shifted first row
slideUp(_matrix, _array)
add single item onto end of row
Parameters:
_matrix : Matrix To Edit
_array : Array to unshift to Matrix
Returns: popped last row
pullOut(_matrix, _rowNum)
add single item onto end of row
Parameters:
_matrix : Matrix To Edit
_rowNum : Row being Targeted
Returns: removed selected row
String to NumberA library that exposes a method to translate strings to numbers. Adapted from MichelT 's String to Number indicator.
catchChecksLibrary "catchChecks"
Type Check for Function Builders to allow Single item to be
passed in, and determine what to do with the item, ie: need an x value?
function that allows label, line, box, float, or even a string..
check item type? string ? 'str.tonumber(_item)' can be in the same
switch as a 'line.get_price(_item, bar_index)' both outputting float
or for pulling a value from simple, array, or matrix, one function
that can switch between them. reduce overhead of many functions.
there are many ways to use this tool, the simplest may be
string/floats on one switch or grabbing colors from line/fill/label
please Share any great recipes you come up with!
typeIs(_temp, _doMeth)
Input anything..
Determine what it is.
Parameters:
_temp : (any) Matrix, Array, or Simple Item
_doMeth : (bool) True for M/A/S , false for int/float/string.. etc..
Returns: (string) Type of item checked. ('bool' .. or 'array'.. etc..)
calcLibrary "calc"
Library for math functions. will expand over time.
split(_sumTotal, _divideBy, _forceMinimum, _haltOnError)
Split a large number into integer sized chunks
Parameters:
_sumTotal : (int) Total numbert of items
_divideBy : (int) Groups to make
_forceMinimum : (bool) force minimum number 1/group
_haltOnError : (bool) force error if too few groups
Returns: int array of items per group
UtilityFunctionsLibrary "UtilityFunctions"
Utility functions written by me
printLabelOnLastBar_string(string)
Prints string in a label on the last bar
Parameters:
string : value to print
Returns: void
printLabelOnLastBar_float(float)
Prints float in a label on the last bar
Parameters:
float : value to print
Returns: void
printSeriesInReverseOnLabels(series)
Prints a float series in labels in reverse (the first value is on the last candle, the second value is on the second to last candle, etc.)
Parameters:
series : float values to print
Returns: void
isPeriodDailyBased(string)
Returns true/false if the period is Daily based (1D, 3D, ...)
Parameters:
string : timeframe period
Returns: true/false
get_multiplier(string)
Gets the mutliplier of the timeframe passed compared to the current timeframe. If current TF is 5m and the passed timeframe period is 30m, the result will be 6
Parameters:
string : timeframe param
Returns: simple float of the multiplier
"Swap" - Bool/Position/Value : Array / Matrix / Var AutoswapLibrary "swap"
Side / Boundary Based All Types Swapper
- three automagical types for Arrays, Matrixes, and Variables
-- no signal : Long/ Short position autoswap
-- true / false : Boolean based side choice
-- Src / Thresh : if source is above or below the threshold
- two operating modes for variables, Holding mode only for arrays/matrixes
-- with two items, will automatically change between the two caveat is it does not delete table/box/line(fill VAR items automatically)
-- with three items, a neutral is available for NA input or neutral
- one function name for all of them. One import name that's easy to type/remember
-- make life easy for your conditional items.
side(source, thresh, _a, _b, _c)
side Change outputs based on position or a crossing level
Parameters:
source : (float) OPTIONAL value input
thresh : (float) OPTIONAL boundary line to cross
_a : (any) if Long/True/Above
_b : (any) if Short/False/Below
_c : (any) OPTIONAL NOT FOR MTX OR ARR... Neutral Item, if var/varip on a/b it will leave behind, ie, a table or box or line will not erase , if it's a varip you're sending in.
Returns: first, second, or third items based on input conditions
Please notify if bugs found.
Thanks.
matrixautotableLibrary "matrixautotable"
Automatic Table from Matrixes with pseudo correction for na values and default color override for missing values. uses overloads in cases of cheap float only, with additional addon for strings next, then cell colors, then text colors, and tooltips last.. basic size and location are auto, include the template to speed this up...
TODO : make bools version
var string group_table = ' Table'
var int _tblssizedemo = input.int ( 10 )
string tableYpos = input.string ( 'middle' , '↕' , inline = 'place' , group = group_table, options= )
string tableXpos = input.string ( 'center' , '↔' , inline = 'place' , group = group_table, options= , tooltip='Position on the chart.')
int _textSize = input.int ( 1 , 'Table Text Size' , inline = 'place' , group = group_table)
var matrix _floatmatrix = matrix.new (_tblssizedemo, _tblssizedemo, 0 )
var matrix _stringmatrix = matrix.new (_tblssizedemo, _tblssizedemo, 'test' )
var matrix _bgcolormatrix = matrix.new (_tblssizedemo, _tblssizedemo, color.white )
var matrix _textcolormatrix = matrix.new (_tblssizedemo, _tblssizedemo, color.black )
var matrix _tooltipmatrix = matrix.new (_tblssizedemo, _tblssizedemo, 'tool' )
// basic table ready to go with the aboec matrixes (replace in your code)
// for demo purpose, random colors, random nums, random na vals
if barstate.islast
varip _xsize = matrix.rows (_floatmatrix) -1
varip _ysize = matrix.columns (_floatmatrix) -1
for _xis = 0 to _xsize -1 by 1
for _yis = 0 to _ysize -1 by 1
_randomr = int(math.random(50,250))
_randomg = int(math.random(50,250))
_randomb = int(math.random(50,250))
_randomt = int(math.random(10,90 ))
bgcolor = color.rgb(250 - _randomr, 250 - _randomg, 250 - _randomb, 100 - _randomt )
txtcolor = color.rgb(_randomr, _randomg, _randomb, _randomt )
matrix.set(_bgcolormatrix ,_yis,_xis, bgcolor )
matrix.set(_textcolormatrix ,_yis,_xis, txtcolor)
matrix.set(_floatmatrix ,_yis,_xis, _randomr)
// random na
_ymiss = math.floor(math.random(0, _yis))
_xmiss = math.floor(math.random(0, _xis))
matrix.set( _floatmatrix ,_ymiss, _xis, na)
matrix.set( _stringmatrix ,_ymiss, _xis, na)
matrix.set( _bgcolormatrix ,_ymiss, _xis, na)
matrix.set( _textcolormatrix ,_ymiss, _xis, na)
matrix.set( _tooltipmatrix ,_ymiss, _xis, na)
// import here
import kaigouthro/matrixautotable/1 as mtxtbl
// and render table..
mtxtbl.matrixtable(_floatmatrix, _stringmatrix, _bgcolormatrix, _textcolormatrix, _tooltipmatrix, _textSize ,tableYpos ,tableXpos)
matrixtable(_floatmatrix, _stringmatrix, _bgcolormatrix, _textcolormatrix, _tooltipmatrix, _textSize, tableYpos, tableXpos) matrixtable
Parameters:
_floatmatrix : float vals
_stringmatrix : string
_bgcolormatrix : color
_textcolormatrix : color
_tooltipmatrix : string
_textSize : int
tableYpos : string
tableXpos : string
matrixtable(_floatmatrix, _stringmatrix, _bgcolormatrix, _textcolormatrix, _textSize, tableYpos, tableXpos) matrixtable
Parameters:
_floatmatrix : float vals
_stringmatrix : string
_bgcolormatrix : color
_textcolormatrix : color
_textSize : int
tableYpos : string
tableXpos : string
matrixtable(_floatmatrix, _stringmatrix, _bgcolormatrix, _txtdefcol, _textSize, tableYpos, tableXpos) matrixtable
Parameters:
_floatmatrix : float vals
_stringmatrix : string
_bgcolormatrix : color
_txtdefcol : color
_textSize : int
tableYpos : string
tableXpos : string
matrixtable(_floatmatrix, _stringmatrix, _txtdefcol, _bgdefcol, _textSize, tableYpos, tableXpos) matrixtable
Parameters:
_floatmatrix : float vals
_stringmatrix : string
_txtdefcol : color
_bgdefcol : color
_textSize : int
tableYpos : string
tableXpos : string
matrixtable(_floatmatrix, _txtdefcol, _bgdefcol, _textSize, tableYpos, tableXpos) matrixtable
Parameters:
_floatmatrix : float vals
_txtdefcol : color
_bgdefcol : color
_textSize : int
tableYpos : string
tableXpos : string
AbdulLibraryLibrary "AbdulLibrary"
The library consists of three sections:
Technical Analysis Functions - A collection of tools commonly used by day traders
Trading Setup Filters Functions - A number of filters that help day traders to screen trading signals
Candlestick Pattern Detection Functions - To detect different candlestick patterns that are used in day trading setups
Note that this would have been possible without the help of @ZenAndTheArtOfTrading as I build-up this library after completing his pine script mastery course so big thanks to him
The content of the library are:-
fibLevels(preDayClose, preDayHigh, preDayLow) Calculates Daily Pivot Point and Fibonacci Key Levels
Parameters:
preDayClose : The previous day candle close
preDayHigh : The previous day candle high
preDayLow : The previous day candle low
Returns: Returns Daily Pivot Point and Fibonacci Key Levels as a tuple
bullishFib(canHigh, canLow, fibLevel) Calculates Fibonacci Levels in Bullish move
Parameters:
canHigh : The high of the move
canLow : The low of the move
fibLevel : The Fib level as % you want to calculate
Returns: Returns The Fib level for the Bullish move
bearishFib(canHigh, canLow, fibLevel) Calculates Fibonacci Levels in Bearish move
Parameters:
canHigh : The high of the move
canLow : The low of the move
fibLevel : The Fib level as % you want to calculate
Returns: Returns The Fib level for the Bearish move
getCandleSize() Calculates the size of candle (high - low) in points
Returns: Returns candle size in points
getCandleBodySize() Calculates the size of candle (close - open) in points
Returns: Returns candle body size in points
getHighWickSize() Calculates the high wick size of candle in points
Returns: Returns The high wick size of candle in points
getLowWickSize() Calculates the low wick size of candle in points
Returns: Returns The low wick size of candle in points
getBodyPercentage() Calculates the candle body size as % of overall candle size
Returns: Returns The candle body size as % of overall candle size
isSwingHigh(period) Checks if the price has created new swing high over a period of time
Parameters:
period : The lookback time we want to check for swing high
Returns: Returns True if the current candle or the previous candle is a swing high
isSwingLow(period) Checks if the price has created new swing low over a period of time
Parameters:
period : The lookback time we want to check for swing low
Returns: Returns True if the current candle or the previous candle is a swing low
isDojiSwingHigh(period) Checks if a doji is a swing high over a period of time
Parameters:
period : The lookback time we want to check for swing high
Returns: Returns True if the doji is a swing high
isDojiSwingLow(period) Checks if a doji is a swing low over a period of time
Parameters:
period : The lookback time we want to check for swing low
Returns: Returns True if the doji is a swing low
isBigBody(atrFilter, atr, candleBodySize, multiplier) Checks if a candle has big body compared to ATR
Parameters:
atrFilter : Check if user wants to use ATR to filter candle-setup signals
atr : The ATR value to be used to compare candle body size
candleBodySize : The candle body size
multiplier : The multiplier to be used to compare candle body size
Returns: Returns Boolean true if the candle setup is big
isSmallBody(atrFilter, atr, candleBodySize, multiplier) Checks if a candle has small body compared to ATR
Parameters:
atrFilter : Check if user wants to use ATR to filter candle-setup signals
atr : The ATR value to be used to compare candle body size
candleBodySize : The candle body size
multiplier : The multiplier to be used to compare candle body size
Returns: Returns Boolean true if the candle setup is small
isHammer(fibLevel, colorMatch) Checks if a candle is a hammer based on user input parameters and candle conditions
Parameters:
fibLevel : Fib level to base candle body on
colorMatch : Checks if user needs for the candel to be green
Returns: Returns Boolean - True if the candle setup is hammer
isShootingStar(fibLevel, colorMatch) Checks if a candle is a shooting star based on user input parameters and candle conditions
Parameters:
fibLevel : Fib level to base candle body on
colorMatch : Checks if user needs for the candel to be red
Returns: Returns Boolean - True if the candle setup is star
isBullEngCan(allowance, period) Check if a candle is a bullish engulfing candle
Parameters:
allowance : How many points the candle open is allowed to be off (To allow for gaps)
period : The lookback period for swing low check
Returns: Boolean - True only if the candle is a bullish engulfing candle
isBearEngCan(allowance, period) Check if a candle is a bearish engulfing candle
Parameters:
allowance : How many points the candle open is allowed to be off (To allow for gaps)
period : The lookback period for swing high check
Returns: Boolean - True only if the candle is a bearish engulfing candle
isBullDoji(maxSize, wickLimit, colorFilter) Check if a candle is a bullish doji candle
Parameters:
maxSize : Maximum candle body size as % of total candle size to be considered as doji
wickLimit : Maximum wick size of one wick compared to the other wick
colorFilter : Checks if the doji is green
Returns: Boolean - True if the candle is a bullish doji
isBearDoji(maxSize, wickLimit, colorFilter) Check if a candle is a bearish doji candle
Parameters:
maxSize : Maximum candle body size as % of total candle size to be considered as doji
wickLimit : Maximum wick size of one wick compared to the other wick
colorFilter : Checks if the doji is red
Returns: Boolean - True if the candle is a bearish doji
isBullOutBar() Check if a candle is a bullish outside bar
Returns: Boolean - True if the candle is a bullish outside bar
isInsideBar() Check if a candle is an inside bar
Returns: Returns Boolean - True if a candle is an inside bar
Punchline_LibLibrary "Punchline_Lib"
roundSmart(float) Truncates decimal points of a float value based on the amount of digits before the decimal point
Parameters:
float : _value any number
Returns: float
tostring_smart(float) converts a float to a string, intelligently cutting off decimal points
Parameters:
float : _value any number
Returns: string
ZenLibraryLibrary "ZenLibrary"
A collection of custom tools & utility functions commonly used with my scripts.
getDecimals() Calculates how many decimals are on the quote price of the current market
Returns: The current decimal places on the market quote price
truncate(float, float) Truncates (cuts) excess decimal places
Parameters:
float : _number The number to truncate
float : _decimalPlaces (default=2) The number of decimal places to truncate to
Returns: The given _number truncated to the given _decimalPlaces
toWhole(float) Converts pips into whole numbers
Parameters:
float : _number The pip number to convert into a whole number
Returns: The converted number
toPips(float) Converts whole numbers back into pips
Parameters:
float : _number The whole number to convert into pips
Returns: The converted number
av_getPositionSize(float, float, float, float) Calculates OANDA forex position size for AutoView based on the given parameters
Parameters:
float : _balance The account balance to use
float : _risk The risk percentage amount (as a whole number - eg. 1 = 1% risk)
float : _stopPoints The stop loss distance in POINTS (not pips)
float : _conversionRate The conversion rate of our account balance currency
Returns: The calculated position size (in units - only compatible with OANDA)
getMA(int, string) Gets a Moving Average based on type
Parameters:
int : _length The MA period
string : _maType The type of MA
Returns: A moving average with the given parameters
getEAP(float) Performs EAP stop loss size calculation (eg. ATR >= 20.0 and ATR < 30, returns 20)
Parameters:
float : _atr The given ATR to base the EAP SL calculation on
Returns: The EAP SL converted ATR size
barsAboveMA(int, float) Counts how many candles are above the MA
Parameters:
int : _lookback The lookback period to look back over
float : _ma The moving average to check
Returns: The bar count of how many recent bars are above the MA
barsBelowMA(int, float) Counts how many candles are below the MA
Parameters:
int : _lookback The lookback period to look back over
float : _ma The moving average to reference
Returns: The bar count of how many recent bars are below the EMA
barsCrossedMA(int, float) Counts how many times the EMA was crossed recently
Parameters:
int : _lookback The lookback period to look back over
float : _ma The moving average to reference
Returns: The bar count of how many times price recently crossed the EMA
getPullbackBarCount(int, int) Counts how many green & red bars have printed recently (ie. pullback count)
Parameters:
int : _lookback The lookback period to look back over
int : _direction The color of the bar to count (1 = Green, -1 = Red)
Returns: The bar count of how many candles have retraced over the given lookback & direction
getBodySize() Gets the current candle's body size (in POINTS, divide by 10 to get pips)
Returns: The current candle's body size in POINTS
getTopWickSize() Gets the current candle's top wick size (in POINTS, divide by 10 to get pips)
Returns: The current candle's top wick size in POINTS
getBottomWickSize() Gets the current candle's bottom wick size (in POINTS, divide by 10 to get pips)
Returns: The current candle's bottom wick size in POINTS
getBodyPercent() Gets the current candle's body size as a percentage of its entire size including its wicks
Returns: The current candle's body size percentage
isHammer(float, bool) Checks if the current bar is a hammer candle based on the given parameters
Parameters:
float : _fib (default=0.382) The fib to base candle body on
bool : _colorMatch (default=false) Does the candle need to be green? (true/false)
Returns: A boolean - true if the current bar matches the requirements of a hammer candle
isStar(float, bool) Checks if the current bar is a shooting star candle based on the given parameters
Parameters:
float : _fib (default=0.382) The fib to base candle body on
bool : _colorMatch (default=false) Does the candle need to be red? (true/false)
Returns: A boolean - true if the current bar matches the requirements of a shooting star candle
isDoji(float, bool) Checks if the current bar is a doji candle based on the given parameters
Parameters:
float : _wickSize (default=2) The maximum top wick size compared to the bottom (and vice versa)
bool : _bodySize (default=0.05) The maximum body size as a percentage compared to the entire candle size
Returns: A boolean - true if the current bar matches the requirements of a doji candle
isBullishEC(float, float, bool) Checks if the current bar is a bullish engulfing candle
Parameters:
float : _allowance (default=0) How many POINTS to allow the open to be off by (useful for markets with micro gaps)
float : _rejectionWickSize (default=disabled) The maximum rejection wick size compared to the body as a percentage
bool : _engulfWick (default=false) Does the engulfing candle require the wick to be engulfed as well?
Returns: A boolean - true if the current bar matches the requirements of a bullish engulfing candle
isBearishEC(float, float, bool) Checks if the current bar is a bearish engulfing candle
Parameters:
float : _allowance (default=0) How many POINTS to allow the open to be off by (useful for markets with micro gaps)
float : _rejectionWickSize (default=disabled) The maximum rejection wick size compared to the body as a percentage
bool : _engulfWick (default=false) Does the engulfing candle require the wick to be engulfed as well?
Returns: A boolean - true if the current bar matches the requirements of a bearish engulfing candle
timeFilter(string, bool) Determines if the current price bar falls inside the specified session
Parameters:
string : _sess The session to check
bool : _useFilter (default=false) Whether or not to actually use this filter
Returns: A boolean - true if the current bar falls within the given time session
dateFilter(int, int) Determines if this bar's time falls within date filter range
Parameters:
int : _startTime The UNIX date timestamp to begin searching from
int : _endTime the UNIX date timestamp to stop searching from
Returns: A boolean - true if the current bar falls within the given dates
dayFilter(bool, bool, bool, bool, bool, bool, bool) Checks if the current bar's day is in the list of given days to analyze
Parameters:
bool : _monday Should the script analyze this day? (true/false)
bool : _tuesday Should the script analyze this day? (true/false)
bool : _wednesday Should the script analyze this day? (true/false)
bool : _thursday Should the script analyze this day? (true/false)
bool : _friday Should the script analyze this day? (true/false)
bool : _saturday Should the script analyze this day? (true/false)
bool : _sunday Should the script analyze this day? (true/false)
Returns: A boolean - true if the current bar's day is one of the given days
atrFilter(float, float) Checks the current bar's size against the given ATR and max size
Parameters:
float : _atr (default=ATR 14 period) The given ATR to check
float : _maxSize The maximum ATR multiplier of the current candle
Returns: A boolean - true if the current bar's size is less than or equal to _atr x _maxSize
fillCell(table, int, int, string, string, color, color) This updates the given table's cell with the given values
Parameters:
table : _table The table ID to update
int : _column The column to update
int : _row The row to update
string : _title The title of this cell
string : _value The value of this cell
color : _bgcolor The background color of this cell
color : _txtcolor The text color of this cell
Returns: A boolean - true if the current bar falls within the given dates