//+------------------------------------------------------------------+ //| BiDirectional_Weighted_Vol_v4_UI.mq5| //| Telif Hakkı 2025, Gemini AI & A.SARIHAN | //| "ACCME UI Style - Ağırlıklı Fiyat Merkezli Split ATR"| //+------------------------------------------------------------------+ #property copyright "Copyright 2025, Gemini AI & A.SARIHAN" #property link "https://www.mql5.com" #property version "4.00" // UI Update: ACCME Style #property strict #property indicator_separate_window #property indicator_buffers 4 #property indicator_plots 2 //--- Plot Ayarları #property indicator_label1 "Upper Vol (Bear SL)" #property indicator_type1 DRAW_LINE #property indicator_color1 clrLimeGreen #property indicator_style1 STYLE_SOLID #property indicator_width1 2 #property indicator_label2 "Lower Vol (Bull SL)" #property indicator_type2 DRAW_LINE #property indicator_color2 clrRed #property indicator_style2 STYLE_SOLID #property indicator_width2 2 //==================================================================// // BÖLÜM 1: GİRİŞ PARAMETRELERİ //==================================================================// input group "Hesaplama Ayarları"; input int InpPeriod = 14; // Periyot input bool InpUseRMA = true; // True: ATR (RMA), False: SMA input group "Panel Ayarları (ACCME Style)"; input bool InpShowPanel = true; // Paneli Göster input int InpPanelX = 20; // Panel X Konumu input int InpPanelY = 40; // Panel Y Konumu //==================================================================// // PANEL TASARIM SABİTLERİ (ACCME DARK THEME) //==================================================================// #define PANEL_W 300 #define PANEL_H 250 // İndikatör için biraz daha kompakt #define UI_PREFIX "BDV_UI_" // Renk Paleti (ACCME Gold/Dark) #define CLR_BG_MAIN C'30,40,45' // Ana Arka Plan (Koyu Mavi-Gri) #define CLR_BG_BOX C'20,28,32' // Veri Kutusu Arka Planı #define CLR_BORDER C'60,70,75' // İnce Çerçeve #define CLR_TEXT_LBL C'160,170,180'// Etiket Rengi #define CLR_TEXT_VAL clrWhite // Değer Rengi #define CLR_ACCENT clrGold // Başlık Rengi #define CLR_UP clrLime // Yükseliş/Pozitif #define CLR_DOWN C'255,80,80' // Düşüş/Negatif #define CLR_NEUTRAL clrSilver // Nötr //==================================================================// // GLOBAL DEĞİŞKENLER & TAMPONLAR //==================================================================// double BufferUpVol[]; // Yukarı Volatilite double BufferDownVol[]; // Aşağı Volatilite (Negatif çizim için) double BufferRawUp[]; // Ham Hesaplama double BufferRawDown[]; // Ham Hesaplama //==================================================================// // BÖLÜM 2: GÖRSEL ARAYÜZ SINIFI (CDisplay) //==================================================================// class CDisplay { private: void CreateRect(string name, int x, int y, int w, int h, color bg, color border=clrNONE) { string objName = UI_PREFIX + name; if(ObjectFind(0, objName) < 0) ObjectCreate(0, objName, OBJ_RECTANGLE_LABEL, 0, 0, 0); ObjectSetInteger(0, objName, OBJPROP_XDISTANCE, x); ObjectSetInteger(0, objName, OBJPROP_YDISTANCE, y); ObjectSetInteger(0, objName, OBJPROP_XSIZE, w); ObjectSetInteger(0, objName, OBJPROP_YSIZE, h); ObjectSetInteger(0, objName, OBJPROP_BGCOLOR, bg); ObjectSetInteger(0, objName, OBJPROP_BORDER_TYPE, BORDER_FLAT); ObjectSetInteger(0, objName, OBJPROP_COLOR, border); ObjectSetInteger(0, objName, OBJPROP_CORNER, CORNER_LEFT_UPPER); ObjectSetInteger(0, objName, OBJPROP_WIDTH, 1); ObjectSetInteger(0, objName, OBJPROP_BACK, false); ObjectSetInteger(0, objName, OBJPROP_SELECTABLE, false); ObjectSetInteger(0, objName, OBJPROP_ZORDER, 10); } void CreateLabel(string name, string text, int x, int y, color c, int size=8, string font="Verdana", bool bold=false) { string objName = UI_PREFIX + name; if(ObjectFind(0, objName) < 0) ObjectCreate(0, objName, OBJ_LABEL, 0, 0, 0); ObjectSetInteger(0, objName, OBJPROP_XDISTANCE, x); ObjectSetInteger(0, objName, OBJPROP_YDISTANCE, y); ObjectSetString(0, objName, OBJPROP_TEXT, text); ObjectSetInteger(0, objName, OBJPROP_COLOR, c); ObjectSetInteger(0, objName, OBJPROP_FONTSIZE, size); if(bold) ObjectSetString(0, objName, OBJPROP_FONT, font + " Bold"); else ObjectSetString(0, objName, OBJPROP_FONT, font); ObjectSetInteger(0, objName, OBJPROP_CORNER, CORNER_LEFT_UPPER); ObjectSetInteger(0, objName, OBJPROP_BACK, false); ObjectSetInteger(0, objName, OBJPROP_SELECTABLE, false); ObjectSetInteger(0, objName, OBJPROP_ZORDER, 11); } public: void Init() { if(!InpShowPanel) return; // 1. Ana Çerçeve CreateRect("MainBG", InpPanelX, InpPanelY, PANEL_W, PANEL_H, CLR_BG_MAIN, CLR_BORDER); // 2. Başlık CreateLabel("Header", "SPLIT VOLATILITY v4", InpPanelX + 15, InpPanelY + 10, CLR_ACCENT, 9, "Verdana", true); int y = InpPanelY + 40; int x_lbl = InpPanelX + 15; int x_box = InpPanelX + 15; int box_w = PANEL_W - 30; // --- KUTU 1: PİYASA DURUMU --- CreateLabel("Lbl_Gen", "PİYASA DURUMU", x_lbl, y, CLR_TEXT_LBL, 7); y += 15; CreateRect("Box_Gen", x_box, y, box_w, 55, CLR_BG_BOX, CLR_BORDER); CreateLabel("Val_Symbol", "Symbol: --", x_box + 10, y + 5, CLR_TEXT_VAL); CreateLabel("Val_Time", "Time: --:--", x_box + 140, y + 5, CLR_TEXT_VAL); CreateLabel("Val_Status", "YÖN: --", x_box + 10, y + 22, CLR_TEXT_VAL, 9, "Verdana", true); CreateLabel("Val_Ratio", "Fark: %0", x_box + 140, y + 22, CLR_TEXT_VAL, 8); y += 65; // --- KUTU 2: SL MESAFELERİ (SEKANAS) --- CreateLabel("Lbl_SL", "SL MESAFELERİ (Sekanas)", x_lbl, y, CLR_TEXT_LBL, 7); y += 15; CreateRect("Box_SL", x_box, y, box_w, 60, CLR_BG_BOX, CLR_BORDER); // Short SL Satırı CreateLabel("Lbl_Short", "SHORT SL (Up):", x_box + 10, y + 10, CLR_TEXT_LBL); CreateLabel("Val_Short", "0.00 sk", x_box + 120, y + 10, CLR_UP, 10, "Consolas", true); // LimeGreen // Long SL Satırı CreateLabel("Lbl_Long", "LONG SL (Down):", x_box + 10, y + 32, CLR_TEXT_LBL); CreateLabel("Val_Long", "0.00 sk", x_box + 120, y + 32, CLR_DOWN, 10, "Consolas", true); // Red // Footer CreateLabel("Footer", "Bi-Directional Weighted Logic", InpPanelX + 15, InpPanelY + PANEL_H - 15, clrGray, 7, "Arial Italic"); } void Update(string symbol, double up_val, double down_val, double price) { if(!InpShowPanel) return; // 1. Sekanas Hesabı: (Değer / Fiyat) * 10000 double sek_up = 0.0, sek_down = 0.0; if(price > 0) { sek_up = (up_val / price) * 10000.0; sek_down = (down_val / price) * 10000.0; } // 2. Durum Belirleme string statusTxt = "DENGELİ"; color statusClr = CLR_NEUTRAL; double diff_percent = 0.0; double total = sek_up + sek_down; if(total > 0) diff_percent = ((sek_up - sek_down) / total) * 100.0; if(sek_up > sek_down * 1.1) { statusTxt = "BASKIN: YUKARI"; statusClr = CLR_UP; } else if(sek_down > sek_up * 1.1) { statusTxt = "BASKIN: AŞAĞI"; statusClr = CLR_DOWN; } // --- GUI GÜNCELLEME --- // Box 1 ObjectSetString(0, UI_PREFIX + "Val_Symbol", OBJPROP_TEXT, symbol); ObjectSetString(0, UI_PREFIX + "Val_Time", OBJPROP_TEXT, TimeToString(TimeCurrent(), TIME_MINUTES)); ObjectSetString(0, UI_PREFIX + "Val_Status", OBJPROP_TEXT, statusTxt); ObjectSetInteger(0, UI_PREFIX + "Val_Status", OBJPROP_COLOR, statusClr); ObjectSetString(0, UI_PREFIX + "Val_Ratio", OBJPROP_TEXT, StringFormat("Skew: %+.1f%%", diff_percent)); // Box 2 (Değerler) ObjectSetString(0, UI_PREFIX + "Val_Short", OBJPROP_TEXT, StringFormat("%.2f sk", sek_up)); ObjectSetString(0, UI_PREFIX + "Val_Long", OBJPROP_TEXT, StringFormat("%.2f sk", sek_down)); } void Destroy() { ObjectsDeleteAll(0, UI_PREFIX); } }; CDisplay g_display; //==================================================================// // BÖLÜM 3: STANDART INDIKATOR FONKSIYONLARI //==================================================================// int OnInit() { SetIndexBuffer(0, BufferUpVol, INDICATOR_DATA); SetIndexBuffer(1, BufferDownVol, INDICATOR_DATA); SetIndexBuffer(2, BufferRawUp, INDICATOR_CALCULATIONS); SetIndexBuffer(3, BufferRawDown, INDICATOR_CALCULATIONS); string short_name = StringFormat("Bi-Dir Vol (%d)", InpPeriod); IndicatorSetString(INDICATOR_SHORTNAME, short_name); IndicatorSetInteger(INDICATOR_DIGITS, 1); IndicatorSetDouble(INDICATOR_LEVELVALUE, 0, 0.0); PlotIndexSetDouble(0, PLOT_EMPTY_VALUE, 0.0); PlotIndexSetDouble(1, PLOT_EMPTY_VALUE, 0.0); // Paneli Başlat g_display.Init(); return(INIT_SUCCEEDED); } void OnDeinit(const int reason) { g_display.Destroy(); ChartRedraw(0); } int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { if(rates_total < InpPeriod + 1) return(0); int start = prev_calculated - 1; if(start < 1) start = 1; // --- HESAPLAMA DÖNGÜSÜ --- for(int i = start; i < rates_total; i++) { // 1. Pivot ve Ham Sapma double weighted_pivot = (high[i] + low[i] + 2.0 * close[i]) / 4.0; double raw_up = high[i] - weighted_pivot; if(raw_up < 0) raw_up = 0; double raw_down = weighted_pivot - low[i]; if(raw_down < 0) raw_down = 0; BufferRawUp[i] = raw_up; BufferRawDown[i] = raw_down; // 2. Yumuşatma (Smoothing) double smoothed_up = 0.0; double smoothed_down = 0.0; if(i < InpPeriod) { BufferUpVol[i] = 0.0; BufferDownVol[i] = 0.0; if(i == InpPeriod - 1) { double sum_u = 0, sum_d = 0; for(int k = 0; k < InpPeriod; k++) { sum_u += BufferRawUp[i-k]; sum_d += BufferRawDown[i-k]; } smoothed_up = sum_u / InpPeriod; smoothed_down = sum_d / InpPeriod; BufferUpVol[i] = smoothed_up; BufferDownVol[i] = -smoothed_down; // Negatif Çizim } } else { double prev_up = BufferUpVol[i-1]; double prev_down_abs = MathAbs(BufferDownVol[i-1]); if(InpUseRMA) { smoothed_up = (prev_up * (InpPeriod - 1) + raw_up) / InpPeriod; smoothed_down = (prev_down_abs * (InpPeriod - 1) + raw_down) / InpPeriod; } else // SMA { double sum_u = 0, sum_d = 0; for(int k = 0; k < InpPeriod; k++) { sum_u += BufferRawUp[i-k]; sum_d += BufferRawDown[i-k]; } smoothed_up = sum_u / InpPeriod; smoothed_down = sum_d / InpPeriod; } BufferUpVol[i] = smoothed_up; BufferDownVol[i] = -smoothed_down; } } // --- PANEL GÜNCELLEME --- if(InpShowPanel) { int last_idx = rates_total - 1; // UI sınıfına son kapanış verilerini gönder g_display.Update(_Symbol, BufferUpVol[last_idx], MathAbs(BufferDownVol[last_idx]), close[last_idx]); } return(rates_total); } //+------------------------------------------------------------------+