This commit is contained in:
2025-05-05 12:16:36 +03:30
parent eeda9917dc
commit 83242e6d1e
7 changed files with 6317 additions and 168 deletions
+286
View File
@@ -0,0 +1,286 @@
//+------------------------------------------------------------------+
//| ForexSessionDetector.mq5 |
//| Copyright 2023, MetaQuotes Software Corp. |
//| https://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright 2023, MetaQuotes Software Corp."
#property link "https://www.metaquotes.net/"
#property version "1.00"
#property indicator_chart_window
#property indicator_buffers 0
#property indicator_plots 0
//+------------------------------------------------------------------+
//| Session Times |
//+------------------------------------------------------------------+
input color SydneyColor = clrRoyalBlue; // Sydney session color
input color TokyoColor = clrGreen; // Tokyo session color
input color LondonColor = clrRed; // London session color
input color NewYorkColor = clrDodgerBlue; // New York session color
input int TextSize = 8; // Font size
input bool ShowHighLow = true; // Show High/Low prices
input bool ShowSessionTimes = true; // Show Session Times
//+------------------------------------------------------------------+
//| Global Variables |
//+------------------------------------------------------------------+
struct SessionInfo
{
string name;
int startHour;
int startMinute;
int endHour;
int endMinute;
color clr;
datetime sessionStart;
datetime sessionEnd;
double high;
double low;
bool active;
};
SessionInfo sessions[4];
string fontFace = "Arial";
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
// Initialize session information
sessions[0].name = "Sydney";
sessions[0].startHour = 22;
sessions[0].startMinute = 0;
sessions[0].endHour = 6;
sessions[0].endMinute = 0;
sessions[0].clr = SydneyColor;
sessions[1].name = "Tokyo";
sessions[1].startHour = 0;
sessions[1].startMinute = 0;
sessions[1].endHour = 9;
sessions[1].endMinute = 0;
sessions[1].clr = TokyoColor;
sessions[2].name = "London";
sessions[2].startHour = 8;
sessions[2].startMinute = 0;
sessions[2].endHour = 17;
sessions[2].endMinute = 0;
sessions[2].clr = LondonColor;
sessions[3].name = "New York";
sessions[3].startHour = 13;
sessions[3].startMinute = 0;
sessions[3].endHour = 22;
sessions[3].endMinute = 0;
sessions[3].clr = NewYorkColor;
return (INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
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[])
{
// Clear previous objects
ObjectsDeleteAll(0, "Session_");
// Process each session
for (int i = 0; i < 4; i++)
{
ProcessSession(i, time, high, low, rates_total);
}
return (rates_total);
}
//+------------------------------------------------------------------+
//| Process a single session |
//+------------------------------------------------------------------+
void ProcessSession(int sessionIndex, const datetime &time[], const double &high[], const double &low[], int rates_total)
{
SessionInfo session = sessions[sessionIndex];
// Find current session start and end times
datetime currentTime = TimeCurrent();
MqlDateTime currentTimeStruct;
TimeToStruct(currentTime, currentTimeStruct);
datetime sessionStart, sessionEnd;
// Handle sessions that span midnight
if (session.startHour > session.endHour)
{
// Session spans midnight (e.g., Sydney 22:00-6:00)
if (currentTimeStruct.hour >= session.startHour || currentTimeStruct.hour < session.endHour)
{
sessionStart = StructToTime(currentTimeStruct.year, currentTimeStruct.mon, currentTimeStruct.day, session.startHour, session.startMinute, 0);
if (currentTimeStruct.hour < session.startHour)
sessionStart -= 86400; // Previous day
sessionEnd = sessionStart + (session.endHour - session.startHour) * 3600 + (session.endMinute - session.startMinute) * 60;
if (sessionEnd <= sessionStart)
sessionEnd += 86400;
session.active = true;
}
else
{
sessionStart = StructToTime(currentTimeStruct.year, currentTimeStruct.mon, currentTimeStruct.day, session.startHour, session.startMinute, 0);
sessionEnd = sessionStart + (session.endHour - session.startHour) * 3600 + (session.endMinute - session.startMinute) * 60;
if (sessionEnd <= sessionStart)
sessionEnd += 86400;
session.active = false;
}
}
else
{
// Normal session (doesn't span midnight)
if (currentTimeStruct.hour >= session.startHour && currentTimeStruct.hour < session.endHour)
{
sessionStart = StructToTime(currentTimeStruct.year, currentTimeStruct.mon, currentTimeStruct.day, session.startHour, session.startMinute, 0);
sessionEnd = StructToTime(currentTimeStruct.year, currentTimeStruct.mon, currentTimeStruct.day, session.endHour, session.endMinute, 0);
session.active = true;
}
else
{
sessionStart = StructToTime(currentTimeStruct.year, currentTimeStruct.mon, currentTimeStruct.day, session.startHour, session.startMinute, 0);
sessionEnd = StructToTime(currentTimeStruct.year, currentTimeStruct.mon, currentTimeStruct.day, session.endHour, session.endMinute, 0);
session.active = false;
}
}
session.sessionStart = sessionStart;
session.sessionEnd = sessionEnd;
// Find high/low for the session
int startIndex = iBarShift(NULL, 0, sessionStart);
int endIndex = iBarShift(NULL, 0, sessionEnd);
if (startIndex == -1 || endIndex == -1)
return;
session.high = high[ArrayMaximum(high, endIndex, startIndex - endIndex + 1)];
session.low = low[ArrayMinimum(low, endIndex, startIndex - endIndex + 1)];
// Draw session information on chart
DrawSessionInfo(session, startIndex, endIndex, sessionIndex);
}
//+------------------------------------------------------------------+
//| Get chart window price max |
//+------------------------------------------------------------------+
double GetWindowPriceMax()
{
double maxPrice;
ChartGetDouble(0, CHART_PRICE_MAX, 0, maxPrice);
return maxPrice;
}
//+------------------------------------------------------------------+
//| Get chart window price min |
//+------------------------------------------------------------------+
double GetWindowPriceMin()
{
double minPrice;
ChartGetDouble(0, CHART_PRICE_MIN, 0, minPrice);
return minPrice;
}
//+------------------------------------------------------------------+
//| Draw session information on chart |
//+------------------------------------------------------------------+
void DrawSessionInfo(SessionInfo &session, int startIndex, int endIndex, int sessionIndex)
{
string objName;
color textColor = session.clr;
double priceMax = GetWindowPriceMax();
double priceMin = GetWindowPriceMin();
// Draw vertical lines for session start/end
objName = "Session_" + session.name + "_Start";
ObjectCreate(0, objName, OBJ_VLINE, 0, session.sessionStart, 0);
ObjectSetInteger(0, objName, OBJPROP_COLOR, session.clr);
ObjectSetInteger(0, objName, OBJPROP_STYLE, STYLE_DOT);
ObjectSetInteger(0, objName, OBJPROP_WIDTH, 1);
ObjectSetInteger(0, objName, OBJPROP_BACK, true);
objName = "Session_" + session.name + "_End";
ObjectCreate(0, objName, OBJ_VLINE, 0, session.sessionEnd, 0);
ObjectSetInteger(0, objName, OBJPROP_COLOR, session.clr);
ObjectSetInteger(0, objName, OBJPROP_STYLE, STYLE_DOT);
ObjectSetInteger(0, objName, OBJPROP_WIDTH, 1);
ObjectSetInteger(0, objName, OBJPROP_BACK, true);
// Draw session name label
if (ShowSessionTimes)
{
objName = "Session_" + session.name + "_Label";
ObjectCreate(0, objName, OBJ_TEXT, 0, session.sessionStart, priceMax - (priceMax - priceMin) * 0.1 * (sessionIndex + 1));
ObjectSetString(0, objName, OBJPROP_TEXT, session.name + " " + TimeToString(session.sessionStart, TIME_MINUTES) + " - " + TimeToString(session.sessionEnd, TIME_MINUTES));
ObjectSetInteger(0, objName, OBJPROP_COLOR, textColor);
ObjectSetInteger(0, objName, OBJPROP_FONTSIZE, TextSize);
ObjectSetString(0, objName, OBJPROP_FONT, fontFace);
ObjectSetInteger(0, objName, OBJPROP_ANCHOR, ANCHOR_LEFT_UPPER);
ObjectSetInteger(0, objName, OBJPROP_BACK, false);
}
// Draw high/low prices if enabled
if (ShowHighLow)
{
objName = "Session_" + session.name + "_High";
ObjectCreate(0, objName, OBJ_TEXT, 0, session.sessionStart + (session.sessionEnd - session.sessionStart) / 2, session.high);
ObjectSetString(0, objName, OBJPROP_TEXT, "H: " + DoubleToString(session.high, _Digits));
ObjectSetInteger(0, objName, OBJPROP_COLOR, textColor);
ObjectSetInteger(0, objName, OBJPROP_FONTSIZE, TextSize);
ObjectSetString(0, objName, OBJPROP_FONT, fontFace);
ObjectSetInteger(0, objName, OBJPROP_ANCHOR, ANCHOR_LOWER);
ObjectSetInteger(0, objName, OBJPROP_BACK, false);
objName = "Session_" + session.name + "_Low";
ObjectCreate(0, objName, OBJ_TEXT, 0, session.sessionStart + (session.sessionEnd - session.sessionStart) / 2, session.low);
ObjectSetString(0, objName, OBJPROP_TEXT, "L: " + DoubleToString(session.low, _Digits));
ObjectSetInteger(0, objName, OBJPROP_COLOR, textColor);
ObjectSetInteger(0, objName, OBJPROP_FONTSIZE, TextSize);
ObjectSetString(0, objName, OBJPROP_FONT, fontFace);
ObjectSetInteger(0, objName, OBJPROP_ANCHOR, ANCHOR_UPPER);
ObjectSetInteger(0, objName, OBJPROP_BACK, false);
}
// Highlight active session
if (session.active)
{
objName = "Session_" + session.name + "_Background";
ObjectCreate(0, objName, OBJ_RECTANGLE, 0, session.sessionStart, priceMax, session.sessionEnd, priceMin);
ObjectSetInteger(0, objName, OBJPROP_COLOR, session.clr);
ObjectSetInteger(0, objName, OBJPROP_BGCOLOR, session.clr);
ObjectSetInteger(0, objName, OBJPROP_BACK, true);
ObjectSetInteger(0, objName, OBJPROP_FILL, true);
ObjectSetInteger(0, objName, OBJPROP_WIDTH, 1);
}
}
//+------------------------------------------------------------------+
//| Create datetime from components |
//+------------------------------------------------------------------+
datetime StructToTime(int year, int month, int day, int hour, int minute, int second)
{
MqlDateTime mdt;
mdt.year = year;
mdt.mon = month;
mdt.day = day;
mdt.hour = hour;
mdt.min = minute;
mdt.sec = second;
return StructToTime(mdt);
}
//+------------------------------------------------------------------+
+282 -133
View File
@@ -63,8 +63,10 @@ input ENUM_SERIESMODE llMode = MODE_LOW; // Lowest Low Calculation Method
//
input group "Fibo Levels";
input ENUM_X_FIBO_LEVELS fiboLevel1 = X_FIBO_LEVEL_236; // Fibo Level 1
input ENUM_X_FIBO_LEVELS fiboLevel2 = X_FIBO_LEVEL_500; // Fibo Level 2
input ENUM_X_FIBO_LEVELS fiboLevel3 = X_FIBO_LEVEL_764; // Fibo Level 3
input ENUM_X_FIBO_LEVELS fiboLevel2 = X_FIBO_LEVEL_382; // Fibo Level 2
input ENUM_X_FIBO_LEVELS fiboLevel3 = X_FIBO_LEVEL_500; // Fibo Level 3
input ENUM_X_FIBO_LEVELS fiboLevel4 = X_FIBO_LEVEL_618; // Fibo Level 4
input ENUM_X_FIBO_LEVELS fiboLevel5 = X_FIBO_LEVEL_764; // Fibo Level 5
//
input group "Sar Detection";
@@ -96,8 +98,8 @@ input int swingLength = 5; // Length
//
input group "Support and Resistance";
input int supResSmoothingLength = 7; // Smoothing Length
input ENUM_X_MA_METHOD supResSmoothingMode = X_MA_MODE_SMA; // Smoothing Method
input int supResSmoothingLength = 7; // Smoothing Length
input ENUM_X_MA_METHOD supResSmoothingMode = X_MA_MODE_NONE; // Smoothing Method
//
// Presentation ...
@@ -119,13 +121,17 @@ input bool showSwings = true; // Show Swings
input bool showFiboLevel1 = true; // Show Fibo Level 1
input bool showFiboLevel2 = true; // Show Fibo Level 2
input bool showFiboLevel3 = true; // Show Fibo Level 3
input bool showFiboLevel4 = true; // Show Fibo Level 4
input bool showFiboLevel5 = true; // Show Fibo Level 5
input bool showPeaksAndVales = true; // Show Peaks And Vales
input bool showPeakAndValeGolden = true; // Show Peak and Vale Golden
input bool showSupportAndResistance = true; // Show Support and Resistance
input bool showShortCycle = true; // Show Short Cycle
input bool showMediumCycle = true; // Show Medium Cycle
input bool showLongCycle = true; // Show Long Cycle
input bool showHindCycle = true; // Show Hind Cycle
//
bool showShortCycle = false; // Show Short Cycle
bool showMediumCycle = false; // Show Medium Cycle
bool showLongCycle = false; // Show Long Cycle
bool showHindCycle = false; // Show Hind Cycle
//
int sarArrowCode = 159; // Parabolic Sar Arrow Code
@@ -155,8 +161,8 @@ int swingHighArrowCode = 226; // Swing High Arrow Code
#property indicator_chart_window
//
#property indicator_buffers 37
#property indicator_plots 27
#property indicator_buffers 39
#property indicator_plots 29
//
// Plot Buffers ...
@@ -367,8 +373,8 @@ double fiboLevel2Buffer[];
//
#property indicator_label16 "Fibo L2"
#property indicator_type16 DRAW_LINE
#property indicator_color16 clrYellow
#property indicator_style16 STYLE_DASH
#property indicator_color16 clrGold
#property indicator_style16 STYLE_DOT
#property indicator_width16 1
//
@@ -381,176 +387,204 @@ double fiboLevel3Buffer[];
//
#property indicator_label17 "Fibo L3"
#property indicator_type17 DRAW_LINE
#property indicator_color17 clrGold
#property indicator_style17 STYLE_DOT
#property indicator_color17 clrYellow
#property indicator_style17 STYLE_DASH
#property indicator_width17 1
//
// FIBO Level 4
//
#define fiboLevel4BufferIndex 17
double fiboLevel4Buffer[];
//
#property indicator_label18 "Fibo L4"
#property indicator_type18 DRAW_LINE
#property indicator_color18 clrGold
#property indicator_style18 STYLE_DOT
#property indicator_width18 1
//
// FIBO Level 5
//
#define fiboLevel5BufferIndex 18
double fiboLevel5Buffer[];
//
#property indicator_label19 "Fibo L5"
#property indicator_type19 DRAW_LINE
#property indicator_color19 clrGold
#property indicator_style19 STYLE_DOT
#property indicator_width19 1
//
// SAR ...
//
#define sarBufferIndex 17
#define sarBufferIndex 19
double sarBuffer[];
//
#property indicator_label18 "SAR"
#property indicator_type18 DRAW_ARROW
#property indicator_color18 clrYellow
#property indicator_width18 1
#property indicator_label20 "SAR"
#property indicator_type20 DRAW_ARROW
#property indicator_color20 clrYellow
#property indicator_width20 1
//
// TREND ...
//
#define trendBufferIndex 18
#define trendBufferPlotIndex 18
#define trendBufferIndex 20
#define trendBufferPlotIndex 20
double trendBuffer[];
//
#define trendColorBufferIndex 19
#define trendColorBufferIndex 21
double trendColorBuffer[];
//
#property indicator_label19 "TRND"
#property indicator_type19 DRAW_COLOR_LINE
#property indicator_color19 CLR_NONE, clrAqua, clrMagenta, clrGray
#property indicator_style19 STYLE_DASH
#property indicator_width19 2
#property indicator_label21 "TRND"
#property indicator_type21 DRAW_COLOR_LINE
#property indicator_color21 CLR_NONE, clrAqua, clrMagenta, clrGray
#property indicator_style21 STYLE_DASH
#property indicator_width21 2
//
// KI ...
//
#define kiBufferIndex 20
#define kiBufferPlotIndex 19
#define kiBufferIndex 22
#define kiBufferPlotIndex 21
double kiBuffer[];
//
#define kiColorBufferIndex 21
#define kiColorBufferIndex 23
double kiColorBuffer[];
//
#property indicator_label20 "KI"
#property indicator_type20 DRAW_COLOR_LINE
#property indicator_color20 CLR_NONE, clrGreen, clrRed, clrGray
#property indicator_style20 STYLE_DASHDOTDOT
#property indicator_width20 2
#property indicator_label22 "KI"
#property indicator_type22 DRAW_COLOR_LINE
#property indicator_color22 CLR_NONE, clrGreen, clrRed, clrGray
#property indicator_style22 STYLE_DASHDOTDOT
#property indicator_width22 2
//
// SWING Low ...
//
#define swingLowBufferIndex 22
#define swingLowBufferPlotIndex 20
#define swingLowBufferIndex 24
#define swingLowBufferPlotIndex 22
double swingLowBuffer[];
//
#property indicator_label21 "SWL"
#property indicator_type21 DRAW_ARROW
#property indicator_color21 clrGreen
#property indicator_width21 1
#property indicator_label23 "SWL"
#property indicator_type23 DRAW_ARROW
#property indicator_color23 clrGreen
#property indicator_width23 1
//
// SWING High ...
//
#define swingHighBufferIndex 23
#define swingHighBufferPlotIndex 21
#define swingHighBufferIndex 25
#define swingHighBufferPlotIndex 23
double swingHighBuffer[];
//
#property indicator_label22 "SWH"
#property indicator_type22 DRAW_ARROW
#property indicator_color22 clrRed
#property indicator_width22 1
#property indicator_label24 "SWH"
#property indicator_type24 DRAW_ARROW
#property indicator_color24 clrRed
#property indicator_width24 1
//
// TKI ...
//
#define tkiBufferIndex 24
#define tkiBufferPlotIndex 22
#define tkiBufferIndex 26
#define tkiBufferPlotIndex 24
double tkiBuffer[];
//
#define tkiColorBufferIndex 25
#define tkiColorBufferIndex 27
double tkiColorBuffer[];
//
#property indicator_label23 "TKI"
#property indicator_type23 DRAW_COLOR_LINE
#property indicator_color23 CLR_NONE, clrGreen, clrRed, clrGray
#property indicator_style23 STYLE_DASHDOTDOT
#property indicator_width23 2
#property indicator_label25 "TKI"
#property indicator_type25 DRAW_COLOR_LINE
#property indicator_color25 CLR_NONE, clrGreen, clrRed, clrGray
#property indicator_style25 STYLE_DASHDOTDOT
#property indicator_width25 2
//
// VIDYA ...
//
#define vidyaBufferIndex 26
#define vidyaBufferPlotIndex 23
#define vidyaBufferIndex 28
#define vidyaBufferPlotIndex 25
double vidyaBuffer[];
//
#define vidyaColorBufferIndex 27
#define vidyaColorBufferIndex 29
double vidyaColorBuffer[];
//
#property indicator_label24 "VIDYA"
#property indicator_type24 DRAW_COLOR_LINE
#property indicator_color24 CLR_NONE, clrAqua, clrMagenta, clrGray
#property indicator_style24 STYLE_SOLID
#property indicator_width24 1
#property indicator_label26 "VIDYA"
#property indicator_type26 DRAW_COLOR_LINE
#property indicator_color26 CLR_NONE, clrAqua, clrMagenta, clrGray
#property indicator_style26 STYLE_SOLID
#property indicator_width26 1
//
// MAH ...
//
#define mahBufferIndex 28
#define mahBufferPlotIndex 24
#define mahBufferIndex 30
#define mahBufferPlotIndex 26
double mahBuffer[];
//
#property indicator_label25 "MAH"
#property indicator_type25 DRAW_LINE
#property indicator_color25 clrMagenta
#property indicator_style25 STYLE_SOLID
#property indicator_width25 1
#property indicator_label27 "MAH"
#property indicator_type27 DRAW_LINE
#property indicator_color27 clrMagenta
#property indicator_style27 STYLE_SOLID
#property indicator_width27 1
//
// MAL ...
//
#define malBufferIndex 29
#define malBufferPlotIndex 25
#define malBufferIndex 31
#define malBufferPlotIndex 27
double malBuffer[];
//
#property indicator_label26 "MAL"
#property indicator_type26 DRAW_LINE
#property indicator_color26 clrAqua
#property indicator_style26 STYLE_SOLID
#property indicator_width26 1
#property indicator_label28 "MAL"
#property indicator_type28 DRAW_LINE
#property indicator_color28 clrAqua
#property indicator_style28 STYLE_SOLID
#property indicator_width28 1
//
// MAC ...
//
#define macBufferIndex 30
#define macBufferPlotIndex 26
#define macBufferIndex 32
#define macBufferPlotIndex 28
double macBuffer[];
//
#property indicator_label27 "MAC"
#property indicator_type27 DRAW_LINE
#property indicator_color27 clrYellow
#property indicator_style27 STYLE_SOLID
#property indicator_width27 1
#property indicator_label29 "MAC"
#property indicator_type29 DRAW_LINE
#property indicator_color29 clrYellow
#property indicator_style29 STYLE_SOLID
#property indicator_width29 1
//
// Data Buffers ...
#define mLastBufferIndex 30
#define mLastBufferIndex 32
//
#define trendStateBufferIndex mLastBufferIndex + 1
@@ -1361,6 +1395,40 @@ void DefineBuffers()
//
PlotIndexSetDouble(fiboLevel3BufferIndex, PLOT_EMPTY_VALUE, emptyValue);
//
// FIBO L4 ...
//
ENUM_DRAW_TYPE fiboL4DrawType = showFiboLevel4 ? DRAW_LINE : DRAW_NONE;
//
ArraySetAsSeries(fiboLevel4Buffer, true);
SetIndexBuffer(fiboLevel4BufferIndex, fiboLevel4Buffer, INDICATOR_DATA);
//
PlotIndexSetInteger(fiboLevel4BufferIndex, PLOT_SHOW_DATA, showFiboLevel4);
PlotIndexSetInteger(fiboLevel4BufferIndex, PLOT_DRAW_TYPE, fiboL4DrawType);
//
PlotIndexSetDouble(fiboLevel4BufferIndex, PLOT_EMPTY_VALUE, emptyValue);
//
// FIBO L5 ...
//
ENUM_DRAW_TYPE fiboL5DrawType = showFiboLevel5 ? DRAW_LINE : DRAW_NONE;
//
ArraySetAsSeries(fiboLevel5Buffer, true);
SetIndexBuffer(fiboLevel5BufferIndex, fiboLevel5Buffer, INDICATOR_DATA);
//
PlotIndexSetInteger(fiboLevel5BufferIndex, PLOT_SHOW_DATA, showFiboLevel5);
PlotIndexSetInteger(fiboLevel5BufferIndex, PLOT_DRAW_TYPE, fiboL5DrawType);
//
PlotIndexSetDouble(fiboLevel5BufferIndex, PLOT_EMPTY_VALUE, emptyValue);
//
// SAR ...
@@ -1819,6 +1887,14 @@ void FillBuffersZero(int barIndex)
valeBuffer[barIndex] = emptyValue;
valeGoldenBuffer[barIndex] = emptyValue;
//
// FiBo ...
fiboLevel1Buffer[barIndex] = emptyValue;
fiboLevel2Buffer[barIndex] = emptyValue;
fiboLevel3Buffer[barIndex] = emptyValue;
fiboLevel4Buffer[barIndex] = emptyValue;
fiboLevel5Buffer[barIndex] = emptyValue;
//
// SAR ...
sarBuffer[barIndex] = emptyValue;
@@ -2030,12 +2106,6 @@ void CalculateValues(
double iHHH = hHHBuffer[bar_index];
double iHLL = hLLBuffer[bar_index];
//
// Calculate BOS ...
//
// Calculate CHOCH ...
//
// Calculate Support ...
double lastSupport =
@@ -2131,15 +2201,105 @@ void CalculateValues(
);
}
//
// Calculate Swings ...
//
double lastSwingLow =
isFirstBar
? emptyValue
: swingLowBuffer[lastBarIndex];
double lastSwingHigh =
isFirstBar
? emptyValue
: swingHighBuffer[lastBarIndex];
//
bool isSwingLow = IsSwingLow(
high,
low,
bar_index,
swingLength //
);
bool isSwingHigh = IsSwingHigh(
high,
low,
bar_index,
swingLength //
);
bool hasSwing = isSwingLow ||
isSwingHigh;
double iSwingLow = emptyValue;
double iSwingHigh = emptyValue;
if (!hasSwing)
{
//
// FillBuffersZero(bar_index);
//
iSwingLow = lastSwingLow;
iSwingHigh = lastSwingHigh;
//
swingLowBuffer[bar_index] = lastSwingLow;
swingHighBuffer[bar_index] = lastSwingHigh;
}
else
{
//
iSwingLow = low[bar_index];
double iSwingHigh = high[bar_index];
//
if (isSwingLow && !isSwingHigh)
{
iSwingHigh = lastSwingHigh;
}
else if (isSwingHigh && !isSwingLow)
{
iSwingLow = lastSwingLow;
}
//
if (iSwingLow > lastSwingLow &&
iSwingHigh == lastSwingHigh)
{
iSwingLow = lastSwingLow;
}
//
if (iSwingHigh < lastSwingHigh &&
iSwingLow == lastSwingLow)
{
iSwingHigh = lastSwingHigh;
}
//
swingLowBuffer[bar_index] = iSwingLow;
swingHighBuffer[bar_index] = iSwingHigh;
}
//
// Calculate Fibo Levels ...
//
double iFiboUpper = peakBuffer[bar_index];
double iFiboLower = valeBuffer[bar_index];
double iFiboValues[] = {
peakBuffer[bar_index],
valeBuffer[bar_index],
supBuffer[bar_index],
swingLowBuffer[bar_index],
swingHighBuffer[bar_index],
resBuffer[bar_index], //
};
//
double iFiboLevel1 = GetFibonacciLevel(
double iFiboUpper = GetMax(iFiboValues);
double iFiboLower = GetMin(iFiboValues);
//
// Fibo Level 1 ...
double iFiboLevel1 = emptyValue;
iFiboLevel1 = GetFibonacciLevel(
iFiboUpper,
iFiboLower,
fiboLevel1,
@@ -2148,7 +2308,9 @@ void CalculateValues(
fiboLevel1Buffer[bar_index] = iFiboLevel1;
//
double iFiboLevel2 = GetFibonacciLevel(
// Fibo Level 2 ...
double iFiboLevel2 = emptyValue;
iFiboLevel2 = GetFibonacciLevel(
iFiboUpper,
iFiboLower,
fiboLevel2,
@@ -2157,7 +2319,9 @@ void CalculateValues(
fiboLevel2Buffer[bar_index] = iFiboLevel2;
//
double iFiboLevel3 = GetFibonacciLevel(
// Fibo Level 3 ...
double iFiboLevel3 = emptyValue;
iFiboLevel3 = GetFibonacciLevel(
iFiboUpper,
iFiboLower,
fiboLevel3,
@@ -2165,6 +2329,28 @@ void CalculateValues(
);
fiboLevel3Buffer[bar_index] = iFiboLevel3;
//
// Fibo Level 4 ...
double iFiboLevel4 = emptyValue;
iFiboLevel4 = GetFibonacciLevel(
iFiboUpper,
iFiboLower,
fiboLevel4,
X_DIRECTION_BEARISH //
);
fiboLevel4Buffer[bar_index] = iFiboLevel4;
//
// Fibo Level 5 ...
double iFiboLevel5 = emptyValue;
iFiboLevel5 = GetFibonacciLevel(
iFiboUpper,
iFiboLower,
fiboLevel5,
X_DIRECTION_BEARISH //
);
fiboLevel5Buffer[bar_index] = iFiboLevel5;
//
// Calculate Trend Color Buffer ...
double iClose = close[bar_index];
@@ -2279,43 +2465,6 @@ void CalculateValues(
peakGoldenBuffer[bar_index] = iPeakGold;
valeGoldenBuffer[bar_index] = iValeGold;
//
// Calculate Swings ...
//
double lastSwingLow =
isFirstBar
? emptyValue
: swingLowBuffer[lastBarIndex];
bool isSwingLow = IsSwingLow(
high,
low,
bar_index,
swingLength //
);
double iSwingLow =
isSwingLow
? low[bar_index]
: lastSwingLow;
swingLowBuffer[bar_index] = iSwingLow;
//
double lastSwingHigh =
isFirstBar
? emptyValue
: swingHighBuffer[lastBarIndex];
bool isSwingHigh = IsSwingHigh(
high,
low,
bar_index,
swingLength //
);
double iSwingHigh =
isSwingHigh
? high[bar_index]
: lastSwingHigh;
swingHighBuffer[bar_index] = iSwingHigh;
//
// TKI State and Color ...