Volatility is a measure that allows you to estimate the "risk" of an asset. There are different types of volatility: Implied volatility: This is the estimated volatility of an asset's price. Historical volatility: This is the realized volatility of an asset over a specific time period. It is also called the statistical volatility. For intraday traders and those looking for an easier way to measure volatility, you can use the true range to measure intraday volatility. True Range The True range indicator was developed by J. Welles Wilder Jr. in the 1970's. It is a better measure of the intraday volatility than the "Range" (which the difference between the session/period high and low) because the latter understates the volatility since it only measures volatility that occurs during a bar/session and ignores overnight volatility. To fix this, the True Range uses the bar's high, low and previous bar's close. By combining these variables, the true range considers both the intraday and overnight part of the price's volatility. The true range is calculated by taking the greatest of the following variables:  High (current bar) less low  High (current bar) less previous bar's close  Previous bar's close less low (current bar) Implementing the Average True Range Indicator First, let us implement the different variables described in the previous paragraph then find which one is the greatest (true range). a = high  low; b = high  close[1]; c = close[1]  low; tr = max(a, max(b, c)); To calculate the average true range (ATR), we simply apply a moving average to the true range. d = sma(tr, 10); This will return the 10bar average true range. Note that QuantShare already has a builtin function ("Atr") that calculates the average true range. Example: d = Atr(10); How Day Traders Measure Intraday Volatility Let us say you are working with oneminute data and you want to calculate the intraday volatility (Average true range based on session high, low and close). As you might have guessed, the calculation of the intraday volatility must be based on daily data. Steps:  Change the time frame to daily TimeframeSet(1); We use negative time frame to reference daily data when working with intraday data (1 = 1day period = daily)  Calculate the average true range of the previous 10 trading days a = atr(10);  Restore the default time frame (oneminute data) TimeframeRestore();  Decompress the result so that daily data is synchronized with the oneminute data a = timeframedecompress(a); The complete formula is as follows: TimeframeSet(1); a = atr(10); TimeframeRestore(); a = timeframedecompress(a); plot(a, "ATR"); There is also another way to implement the same thing. Here is the formula: b = TimeframeApply(1, atr(10)); b = timeframedecompress(b); plot(b, "ATR", colorGreen); The "TimeframeApply" function calculates a specific series in a different time frame. It replaces the "TimeframeSet" and "TimeframeRestore" functions. Example of Strategy Using the true range Indicator Let us implement the following trading system:  Buy when the intraday volatility as measured by ATR is increasing and when price crosses above 10bar moving average  Sell at the end of the trading session Here is how to create a trading system: How to create a trading system And here is the formula that you should use to implement the above strategy: rule1 = TimeframeApply(1, atr(1) > ref(atr(1), 1)); // Ref: Reference previous bar's value rule1 = timeframedecompress(rule1); buy = rule1 and cross(close, sma(10)); sell = hour() >=16;
