//+------------------------------------------------------------------+ //| OSC_OC_Mirror_14LINHAS | //| OSC_OC com 7+7 DSLs (C'0,204,204' e C'162,64,208') | //+------------------------------------------------------------------+ #property copyright "Copyright © 2010-2024 - OSC_OC Mirror" #property link "github.com" //---- indicator settings #property indicator_separate_window #property indicator_level1 0 #property indicator_levelcolor DarkSlateGray #property indicator_levelstyle 0 #property indicator_buffers 20 // Cores das linhas #property indicator_color1 Aqua // Bull 1 #property indicator_color2 Aqua // Bull 2 #property indicator_color3 Teal // Bull 3 #property indicator_color4 Teal // Bull 4 #property indicator_color5 Teal // Bull 5 #property indicator_color6 Teal // Bull 6 #property indicator_color7 Teal // Bull 7 #property indicator_color8 DeepPink // Bear 1 #property indicator_color9 DeepPink // Bear 2 #property indicator_color10 C'162,64,208' // Bear 3 #property indicator_color11 C'162,64,208' // Bear 4 #property indicator_color12 C'162,64,208' // Bear 5 #property indicator_color13 C'162,64,208' // Bear 6 #property indicator_color14 C'162,64,208' // Bear 7 #property indicator_color15 Aqua // Signal #property indicator_color16 DeepPink // Inverse #property indicator_width1 1 #property indicator_width2 1 #property indicator_width3 1 #property indicator_width4 1 #property indicator_width5 1 #property indicator_width6 1 #property indicator_width7 1 #property indicator_width8 1 #property indicator_width9 1 #property indicator_width10 1 #property indicator_width11 1 #property indicator_width12 1 #property indicator_width13 1 #property indicator_width14 1 #property indicator_width15 2 #property indicator_width16 2 //---- indicator parameters extern int PeriodeOSC = 20; extern int SignalPeriod = 9; extern bool ShowHistograms = true; extern bool ShowRectangle = true; extern bool ShowAngle = true; //---- buffers double BullLine1[], BullLine2[], BullLine3[], BullLine4[], BullLine5[], BullLine6[], BullLine7[]; double BearLine1[], BearLine2[], BearLine3[], BearLine4[], BearLine5[], BearLine6[], BearLine7[]; double SignalBuffer[], InverseBuffer[]; //+------------------------------------------------------------------+ //| Calcular OSC_OC Bull (EMA Close - EMA Open) | //+------------------------------------------------------------------+ double OSC_OC_Bull(int shift) { return iMA(NULL, 0, PeriodeOSC, 0, MODE_EMA, PRICE_CLOSE, shift) - iMA(NULL, 0, PeriodeOSC, 0, MODE_EMA, PRICE_OPEN, shift); } //+------------------------------------------------------------------+ //| Calcular OSC_OC Bear (EMA Open - EMA Close) | //+------------------------------------------------------------------+ double OSC_OC_Bear(int shift) { return iMA(NULL, 0, PeriodeOSC, 0, MODE_EMA, PRICE_OPEN, shift) - iMA(NULL, 0, PeriodeOSC, 0, MODE_EMA, PRICE_CLOSE, shift); } //+------------------------------------------------------------------+ //| Função para criar labels | //+------------------------------------------------------------------+ void CreateLabel(string name, string text, int x, int y, color clr, int fontSize = 10) { if(ObjectFind(name) != -1) ObjectDelete(name); ObjectCreate(name, OBJ_LABEL, 1, 0, 0); ObjectSetText(name, text, fontSize, "Arial", clr); ObjectSet(name, OBJPROP_CORNER, 1); ObjectSet(name, OBJPROP_XDISTANCE, x); ObjectSet(name, OBJPROP_YDISTANCE, y); } //+------------------------------------------------------------------+ //| Calcular ângulo | //+------------------------------------------------------------------+ double GetAngle(double current, double previous) { return MathArctan(current - previous) * 180.0 / M_PI; } //+------------------------------------------------------------------+ int init() { SetIndexBuffer(0, BullLine1); SetIndexBuffer(1, BullLine2); SetIndexBuffer(2, BullLine3); SetIndexBuffer(3, BullLine4); SetIndexBuffer(4, BullLine5); SetIndexBuffer(5, BullLine6); SetIndexBuffer(6, BullLine7); SetIndexBuffer(7, BearLine1); SetIndexBuffer(8, BearLine2); SetIndexBuffer(9, BearLine3); SetIndexBuffer(10, BearLine4); SetIndexBuffer(11, BearLine5); SetIndexBuffer(12, BearLine6); SetIndexBuffer(13, BearLine7); SetIndexBuffer(14, SignalBuffer); SetIndexBuffer(15, InverseBuffer); for(int b = 0; b <= 6; b++) SetIndexStyle(b, DRAW_LINE, STYLE_SOLID, 1); for(int r = 7; r <= 13; r++) SetIndexStyle(r, DRAW_LINE, STYLE_SOLID, 1); SetIndexStyle(14, DRAW_LINE, STYLE_SOLID, 2, DarkTurquoise); SetIndexStyle(15, DRAW_LINE, STYLE_SOLID, 2, Magenta); IndicatorShortName("OSC_OC_14LINHAS (C'0,204,204'|C'162,64,208')"); return(0); } //+------------------------------------------------------------------+ int deinit() { for(int obj = ObjectsTotal()-1; obj >= 0; obj--) ObjectDelete(ObjectName(obj)); return(0); } //+------------------------------------------------------------------+ int start() { int totalBars = MathMin(Bars, 500); // número fixo de barras a processar if(totalBars < 1) return 0; double bullVal, bearVal; double scale = 0.9; double step = 0.12; // Primeiro loop: preenche Bull e Bear lines (do mais antigo para o mais novo) for(int pos = totalBars-1; pos >= 0; pos--) { bullVal = OSC_OC_Bull(pos); bearVal = OSC_OC_Bear(pos); BullLine1[pos] = bullVal; BullLine2[pos] = bullVal * (scale - step * 0); BullLine3[pos] = bullVal * (scale - step * 1); BullLine4[pos] = bullVal * (scale - step * 2); BullLine5[pos] = bullVal * (scale - step * 3); BullLine6[pos] = bullVal * (scale - step * 4); BullLine7[pos] = bullVal * (scale - step * 5); BearLine1[pos] = bearVal; BearLine2[pos] = bearVal * (scale - step * 0); BearLine3[pos] = bearVal * (scale - step * 1); BearLine4[pos] = bearVal * (scale - step * 2); BearLine5[pos] = bearVal * (scale - step * 3); BearLine6[pos] = bearVal * (scale - step * 4); BearLine7[pos] = bearVal * (scale - step * 5); } // Segundo loop: calcula Signal (SMA do BullLine1) usando período fixo for(int sigPos = 0; sigPos < totalBars; sigPos++) { double sum = 0; int count = 0; for(int j = 0; j < SignalPeriod; j++) { int idx = sigPos + j; if(idx < totalBars) // garante que não ultrapassa o total calculado { sum += BullLine1[idx]; count++; } } SignalBuffer[sigPos] = (count > 0) ? sum / count : 0; InverseBuffer[sigPos] = -SignalBuffer[sigPos]; } // Mostrar ângulo if(ShowAngle) { double angle = GetAngle(BullLine1[0], BullLine1[1]); color corAngulo = Gold; if(MathAbs(angle) > 2.5) corAngulo = Red; else if(angle > 0) corAngulo = C'0,204,204'; else if(angle < 0) corAngulo = C'162,64,208'; CreateLabel("Angle", DoubleToStr(angle, 1) + "°", 5, 5, corAngulo, 11); } // DENTRO/FORA if(ShowRectangle) { double maxV = -999999, minV = 999999; for(int rPos = 0; rPos < MathMin(Bars, 100); rPos++) { if(BullLine1[rPos] > maxV) maxV = BullLine1[rPos]; if(BearLine1[rPos] > maxV) maxV = BearLine1[rPos]; if(BullLine1[rPos] < minV) minV = BullLine1[rPos]; if(BearLine1[rPos] < minV) minV = BearLine1[rPos]; } double centro = (maxV + minV) / 2; double faixa = (maxV - minV) * 0.05; double topo = centro + faixa/2; double fundo = centro - faixa/2; string texto = (BullLine1[0] <= topo && BullLine1[0] >= fundo) ? "(DENTRO)" : "(FORA)"; color corTexto = (BullLine1[0] > SignalBuffer[0]) ? C'0,204,204' : C'162,64,208'; if(texto == "(DENTRO)") corTexto = DarkGray; CreateLabel("InsideOutside", texto, 5, 25, corTexto, 10); // Retângulo if(ObjectFind("Rect") != -1) ObjectDelete("Rect"); ObjectCreate("Rect", OBJ_RECTANGLE, 1, Time[Bars-1], topo, Time[0], fundo); ObjectSet("Rect", OBJPROP_COLOR, DarkGray); ObjectSet("Rect", OBJPROP_WIDTH, 1); ObjectSet("Rect", OBJPROP_STYLE, STYLE_DOT); } // Histogramas if(ShowHistograms) { int ethVal = (int)(MathAbs(BearLine1[0] - SignalBuffer[0]) * 100); int usdVal = (int)(MathAbs(BullLine1[0] - SignalBuffer[0]) * 100); if(ethVal > 100) ethVal = 100; if(usdVal > 100) usdVal = 100; // Bloco ETH (mais à esquerda) CreateLabel("ETH_Text", "ETH", 80, 15, White, 9); // Subiu e aumentou leve espaçamento CreateLabel("ETH_Val", DoubleToStr(ethVal, 0) + "%", 80, 40, clrDarkViolet, 18); // Aumentou distância vertical (15 → 25) // Bloco USD (mais à direita) CreateLabel("USD_Text", "USD", 125, 15, White, 9); // Afastado horizontalmente (80 → 125 = 45 pixels) CreateLabel("USD_Val", DoubleToStr(usdVal, 0) + "%", 125, 40, clrAqua, 18); } return(0); } //+------------------------------------------------------------------+