dennishh2024 Posted August 18 Report Share Posted August 18 Is it possible to make an indicator or as a paintbar, like a standard deviation volume bar, like: https://toslc.thinkorswim.com/center/reference/Tech-Indicators/studies-library/R-S/RelativeVolumeStDev With color coded volume bars according to how many standard deviations the volume of the bar is. The look back period should be large, like 200 bars from the regular sessions only. The indicator is to be used on a 1-min chart. In mathematical sense, the Relative Volume StDev is calculated as the ratio of the volume to its simple moving average (SMA), expressed in standard deviations. This value is plotted as a histogram as how many standard deviations the volume of that candle is; its bars are highlighted when the volume is unusually large. Grey: less then 1 standard deviation from the mean Blue: between 1 and 1,5 standard deviation from the mean Light blue: Between 1,5 and 2,5 standard deviation from the mean Fuchsia, more then 2,5 standard deviations from the mean C# generated script from chatgpt….. : using System; using System.Linq; using System.Drawing; using System.Collections.Generic; public class RelativeVolumeStDev { private int lookback = 21; // Time Frame Base private int signalLength = 8; // Signal Oscillation Length private int lengthBand = 55; // Base Oscillation Length private List<double> volumes = new List<double>(); private List<double> pervolList = new List<double>(); public void OnBarUpdate(double volume, double close, double open) { volumes.Add(volume); if (volumes.Count < lookback) return; // Calculate average volume double avvol = volumes.Skip(Math.Max(0, volumes.Count - lookback)).Sum() / lookback; // Calculate percentage volume deviation double pervol = (volume - avvol) / avvol * 100; pervolList.Add(pervol); // Calculate standard deviation of percentage volume deviation double vstd = CalculateStandardDeviation(pervolList.Skip(Math.Max(0, pervolList.Count - lookback)).ToArray()); // Determine the color of the volume bar based on standard deviation Color barColor = Color.Gray; // Default color for < 1 standard deviation if (pervol >= 1 * vstd && pervol < 1.5 * vstd) barColor = Color.Blue; else if (pervol >= 1.5 * vstd && pervol < 2.5 * vstd) barColor = Color.LightBlue; else if (pervol >= 2.5 * vstd) barColor = Color.Fuchsia; // Plot the colored volume bar PlotVolumeBar(volume, barColor); // Optional: Plot the signal line and standard deviation bands if (pervolList.Count >= signalLength) { double signal = pervolList.Skip(Math.Max(0, pervolList.Count - signalLength)).Average(); PlotSignalLine(signal, Color.Red); if (pervolList.Count >= lengthBand) { double ma = pervolList.Skip(Math.Max(0, pervolList.Count - lengthBand)).Average(); double offs = 1.644 * CalculateStandardDeviation(pervolList.Skip(Math.Max(0, pervolList.Count - lengthBand)).ToArray()); double offs2 = 0.994 * CalculateStandardDeviation(pervolList.Skip(Math.Max(0, pervolList.Count - lengthBand)).ToArray()); double up = ma + offs; double dn = ma - offs; double up2 = ma + offs2; double dn2 = ma - offs2; PlotBand(up, dn, ma, up2, dn2); } } } private double CalculateStandardDeviation(double[] values) { double avg = values.Average(); return Math.Sqrt(values.Sum(v => Math.Pow(v - avg, 2)) / values.Length); } private void PlotVolumeBar(double volume, Color color) { // Implement your plotting logic here to draw the volume bar with the given color Console.WriteLine($"Volume: {volume}, Color: {color}"); } private void PlotSignalLine(double signal, Color color) { // Implement your plotting logic here to draw the signal line Console.WriteLine($"Signal Line: {signal}, Color: {color}"); } private void PlotBand(double up, double dn, double ma, double up2, double dn2) { // Implement your plotting logic here to draw the bands Console.WriteLine($"Bands: up={up}, dn={dn}, ma={ma}, up2={up2}, dn2={dn2}"); } } Integration: Plotting: You need to implement the PlotVolumeBar, PlotSignalLine, and PlotBand methods to integrate this code with your charting platform. Data Feeds: Ensure that the OnBarUpdate method is called for each new bar with the correct volume, close, and open prices. Quote Link to comment Share on other sites More sharing options...
Mike Medved Posted August 22 Report Share Posted August 22 How's this: Quote Link to comment Share on other sites More sharing options...
dennishh2024 Posted August 22 Author Report Share Posted August 22 Yeah that could definitely work! Maybe change the colouring scheme a bit. Like anything below 1 st.dev. less of a signal color like light grey maybe. Because we are saying that from a volume-perspective the associated candle is not significant. And volumes between st.dev. 1.01 and 1.99 a signal colour, and 2.0 and above a signal colour? And I was wondering what you have as a look back period to calculate the rel.vol.st.dev. Is it all loaded candles on the chart? Or a big portion of it? Quote Link to comment Share on other sites More sharing options...
Mike Medved Posted August 22 Report Share Posted August 22 The look back is the same as the SMA period. You can set it as an indicator parameter. I guess I could make it a 3-color thing. Quote Link to comment Share on other sites More sharing options...
Mike Medved Posted August 22 Report Share Posted August 22 Will be in next beta Will be in next beta Quote Link to comment Share on other sites More sharing options...
dennishh2024 Posted August 23 Author Report Share Posted August 23 (edited) Thanks Mike!! Looking forward to using it Edited August 23 by dennishh2024 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.