Rozumiem teraz sytuację lepiej. Przywrócę kierunki strzałek do oryginalnej logiki (czyli strzałka w dół dla sygnału sprzedaży i strzałka w górę dla sygnału kupna).
Co do problemu z wyborem kolorów w Wine na macOS – to znany problem. Wine czasami nie renderuje poprawnie niektórych kontrolek GUI, w tym okien dialogowych do wyboru kolorów. Niestety, nie mamy bezpośredniej kontroli nad tym, jak Wine obsługuje natywne okna systemu Windows w macOS.
Rozwiązanie:
Zamiast używać standardowych input color (które uruchamiają natywne okno wyboru koloru), zaimplementujemy własne listy rozwijane (enum) z predefiniowanymi kolorami. To obejście jest często stosowane w MQL5, gdy wiemy, że platforma może mieć problemy z GUI.
Poniżej znajdziesz ostateczną wersję kodu z:
- Przywróconymi kierunkami strzałek (tak jak wcześniej:
buySig = strzałka w dół, sellSig = strzałka w górę).
- Własnymi ustawieniami kolorów za pomocą
enum zamiast input color.
- Gradientem kolorów EMA, który już się spodobał.
Oto kod:
//+------------------------------------------------------------------+
//| InfinityAlgoRemake.mq5 (MT5) |
//| port Pine-scriptu „Infinity Algo – Remake" |
//| Strzałki BUY/SELL (Buffer-based) bez alertów |
//+------------------------------------------------------------------+
#property copyright "Free / Open-Source"
#property version "2.22"
#property indicator_chart_window
#property indicator_buffers 19
#property indicator_plots 16
//–– 1. SuperTrend --------------------------------------------------
#property indicator_label1 "SuperTrend"
#property indicator_type1 DRAW_LINE
#property indicator_color1 clrAqua
#property indicator_style1 STYLE_SOLID
#property indicator_width1 2
//–– 2-14. EMA-y 15-51 (Gradient Kolorów) ---------------------------
#property indicator_label2 "EMA 15"
#property indicator_type2 DRAW_LINE
#property indicator_color2 clrRed
#property indicator_width2 1
#property indicator_label3 "EMA 18"
#property indicator_type3 DRAW_LINE
#property indicator_color3 clrOrangeRed
#property indicator_width3 1
#property indicator_label4 "EMA 21"
#property indicator_type4 DRAW_LINE
#property indicator_color4 clrOrange
#property indicator_width4 1
#property indicator_label5 "EMA 24"
#property indicator_type5 DRAW_LINE
#property indicator_color5 clrGold
#property indicator_width5 1
#property indicator_label6 "EMA 27"
#property indicator_type6 DRAW_LINE
#property indicator_color6 clrYellowGreen
#property indicator_width6 1
#property indicator_label7 "EMA 30"
#property indicator_type7 DRAW_LINE
#property indicator_color7 clrLimeGreen
#property indicator_width7 1
#property indicator_label8 "EMA 33"
#property indicator_type8 DRAW_LINE
#property indicator_color8 clrMediumSeaGreen
#property indicator_width8 1
#property indicator_label9 "EMA 36"
#property indicator_type9 DRAW_LINE
#property indicator_color9 clrSeaGreen
#property indicator_width9 1
#property indicator_label10 "EMA 39"
#property indicator_type10 DRAW_LINE
#property indicator_color10 clrSkyBlue
#property indicator_width10 1
#property indicator_label11 "EMA 42"
#property indicator_type11 DRAW_LINE
#property indicator_color11 clrDeepSkyBlue
#property indicator_width11 1
#property indicator_label12 "EMA 45"
#property indicator_type12 DRAW_LINE
#property indicator_color12 clrRoyalBlue
#property indicator_width12 1
#property indicator_label13 "EMA 48"
#property indicator_type13 DRAW_LINE
#property indicator_color13 clrMediumPurple
#property indicator_width13 1
#property indicator_label14 "EMA 51"
#property indicator_type14 DRAW_LINE
#property indicator_color14 clrDarkViolet
#property indicator_width14 1
//–– 15-16. Strzałki Sygnałowe (DRAW_ARROW) --------------------------
#property indicator_label15 "Sell Signal" // UWAGA: Etykieta "Sell" dla strzałki w dół
#property indicator_type15 DRAW_ARROW
#property indicator_color15 clrOrange // Domyślny kolor (zostanie nadpisany w OnInit)
#property indicator_width15 3 // Domyślna szerokość (zostanie nadpisana)
#property indicator_label16 "Buy Signal" // UWAGA: Etykieta "Buy" dla strzałki w górę
#property indicator_type16 DRAW_ARROW
#property indicator_color16 clrLightBlue // Domyślny kolor (zostanie nadpisany w OnInit)
#property indicator_width16 3 // Domyślna szerokość (zostanie nadpisana)
//===================================================================
// DEFINICJE KOLORÓW (ENUM)
//===================================================================
enum ENUM_ARROW_COLORS {
Red = clrRed,
Orange = clrOrange,
Yellow = clrYellow,
Lime = clrLime,
Aqua = clrAqua,
Blue = clrBlue,
Fuchsia = clrFuchsia,
White = clrWhite,
Silver = clrSilver,
Custom1 = 0xFF8000, // Pomarańczowy (dla Sell)
Custom2 = 0xADD8E6 // Jasnoniebieski (dla Buy)
};
//===================================================================
// PARAMETRY UŻYTKOWNIKA
//===================================================================
input group "Ustawienia Wskaźnika"
input double InpSensitivity = 3.5; // Czułość Supertrendu
input int InpKeltnerLength = 9; // Długość SMA dla Keltnera
input double InpFactor = 2.0; // Mnożnik pasma
input bool InpShowEMAs = true; // Pokaż EMA-y?
input group "Ustawienia Strzałek"
input ENUM_ARROW_COLORS SellArrowColor = Orange; // Kolor strzałki SPRZEDAŻY (↓)
input ENUM_ARROW_COLORS BuyArrowColor = Custom2; // Kolor strzałki KUPNA (↑)
input int InpArrowSize = 3; // Wielkość strzałek (1-5)
input int InpArrowShiftPoints = 50; // Odległość od ceny (pkt)
//===================================================================
// BUFORY
//===================================================================
double SupTrend[];
double EMA15[], EMA18[], EMA21[], EMA24[], EMA27[], EMA30[], EMA33[];
double EMA36[], EMA39[], EMA42[], EMA45[], EMA48[], EMA51[];
double SellArrows[], BuyArrows[]; // Sell = ↓, Buy = ↑
double UpBand[], DnBand[], DirBuf[];
//===================================================================
// UCHWYTY EMA / SMA
//===================================================================
int emaHandle[13];
int smaHandle = INVALID_HANDLE;
int emaPer[13] = {15,18,21,24,27,30,33,36,39,42,45,48,51};
//===================================================================
// INICJALIZACJA
//===================================================================
int OnInit()
{
ChartSetInteger(0, CHART_BRING_TO_TOP, true);
// Bufory Danych (Linie)
SetIndexBuffer(0, SupTrend, INDICATOR_DATA);
SetIndexBuffer(1, EMA15, INDICATOR_DATA);
SetIndexBuffer(2, EMA18, INDICATOR_DATA);
SetIndexBuffer(3, EMA21, INDICATOR_DATA);
SetIndexBuffer(4, EMA24, INDICATOR_DATA);
SetIndexBuffer(5, EMA27, INDICATOR_DATA);
SetIndexBuffer(6, EMA30, INDICATOR_DATA);
SetIndexBuffer(7, EMA33, INDICATOR_DATA);
SetIndexBuffer(8, EMA36, INDICATOR_DATA);
SetIndexBuffer(9, EMA39, INDICATOR_DATA);
SetIndexBuffer(10, EMA42, INDICATOR_DATA);
SetIndexBuffer(11, EMA45, INDICATOR_DATA);
SetIndexBuffer(12, EMA48, INDICATOR_DATA);
SetIndexBuffer(13, EMA51, INDICATOR_DATA);
// Bufory Strzałek
SetIndexBuffer(14, SellArrows, INDICATOR_DATA); // Strzałka w dół (Sell)
SetIndexBuffer(15, BuyArrows, INDICATOR_DATA); // Strzałka w górę (Buy)
// Bufory Obliczeniowe
SetIndexBuffer(16, UpBand, INDICATOR_CALCULATIONS);
SetIndexBuffer(17, DnBand, INDICATOR_CALCULATIONS);
SetIndexBuffer(18, DirBuf, INDICATOR_CALCULATIONS);
// Ustawienia pustych wartości
for(int p=0; p<16; p++)
PlotIndexSetDouble(p, PLOT_EMPTY_VALUE, EMPTY_VALUE);
// Ustawienie kodów strzałek
PlotIndexSetInteger(14, PLOT_ARROW, 234); // Strzałka w dół (Sell)
PlotIndexSetInteger(15, PLOT_ARROW, 233); // Strzałka w górę (Buy)
// Przypisanie kolorów ze zmiennych enum
PlotIndexSetInteger(14, PLOT_LINE_COLOR, (color)SellArrowColor); // Sell (↓)
PlotIndexSetInteger(15, PLOT_LINE_COLOR, (color)BuyArrowColor); // Buy (↑)
// Wielkość strzałek
int sz = InpArrowSize;
if(sz < 1) sz = 1;
if(sz > 5) sz = 5;
PlotIndexSetInteger(14, PLOT_LINE_WIDTH, sz);
PlotIndexSetInteger(15, PLOT_LINE_WIDTH, sz);
// Tworzenie uchwytów EMA
for(int n=0; n<13; n++)
{
emaHandle[n] = iMA(_Symbol, _Period, emaPer[n], 0, MODE_EMA, PRICE_HIGH);
if(emaHandle[n] == INVALID_HANDLE)
{
Print("Błąd tworzenia EMA(", emaPer[n], ")");
return INIT_FAILED;
}
}
// SMA Keltnera
smaHandle = iMA(_Symbol, _Period, InpKeltnerLength, 0, MODE_SMA, PRICE_CLOSE);
if(smaHandle == INVALID_HANDLE)
{
Print("Błąd tworzenia SMA Keltnera");
return INIT_FAILED;
}
Print("Wskaźnik zainicjalizowany.");
return INIT_SUCCEEDED;
}
//===================================================================
// DEINIT
//===================================================================
void OnDeinit(const int reason)
{
for(int n=0; n<13; n++) IndicatorRelease(emaHandle[n]);
IndicatorRelease(smaHandle);
}
//===================================================================
// KOPIOWANIE DANYCH Z WSKAŹNIKÓW
//===================================================================
bool CopyBuf(int h, double &buf[], int sz)
{
return CopyBuffer(h, 0, 0, sz, buf) > 0;
}
//===================================================================
// GŁÓWNA FUNKCJA OBLICZENIOWA
//===================================================================
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 < InpKeltnerLength + 5) return 0;
static double smaBuf[];
ArrayResize(smaBuf, rates_total);
if(!CopyBuf(smaHandle, smaBuf, rates_total)) return 0;
// Kopiowanie EMA
if(InpShowEMAs)
{
CopyBuf(emaHandle[0], EMA15, rates_total);
CopyBuf(emaHandle[1], EMA18, rates_total);
CopyBuf(emaHandle[2], EMA21, rates_total);
CopyBuf(emaHandle[3], EMA24, rates_total);
CopyBuf(emaHandle[4], EMA27, rates_total);
CopyBuf(emaHandle[5], EMA30, rates_total);
CopyBuf(emaHandle[6], EMA33, rates_total);
CopyBuf(emaHandle[7], EMA36, rates_total);
CopyBuf(emaHandle[8], EMA39, rates_total);
CopyBuf(emaHandle[9], EMA42, rates_total);
CopyBuf(emaHandle[10], EMA45, rates_total);
CopyBuf(emaHandle[11], EMA48, rates_total);
CopyBuf(emaHandle[12], EMA51, rates_total);
}
else
{
ArrayInitialize(EMA15, EMPTY_VALUE);
ArrayInitialize(EMA18, EMPTY_VALUE);
ArrayInitialize(EMA21, EMPTY_VALUE);
ArrayInitialize(EMA24, EMPTY_VALUE);
ArrayInitialize(EMA27, EMPTY_VALUE);
ArrayInitialize(EMA30, EMPTY_VALUE);
ArrayInitialize(EMA33, EMPTY_VALUE);
ArrayInitialize(EMA36, EMPTY_VALUE);
ArrayInitialize(EMA39, EMPTY_VALUE);
ArrayInitialize(EMA42, EMPTY_VALUE);
ArrayInitialize(EMA45, EMPTY_VALUE);
ArrayInitialize(EMA48, EMPTY_VALUE);
ArrayInitialize(EMA51, EMPTY_VALUE);
}
// Obliczanie SuperTrend
int first = (prev_calculated > 0) ? prev_calculated - 1 : rates_total - InpKeltnerLength - 2;
if(first < 0) first = 0;
for(int i = first; i >= 0; i--)
{
// Czyszczenie buforów strzałek
SellArrows[i] = EMPTY_VALUE;
BuyArrows[i] = EMPTY_VALUE;
double range = high[i] - low[i];
double sma = smaBuf[i];
double upKelt = sma + range;
double dnKelt = sma - range;
double kRange = upKelt - dnKelt;
UpBand[i] = close[i] + InpSensitivity * kRange;
DnBand[i] = close[i] - InpSensitivity * kRange;
if(i < rates_total - 1)
{
if(DnBand[i] < DnBand[i+1] || close[i+1] > DnBand[i+1]) DnBand[i] = DnBand[i+1];
if(UpBand[i] > UpBand[i+1] || close[i+1] < UpBand[i+1]) UpBand[i] = UpBand[i+1];
if(DirBuf[i+1] == 1 && close[i] < DnBand[i])
DirBuf[i] = -1;
else if(DirBuf[i+1] == -1 && close[i] > UpBand[i])
DirBuf[i] = 1;
else
DirBuf[i] = DirBuf[i+1];
}
else DirBuf[i] = 1;
SupTrend[i] = (DirBuf[i] == 1) ? DnBand[i] : UpBand[i];
// Sygnały (oryginalna logika: buySig = strzałka w dół, sellSig = strzałka w górę)
if(i < rates_total - 1)
{
bool buySig = (DirBuf[i] == 1 && DirBuf[i+1] == -1); // Trend zmienił się na ↑ (sprzedaż)
bool sellSig = (DirBuf[i] == -1 && DirBuf[i+1] == 1); // Trend zmienił się na ↓ (kupno)
if(buySig)
{
// Strzałka SPRZEDAŻY (w dół, nad świecą)
SellArrows[i] = high[i] + InpArrowShiftPoints * _Point;
}
if(sellSig)
{
// Strzałka KUPNA (w górę, pod świecą)
BuyArrows[i] = low[i] - InpArrowShiftPoints * _Point;
}
}
}
return rates_total;
}
//+------------------------------------------------------------------+
Co dokładnie zmieniłem:
-
Kierunek Strzałek:
buySig (trend zmienił się na w górę) = strzałka w dół (SellArrows, kod 234).
sellSig (trend zmienił się na w dół) = strzałka w górę (BuyArrows, kod 233).
- Tak jak było wcześniej – sygnalizujemy kierunek przyszłego ruchu ceny.
-
Kolory Strzałek (za pomocą enum):
- Zamiast
input color, użyłem enum ENUM_ARROW_COLORS, gdzie zdefiniowałem popularne kolory.
- W
OnInit, kolory są rzutowane na color i ustawiane dynamicznie:
PlotIndexSetInteger(14, PLOT_LINE_COLOR, (color)SellArrowColor);
PlotIndexSetInteger(15, PLOT_LINE_COLOR, (color)BuyArrowColor);
- Teraz w oknie ustawień wskaźnika będziesz miał rozwijaną listę z kolorami:
Red, Orange, Yellow, Lime, Aqua, Blue, Fuchsia, White, Silver
- Dodatkowo dwa kolory własne:
Custom1 (pomarańczowy) i Custom2 (jasnoniebieski).
-
Gradient EMA bez zmian – zostawiłem tak jak był, bo się spodobał.
Dlaczego enum zamiast input color?
- Wine (na macOS/Linux) ma problemy z okienkiem wyboru koloru (
Color Dialog).
enum działa zawsze i jest natywnie wspierany przez MetaTrader.
- Użytkownik wybiera kolor z listy tekstowej – wygodnie i stabilnie.
Jak to wygląda w praktyce?
Gdy otworzysz ustawienia wskaźnika w MetaTrader 5:
- Zamiast pola koloru zobaczysz listę rozwijaną (dropdown).
- Dostępne opcje:
Red
Orange
Yellow
Lime
Aqua
Blue
Fuchsia
White
Silver
Custom1 (pomarańczowy, 0xFF8000)
Custom2 (jasnoniebieski, 0xADD8E6)
Wybierz sobie Orange dla strzałek sprzedaży (SellArrowColor) i Aqua dla kupna (BuyArrowColor) – efekt będzie natychmiastowy.
Testuj i ciesz się!
Jeśli nadal będą jakieś problemy z Wine, rozważ użycie MetaTrader 5 natywne na Windows (np. przez BootCamp lub maszynę wirtualną). Tam wszystko powinno działać bez zarzutu.
Miłego tradingu! 🚀