//+------------------------------------------------------------------+ // https://forex-station.com/post1295576989.html#p1295576989 //+------------------------------------------------------------------+ #property copyright "c. 2025, Forex-Station" #property link "http://www.Forex-Station.com/" #property indicator_chart_window #property indicator_buffers 14 #property indicator_plots 13 #property indicator_label1 "BB1 Upper" #property indicator_type1 DRAW_LINE #property indicator_color1 clrSpringGreen #property indicator_label2 "BB1 Lower" #property indicator_type2 DRAW_LINE #property indicator_color2 clrHotPink #property indicator_width1 2 #property indicator_width2 2 #property indicator_label3 "BB2 Upper" #property indicator_type3 DRAW_LINE #property indicator_color3 clrSpringGreen #property indicator_label4 "BB2 Lower" #property indicator_type4 DRAW_LINE #property indicator_color4 clrHotPink #property indicator_width3 1 #property indicator_width4 1 #property indicator_label5 "BB3 Upper" #property indicator_type5 DRAW_LINE #property indicator_color5 clrSpringGreen #property indicator_label6 "BB3 Lower" #property indicator_type6 DRAW_LINE #property indicator_color6 clrHotPink #property indicator_style5 STYLE_DOT #property indicator_style6 STYLE_DOT #property indicator_label7 "BB4 Upper" #property indicator_type7 DRAW_LINE #property indicator_color7 clrSpringGreen #property indicator_label8 "BB4 Lower" #property indicator_type8 DRAW_LINE #property indicator_color8 clrHotPink #property indicator_style7 STYLE_DOT #property indicator_style8 STYLE_DOT #property indicator_label9 "BB5 Upper" #property indicator_type9 DRAW_LINE #property indicator_color9 clrSpringGreen #property indicator_label10 "BB5 Lower" #property indicator_type10 DRAW_LINE #property indicator_color10 clrHotPink #property indicator_style9 STYLE_DOT #property indicator_style10 STYLE_DOT #property indicator_label11 "BB5 Upper" #property indicator_type11 DRAW_LINE #property indicator_color11 clrSpringGreen #property indicator_label12 "BB5 Lower" #property indicator_type12 DRAW_LINE #property indicator_color12 clrHotPink #property indicator_style11 STYLE_DOT #property indicator_style12 STYLE_DOT #property indicator_label13 "Middle SMA" #property indicator_type13 DRAW_COLOR_LINE #property indicator_color13 clrLime, clrRed #property indicator_width13 5 input int MA_Period = 20; input ENUM_APPLIED_PRICE MA_Price = PRICE_CLOSE; input double BB_Deviation1 = 2.0; input double BB_Deviation2 = 1.9; input double BB_Deviation3 = 1.8; input double BB_Deviation4 = 1.7; input double BB_Deviation5 = 1.6; input double BB_Deviation6 = 1.5; //Forex-Station button template start41; copy and paste input string button_note1 = "------------------------------"; // ------------------------------ input int btn_Subwindow = 0; // What window to put the button on. If <0, the button will use the same sub-window as the indicator. input ENUM_BASE_CORNER btn_corner = CORNER_LEFT_UPPER; // chart btn_corner for anchoring input string btn_text = "BB"; // Display id input string btn_Font = "Arial"; // button font name input int btn_FontSize = 9; // btn__font size input color btn_text_ON_color = clrLime; // ON color when the button is turned on input color btn_text_OFF_color = clrRed; // OFF color when the button is turned off input color btn_background_color = clrDimGray; // background color of the button input color btn_border_color = clrBlack; // border color the button input int button_x = 100; // Horizontal location input int button_y = 135; // Vertical location input int btn_Width = 80; // btn__width input int btn_Height = 20; // btn__height input string UniqueButtonID = "Bollinger"; // Unique ID for each button input string button_note2 = "------------------------------"; // ------------------------------ string IndicatorObjPrefix, buttonId; bool IndicatorEnabled = true; //Forex-Station button template end41; copy and paste // Buffers double bb1Upper[], bb1Lower[], bb2Upper[], bb2Lower[], bb3Upper[], bb3Lower[], bb4Upper[], bb4Lower[], bb5Upper[], bb5Lower[], bb6Upper[], bb6Lower[]; double mid[], priceBuffer[]; double smaBuffer[], smaColorIndex[]; int bbHandle1, bbHandle2, bbHandle3, bbHandle4, bbHandle5, bbHandle6; //+------------------------------------------------------------------------------------------------------------------+ //Forex-Station button template start42; copy and paste int OnInit() { IndicatorObjPrefix = "__" + btn_text + "__"; // The leading "_" gives buttonId a *unique* prefix. Furthermore, prepending the swin is usually unique unless >2+ of THIS indy are displayed in the SAME sub-window. (But, if >2 used, be sure to shift the buttonId position) buttonId = "_" + UniqueButtonID + IndicatorObjPrefix + "_BT_"; // Check if button already exists and get its current state bool buttonExists = (ObjectFind(0, buttonId) >= 0); bool currentButtonState = false; // Default to OFF if (buttonExists) { // Button exists - get its current state currentButtonState = (bool)ObjectGetInteger(0, buttonId, OBJPROP_STATE); Print("Button exists with state: ", currentButtonState ? "ON" : "OFF"); } else { // Create new button createButton(buttonId, btn_text, btn_Width, btn_Height, btn_Font, btn_FontSize, btn_background_color, btn_border_color, btn_text_ON_color); ObjectSetInteger(0, buttonId, OBJPROP_YDISTANCE, button_y); ObjectSetInteger(0, buttonId, OBJPROP_XDISTANCE, button_x); Print("New button created with default state: ON"); } IndicatorEnabled = currentButtonState; // Initialize indicator regardless of state to ensure proper buffer setup init2(); // Set plot visibility based on actual button state if (currentButtonState) { ObjectSetInteger(0, buttonId, OBJPROP_COLOR, btn_text_ON_color); ObjectSetString(0, buttonId, OBJPROP_TEXT, btn_text); for(int i=0; i mid[i - 1]) ? 0 : 1; // 0: lime, 1: red double sum = 0.0, sumsq = 0.0; for (int j = 0; j < MA_Period; j++) { double price = GetPrice(MA_Price, open[i - j], high[i - j], low[i - j], close[i - j]); sum += price; sumsq += price * price; } double mean = sum / MA_Period; double var = (sumsq / MA_Period) - (mean * mean); double std = MathSqrt(MathMax(var, 0)); bb1Upper[i] = mean + BB_Deviation1 * std; bb1Lower[i] = mean - BB_Deviation1 * std; bb2Upper[i] = mean + BB_Deviation2 * std; bb2Lower[i] = mean - BB_Deviation2 * std; bb3Upper[i] = mean + BB_Deviation3 * std; bb3Lower[i] = mean - BB_Deviation3 * std; bb4Upper[i] = mean + BB_Deviation4 * std; bb4Lower[i] = mean - BB_Deviation4 * std; bb5Upper[i] = mean + BB_Deviation5 * std; bb5Lower[i] = mean - BB_Deviation5 * std; bb6Upper[i] = mean + BB_Deviation6 * std; bb6Lower[i] = mean - BB_Deviation6 * std; } return rates_total; } //+------------------------------------------------------------------------------------------------------------------+ double GetPrice(int mode, double o, double h, double l, double c) { switch (mode) { case PRICE_OPEN: return o; case PRICE_HIGH: return h; case PRICE_LOW: return l; case PRICE_MEDIAN: return (h + l) / 2.0; case PRICE_TYPICAL: return (h + l + c) / 3.0; case PRICE_WEIGHTED: return (h + l + c + c) / 4.0; default: return c; } } //+------------------------------------------------------------------------------------------------------------------+