OPEN-SOURCE SCRIPT
ICT Swing

//+------------------------------------------------------------------+
//| FractalLines.mq5 |
//| Ultimos 3 Fractales |
//+------------------------------------------------------------------+
#property copyright "Solicitud Personalizada"
#property version "1.00"
#property indicator_chart_window
#property indicator_buffers 0
#property indicator_plots 0
//--- Parametros
input int LineExtension = 20; // Extension de la linea (velas a la derecha)
input int MaxFractales = 3; // Maximo numero de fractales a mostrar (3)
input color ColorClose = clrWhite; // Color linea del CLOSE
input color ColorAlcista = clrDodgerBlue;// Color linea del MINIMO (alcista)
input color ColorBajista = clrRed; // Color linea del MAXIMO (bajista)
//+------------------------------------------------------------------+
//| Detectar fractal ALCISTA |
//+------------------------------------------------------------------+
bool EsFractalAlcista(int pos, const double &low[])
{
if(pos < 2 || pos >= ArraySize(low) - 2) return false;
return (low[pos] < low[pos-1] && low[pos] < low[pos-2] &&
low[pos] < low[pos+1] && low[pos] < low[pos+2]);
}
//+------------------------------------------------------------------+
//| Detectar fractal BAJISTA |
//+------------------------------------------------------------------+
bool EsFractalBajista(int pos, const double &high[])
{
if(pos < 2 || pos >= ArraySize(high) - 2) return false;
return (high[pos] > high[pos-1] && high[pos] > high[pos-2] &&
high[pos] > high[pos+1] && high[pos] > high[pos+2]);
}
//+------------------------------------------------------------------+
//| Obtener segundos por timeframe |
//+------------------------------------------------------------------+
int GetSegundosPorVela()
{
switch(Period())
{
case PERIOD_M1: return 60;
case PERIOD_M5: return 300;
case PERIOD_M15: return 900;
case PERIOD_M30: return 1800;
case PERIOD_H1: return 3600;
case PERIOD_H4: return 14400;
case PERIOD_D1: return 86400;
case PERIOD_W1: return 604800;
case PERIOD_MN1: return 2592000;
default: return 86400;
}
}
//+------------------------------------------------------------------+
//| Dibujar linea |
//+------------------------------------------------------------------+
void DibujarLinea(string nombre, double nivel, datetime tiempo, color col)
{
ObjectDelete(0, nombre);
int seg = GetSegundosPorVela();
datetime futuro = tiempo + (LineExtension * seg);
if(ObjectCreate(0, nombre, OBJ_TREND, 0, tiempo, nivel, futuro, nivel))
{
ObjectSetInteger(0, nombre, OBJPROP_COLOR, col);
ObjectSetInteger(0, nombre, OBJPROP_STYLE, STYLE_SOLID);
ObjectSetInteger(0, nombre, OBJPROP_WIDTH, 1);
ObjectSetInteger(0, nombre, OBJPROP_BACK, false);
ObjectSetInteger(0, nombre, OBJPROP_RAY_RIGHT, false);
ChartRedraw();
}
}
//+------------------------------------------------------------------+
//| Limpiar todas las lineas de fractales |
//+------------------------------------------------------------------+
void LimpiarLineas()
{
for(int i = ObjectsTotal(0)-1; i >= 0; i--)
{
string nombre = ObjectName(0, i);
if(StringFind(nombre, "Fractal_Alcista_") == 0 ||
StringFind(nombre, "Fractal_Bajista_") == 0)
{
ObjectDelete(0, nombre);
}
}
}
//+------------------------------------------------------------------+
//| Main |
//+------------------------------------------------------------------+
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 < 10) return(0);
// Limpiar lineas anteriores
LimpiarLineas();
// --- COLECCIONAR FRACTALES ALCISTAS (los mas cercanos al precio) ---
int alcistas[];
int alcistasCount = 0;
ArrayResize(alcistas, rates_total);
for(int i = rates_total - 1; i >= 2; i--)
{
if(EsFractalAlcista(i, low))
{
alcistas[alcistasCount] = i;
alcistasCount++;
if(alcistasCount >= MaxFractales) break;
}
}
// --- DIBUJAR LINEAS ALCISTAS (CLOSE y MINIMO) ---
for(int j = 0; j < alcistasCount; j++)
{
int idx = alcistas[j];
double nivelClose = close[idx];
double nivelMinimo = low[idx];
datetime tiempo = time[idx];
// Linea en el CLOSE
DibujarLinea("Fractal_Alcista_Close_" + IntegerToString(idx), nivelClose, tiempo, ColorClose);
// Linea en el MINIMO
DibujarLinea("Fractal_Alcista_Min_" + IntegerToString(idx), nivelMinimo, tiempo, ColorAlcista);
Print("ALCISTA #", j+1, " | Vela: ", idx, " | Close: ", nivelClose, " | Min: ", nivelMinimo);
}
// --- COLECCIONAR FRACTALES BAJISTAS (los mas cercanos al precio) ---
int bajistas[];
int bajistasCount = 0;
ArrayResize(bajistas, rates_total);
for(int i = rates_total - 1; i >= 2; i--)
{
if(EsFractalBajista(i, high))
{
bajistas[bajistasCount] = i;
bajistasCount++;
if(bajistasCount >= MaxFractales) break;
}
}
// --- DIBUJAR LINEAS BAJISTAS (CLOSE y MAXIMO) ---
for(int j = 0; j < bajistasCount; j++)
{
int idx = bajistas[j];
double nivelClose = close[idx];
double nivelMaximo = high[idx];
datetime tiempo = time[idx];
// Linea en el CLOSE
DibujarLinea("Fractal_Bajista_Close_" + IntegerToString(idx), nivelClose, tiempo, ColorClose);
// Linea en el MAXIMO
DibujarLinea("Fractal_Bajista_Max_" + IntegerToString(idx), nivelMaximo, tiempo, ColorBajista);
Print("BAJISTA #", j+1, " | Vela: ", idx, " | Close: ", nivelClose, " | Max: ", nivelMaximo);
}
return(rates_total);
}
//+------------------------------------------------------------------+
//| FractalLines.mq5 |
//| Ultimos 3 Fractales |
//+------------------------------------------------------------------+
#property copyright "Solicitud Personalizada"
#property version "1.00"
#property indicator_chart_window
#property indicator_buffers 0
#property indicator_plots 0
//--- Parametros
input int LineExtension = 20; // Extension de la linea (velas a la derecha)
input int MaxFractales = 3; // Maximo numero de fractales a mostrar (3)
input color ColorClose = clrWhite; // Color linea del CLOSE
input color ColorAlcista = clrDodgerBlue;// Color linea del MINIMO (alcista)
input color ColorBajista = clrRed; // Color linea del MAXIMO (bajista)
//+------------------------------------------------------------------+
//| Detectar fractal ALCISTA |
//+------------------------------------------------------------------+
bool EsFractalAlcista(int pos, const double &low[])
{
if(pos < 2 || pos >= ArraySize(low) - 2) return false;
return (low[pos] < low[pos-1] && low[pos] < low[pos-2] &&
low[pos] < low[pos+1] && low[pos] < low[pos+2]);
}
//+------------------------------------------------------------------+
//| Detectar fractal BAJISTA |
//+------------------------------------------------------------------+
bool EsFractalBajista(int pos, const double &high[])
{
if(pos < 2 || pos >= ArraySize(high) - 2) return false;
return (high[pos] > high[pos-1] && high[pos] > high[pos-2] &&
high[pos] > high[pos+1] && high[pos] > high[pos+2]);
}
//+------------------------------------------------------------------+
//| Obtener segundos por timeframe |
//+------------------------------------------------------------------+
int GetSegundosPorVela()
{
switch(Period())
{
case PERIOD_M1: return 60;
case PERIOD_M5: return 300;
case PERIOD_M15: return 900;
case PERIOD_M30: return 1800;
case PERIOD_H1: return 3600;
case PERIOD_H4: return 14400;
case PERIOD_D1: return 86400;
case PERIOD_W1: return 604800;
case PERIOD_MN1: return 2592000;
default: return 86400;
}
}
//+------------------------------------------------------------------+
//| Dibujar linea |
//+------------------------------------------------------------------+
void DibujarLinea(string nombre, double nivel, datetime tiempo, color col)
{
ObjectDelete(0, nombre);
int seg = GetSegundosPorVela();
datetime futuro = tiempo + (LineExtension * seg);
if(ObjectCreate(0, nombre, OBJ_TREND, 0, tiempo, nivel, futuro, nivel))
{
ObjectSetInteger(0, nombre, OBJPROP_COLOR, col);
ObjectSetInteger(0, nombre, OBJPROP_STYLE, STYLE_SOLID);
ObjectSetInteger(0, nombre, OBJPROP_WIDTH, 1);
ObjectSetInteger(0, nombre, OBJPROP_BACK, false);
ObjectSetInteger(0, nombre, OBJPROP_RAY_RIGHT, false);
ChartRedraw();
}
}
//+------------------------------------------------------------------+
//| Limpiar todas las lineas de fractales |
//+------------------------------------------------------------------+
void LimpiarLineas()
{
for(int i = ObjectsTotal(0)-1; i >= 0; i--)
{
string nombre = ObjectName(0, i);
if(StringFind(nombre, "Fractal_Alcista_") == 0 ||
StringFind(nombre, "Fractal_Bajista_") == 0)
{
ObjectDelete(0, nombre);
}
}
}
//+------------------------------------------------------------------+
//| Main |
//+------------------------------------------------------------------+
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 < 10) return(0);
// Limpiar lineas anteriores
LimpiarLineas();
// --- COLECCIONAR FRACTALES ALCISTAS (los mas cercanos al precio) ---
int alcistas[];
int alcistasCount = 0;
ArrayResize(alcistas, rates_total);
for(int i = rates_total - 1; i >= 2; i--)
{
if(EsFractalAlcista(i, low))
{
alcistas[alcistasCount] = i;
alcistasCount++;
if(alcistasCount >= MaxFractales) break;
}
}
// --- DIBUJAR LINEAS ALCISTAS (CLOSE y MINIMO) ---
for(int j = 0; j < alcistasCount; j++)
{
int idx = alcistas[j];
double nivelClose = close[idx];
double nivelMinimo = low[idx];
datetime tiempo = time[idx];
// Linea en el CLOSE
DibujarLinea("Fractal_Alcista_Close_" + IntegerToString(idx), nivelClose, tiempo, ColorClose);
// Linea en el MINIMO
DibujarLinea("Fractal_Alcista_Min_" + IntegerToString(idx), nivelMinimo, tiempo, ColorAlcista);
Print("ALCISTA #", j+1, " | Vela: ", idx, " | Close: ", nivelClose, " | Min: ", nivelMinimo);
}
// --- COLECCIONAR FRACTALES BAJISTAS (los mas cercanos al precio) ---
int bajistas[];
int bajistasCount = 0;
ArrayResize(bajistas, rates_total);
for(int i = rates_total - 1; i >= 2; i--)
{
if(EsFractalBajista(i, high))
{
bajistas[bajistasCount] = i;
bajistasCount++;
if(bajistasCount >= MaxFractales) break;
}
}
// --- DIBUJAR LINEAS BAJISTAS (CLOSE y MAXIMO) ---
for(int j = 0; j < bajistasCount; j++)
{
int idx = bajistas[j];
double nivelClose = close[idx];
double nivelMaximo = high[idx];
datetime tiempo = time[idx];
// Linea en el CLOSE
DibujarLinea("Fractal_Bajista_Close_" + IntegerToString(idx), nivelClose, tiempo, ColorClose);
// Linea en el MAXIMO
DibujarLinea("Fractal_Bajista_Max_" + IntegerToString(idx), nivelMaximo, tiempo, ColorBajista);
Print("BAJISTA #", j+1, " | Vela: ", idx, " | Close: ", nivelClose, " | Max: ", nivelMaximo);
}
return(rates_total);
}
//+------------------------------------------------------------------+
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.