I asked AI to give me the code for a Bollinger band Squeeze and the result was not very good. I have modified it so at least it is valid but it still won’t provide an alert to a BB squeeze. can I ask why it does not work as it looks good to me?
/ Define parameters for Bollinger Bands
Length = 3; // Number of periods for the moving average
StdDevMultiplier = 2; // Standard deviation multiplier for the bands
SqueezeThreshold = 0.02; // Threshold for the squeeze (2%)
The AI Bot is not great at scripting currently, it is why we are working on training a second bot, specific to scripting. There are a number of hurdles to get past with the technology so that it understands Optuma Syntax well enough to assist in questions like this.
I ran your query past the bot currently in training, it has come up with something that should work, or at least get you going in the right direction:
// Set Bollinger Band properties with a 20-period moving average and 2 standard deviations
b1 = BB(BARS=20, STDDEV=2);
// Calculate the width of the Bollinger Bands
bandWidth = b1.UpperLine - b1.LowerLine;
// Calculate the bandwidth from 5 bars ago
previousBandWidth = OFFSET(bandWidth, OFFSET=5);
// Define the condition for a 50% drop in bandwidth
squeezeCondition = bandWidth < (previousBandWidth * 0.5);
// Output the squeeze condition
plot1 = squeezeCondition; // This will plot a value of 1 when a squeeze is detected, and 0 otherwise
You can modify this as needed but I have checked it here and it appears to work.