126 行
无行尾
4.2 KiB
MQL5
126 行
无行尾
4.2 KiB
MQL5
//+------------------------------------------------------------------+
|
|
//| FibLevels.mqh |
|
|
//| Fibonacci Level Calculation and Drawing |
|
|
//+------------------------------------------------------------------+
|
|
#property copyright "QuarterTheory x VIZION"
|
|
#property strict
|
|
|
|
#include "GlobalVariables.mqh"
|
|
#include "InputParams.mqh"
|
|
#include "Utilities.mqh"
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| Calculate Fibonacci and MFIB levels |
|
|
//+------------------------------------------------------------------+
|
|
void CalculateLevels()
|
|
{
|
|
// Static Fibonacci levels for reference
|
|
double high = iHigh(_Symbol, PERIOD_CURRENT, 0);
|
|
double low = iLow(_Symbol, PERIOD_CURRENT, 0);
|
|
|
|
for(int i=1; i<=Lookback_Bars; i++)
|
|
{
|
|
double h = iHigh(_Symbol, PERIOD_CURRENT, i);
|
|
double l = iLow(_Symbol, PERIOD_CURRENT, i);
|
|
if(h > high) high = h;
|
|
if(l < low) low = l;
|
|
}
|
|
|
|
double range = high - low;
|
|
PriceLevels[0] = low;
|
|
PriceLevels[1] = low + range * 0.236;
|
|
PriceLevels[2] = low + range * 0.382;
|
|
PriceLevels[3] = low + range * 0.5;
|
|
PriceLevels[4] = low + range * 0.618;
|
|
PriceLevels[5] = low + range * 0.786;
|
|
PriceLevels[6] = high;
|
|
|
|
// MOVING FIBONACCI - From ATH to ATL (stacked from top)
|
|
double ath = iHigh(_Symbol, PERIOD_CURRENT, 0);
|
|
double atl = iLow(_Symbol, PERIOD_CURRENT, 0);
|
|
|
|
for(int i=1; i<=MFIB_Lookback; i++)
|
|
{
|
|
double h = iHigh(_Symbol, PERIOD_CURRENT, i);
|
|
double l = iLow(_Symbol, PERIOD_CURRENT, i);
|
|
if(h > ath) ath = h;
|
|
if(l < atl) atl = l;
|
|
}
|
|
|
|
MFIB_High = ath;
|
|
MFIB_Low = atl;
|
|
double mfib_range = ath - atl;
|
|
|
|
// Levels stacked from ATH down to ATL
|
|
MFIB_Level_236 = ath - (mfib_range * 0.236);
|
|
MFIB_Level_382 = ath - (mfib_range * 0.382);
|
|
MFIB_Level_050 = ath - (mfib_range * 0.500);
|
|
MFIB_Level_618 = ath - (mfib_range * 0.618);
|
|
MFIB_Level_786 = ath - (mfib_range * 0.786);
|
|
|
|
// MFIB .382 Bias Logic
|
|
if(Use_MFIB_382_Bias)
|
|
{
|
|
double current = MidPrice();
|
|
|
|
if(current > MFIB_Level_382)
|
|
MFIB_Bias = BIAS_BULL;
|
|
else if(current < MFIB_Level_382)
|
|
MFIB_Bias = BIAS_BEAR;
|
|
else
|
|
MFIB_Bias = BIAS_NEUTRAL;
|
|
}
|
|
else
|
|
{
|
|
MFIB_Bias = BIAS_NEUTRAL;
|
|
}
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| Draw Fibonacci levels on chart |
|
|
//+------------------------------------------------------------------+
|
|
void DrawLevels()
|
|
{
|
|
ObjectsDeleteAll(0, "Level_");
|
|
ObjectsDeleteAll(0, "MFIB_");
|
|
|
|
color level_colors[7] = {clrRed, clrOrange, clrYellow, clrLime, clrCyan, clrBlue, clrMagenta};
|
|
|
|
// Draw static fib levels
|
|
for(int i=0; i<7; i++)
|
|
{
|
|
string name = "Level_" + IntegerToString(i);
|
|
ObjectCreate(0, name, OBJ_HLINE, 0, 0, PriceLevels[i]);
|
|
ObjectSetInteger(0, name, OBJPROP_COLOR, level_colors[i]);
|
|
ObjectSetInteger(0, name, OBJPROP_STYLE, STYLE_DOT);
|
|
ObjectSetInteger(0, name, OBJPROP_WIDTH, 1);
|
|
}
|
|
|
|
// Draw MFIB levels (more prominent)
|
|
string mfib_name = "MFIB_382";
|
|
ObjectCreate(0, mfib_name, OBJ_HLINE, 0, 0, MFIB_Level_382);
|
|
ObjectSetInteger(0, mfib_name, OBJPROP_COLOR, clrYellow);
|
|
ObjectSetInteger(0, mfib_name, OBJPROP_STYLE, STYLE_SOLID);
|
|
ObjectSetInteger(0, mfib_name, OBJPROP_WIDTH, 2);
|
|
|
|
mfib_name = "MFIB_618";
|
|
ObjectCreate(0, mfib_name, OBJ_HLINE, 0, 0, MFIB_Level_618);
|
|
ObjectSetInteger(0, mfib_name, OBJPROP_COLOR, clrCyan);
|
|
ObjectSetInteger(0, mfib_name, OBJPROP_STYLE, STYLE_SOLID);
|
|
ObjectSetInteger(0, mfib_name, OBJPROP_WIDTH, 2);
|
|
|
|
mfib_name = "MFIB_050";
|
|
ObjectCreate(0, mfib_name, OBJ_HLINE, 0, 0, MFIB_Level_050);
|
|
ObjectSetInteger(0, mfib_name, OBJPROP_COLOR, clrWhite);
|
|
ObjectSetInteger(0, mfib_name, OBJPROP_STYLE, STYLE_SOLID);
|
|
ObjectSetInteger(0, mfib_name, OBJPROP_WIDTH, 1);
|
|
}
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| Clean up all level objects |
|
|
//+------------------------------------------------------------------+
|
|
void CleanupLevels()
|
|
{
|
|
ObjectsDeleteAll(0, "Level_");
|
|
ObjectsDeleteAll(0, "MFIB_");
|
|
} |