Bollinger Bands Squeeze detector

 
Hello everyone so in this EA i have tried to detect a squeeze by subtracting the values of the upperband and the lowerband then dividing by the middle band to get the bandwidth i then created a squeezethreshold of 2% and check if the bandwidth value is below the squeeze threshhold if it is then i would have detected a squeeze so i added bandwidth indicator to see what i was doing wrong and i also commented the value of the bandwidth on the chart and the value seem very high and unrealistic i had rounded it as a percentage i have attached file bbands%.png for this and also squeezef.png . If anyone can please help me to accurately detect  squeeze .Thank you in advance.
#include <Trade/Trade.mqh>
int bars =        Bars(_Symbol, PERIOD_CURRENT);

input int MagicNumber = 212121;
string            RSI_Name;
string            BB_Name;
string            YMA_Name;
string            RMA_Name;
int               handleBB;
int               handleRSI;
int               handleMA;
int               handleMA1;

//indicator arrays
double RSI[];
double bb_upper[];
double bb_lower[];
double bb_middle[];
double Yellow_ma[];
double Red_ma[];
CTrade trade;
int OnInit()
  {
//---
 RSI_Name = ChartIndicatorName(0,1,0);
   BB_Name = ChartIndicatorName(0,1,1);
   YMA_Name = ChartIndicatorName(0,1,2);
   RMA_Name = ChartIndicatorName(0,1,3);

   handleRSI = ChartIndicatorGet(0,1,RSI_Name);
   if(handleRSI == INVALID_HANDLE)
      Alert(__FUNCTION__,"> Handle is Invalid..Check the name!",RSI_Name);
   handleBB = ChartIndicatorGet(0,1,BB_Name);
   if(handleBB == INVALID_HANDLE)
      Alert(__FUNCTION__,"> Handle is Invalid..Check the name!",BB_Name);

   handleMA = ChartIndicatorGet(0,1,YMA_Name);
   if(handleMA == INVALID_HANDLE)
      Alert(__FUNCTION__,"> Handle is Invalid..Check the name!",YMA_Name);
   handleMA1 = ChartIndicatorGet(0,1,RMA_Name);
   if(handleMA1 == INVALID_HANDLE)
      Alert(__FUNCTION__,"> Handle is Invalid..Check the name!",RMA_Name);



   trade.SetExpertMagicNumber(MagicNumber);

   
//---
   return(INIT_SUCCEEDED);
  }

void OnDeinit(const int reason)
  {
//---
    IndicatorRelease(handleBB);
   IndicatorRelease(handleMA);
   IndicatorRelease(handleMA1);
   IndicatorRelease(handleRSI);
  }

void OnTick()
  {
//---|creating the logi c of the bot|
   if(handleBB!=INVALID_HANDLE && handleMA!=INVALID_HANDLE && handleMA1!=INVALID_HANDLE && handleRSI!=INVALID_HANDLE){
    (CopyBuffer(handleBB,1,1,bars,bb_upper));
      (CopyBuffer(handleBB,2,1,bars,bb_lower));
      (CopyBuffer(handleBB,0,1,bars,bb_middle));
       datetime time =iTime(_Symbol,PERIOD_CURRENT,0);
    
      double bandwidth= 100*((bb_upper[0]- bb_lower[0])/bb_lower[0]);
      Print("bandwidth ",bandwidth," time ",time);
       // Calculate the squeeze threshold based on the upper band value
      double squeezeThreshold =  2.0;
      if( bandwidth <squeezeThreshold){
   
      Print("Squeeze detected ",bandwidth," time ",time);
      }
      
   }
  }



Documentation on MQL5: Python Integration / order_calc_margin
Documentation on MQL5: Python Integration / order_calc_margin
  • www.mql5.com
order_calc_margin - Python Integration - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
Files:
squeezef.PNG  55 kb
bband1.PNG  18 kb
 
Your topic has been moved to the section: Expert Advisors and Automated Trading
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
 

What is the point of your post?

You have not asked a question nor explained anything in detail.

 
Fernando Carreiro #:

What is the point of your post?

You have not asked a question nor explained anything in detail.

Okay am working on an expert advisor that uses bollinger bands squeeze strategy , so i have been trying to detect a squeeze and i came across the fomular bandwidth = 100*((upperband-lowerband)/middleband) and from https://forextraininggroup.com/catching-breakouts-with-the-bollinger-band-squeeze/ article a squeeze is usually formed when the bandwidth value is below 4% or 2% threshold i have printed my bandwidth and the value is over 100% which does'nt make sense . I need help or guidence to rectify this error

Catching Breakouts with the Bollinger Band Squeeze
Catching Breakouts with the Bollinger Band Squeeze
  • Vic Patel
  • forextraininggroup.com
The Bollinger band squeeze play is a high probability trading set up that offers a solid risk to reward profile. There are a few variations of the squeeze set up that you can trade depending on your preference. We’ll discuss some basic foundations of the Bollinger band study, the importance of understanding the cyclical nature of market...