Price Data #
open, high, low, close, volume, oi, hl2, hlc3, ohlc4Core OHLCV data series.
Example
# Access current bar data
current_close = close
current_volume = volume
# Calculate typical price manually
my_hlc3 = (high + low + close) / 3BLAZESCRIPT / LANGUAGE DOCUMENTATION
open, high, low, close, volume, oi, hl2, hlc3, ohlc4Core OHLCV data series.
# Access current bar data
current_close = close
current_volume = volume
# Calculate typical price manually
my_hlc3 = (high + low + close) / 3position_size, position_avg_price, open_pnl, bars_in_trade, max_runup, max_drawdownReal-time in-trade metrics.
# Check if we are in a trade
in_trade = position_size != 0
# Stop loss based on PnL
panic_exit = open_pnl < -1000PDH, PDL, PDC, PDO, CDH, CDL, CDOPrevious and Current Day's Open, High, Low, and Close.
# Breakout of Previous Day High
breakout = close > PDH
# Gap up condition
gap_up = CDO > PDCtime, Date, DayOfMonth, DayOfWeek, DayOfYear, DaysSince1900, DayFirstBar, DayLastBarTime and daily boundary booleans.
# 1. Time-based trading window (Format HHMM)
# Example: 9:30 AM to 11:00 AM
trading_window = (time >= 930) & (time <= 1100)
# 2. Day of Week (1=Monday, ..., 5=Friday)
is_friday = DayOfWeek == 5
# 3. Session Boundaries
# Reset state on first bar of day
if DayFirstBar:
my_var = 0
# Close positions on last bar
exit_on_close = DayLastBar
# 4. Specific Date (YYYYMMDD)
is_budget_day = Date == 20230201abs, round, min, max, avg, sumStandard mathematical functions.
# Calculate average price
avg_price = avg(open, high, low, close)
# Round to 2 decimal places
rounded_rsi = round(rsi_14, 2)
# Sum of volume over 10 bars
vol_sum = sum(volume, 10)pow, sqrt, square, log, exp, sign, ceil, floorAlgebraic and logarithmic operations.
# Logarithmic return
log_ret = log(close / close[1])
# Standard deviation calculation steps
variance = sum(square(close - avg(close, 20)), 20) / 20
std_dev = sqrt(variance)sin, cos, tan, asin, acos, atan, e_const, pi_const, phi_constTrig functions and constants.
# Sine wave based on bar index
cycle = sin(BarIndex * pi_const / 10)
# Use constants
circumference = 2 * pi_const * radius(source, leftbars, rightbars)Identifies local pivot points.
# Find a pivot high (5 bars left, 2 bars right)
pivot_high = peak(high, 5, 2)
# Find a pivot low
pivot_low = trough(low, 5, 2)(source, leftbars, rightbars, n=1)Bar offset to local pivot points.
# Bars since last pivot high
bars_since_peak = peakbars(high, 5, 2)
# Get the value of that peak
peak_val = high[bars_since_peak](source, leftbars, rightbars)Trend structure identification.
# Check for Higher High
is_hh = HigherHigh(high, 5, 2)
# Check for Lower Low
is_ll = LowerLow(low, 5, 2)BarIndex, BeginValue, EndValue, medianArray position indexing and statistical utilities.
# Current bar number
current_bar = BarIndex
# Median price over 20 bars
med_price = median(close, 20)