314 行
无行尾
11 KiB
MQL5
314 行
无行尾
11 KiB
MQL5
//+------------------------------------------------------------------+
|
|
//| Warnings.mqh |
|
|
//| Warning Detection System |
|
|
//+------------------------------------------------------------------+
|
|
#property copyright "QuarterTheory x VIZION"
|
|
#property strict
|
|
|
|
#include "GlobalVariables.mqh"
|
|
#include "InputParams.mqh"
|
|
#include "Utilities.mqh"
|
|
|
|
//+------------------------------------------------------------------+
|
|
//| Detect all warning signals |
|
|
//+------------------------------------------------------------------+
|
|
void DetectWarnings()
|
|
{
|
|
double current = MidPrice();
|
|
double bufferPts = (double)MA_Touch_Buffer;
|
|
double prev = iClose(_Symbol, PERIOD_CURRENT, 1);
|
|
|
|
double mfib_levels[5] = {MFIB_Level_236, MFIB_Level_382, MFIB_Level_050, MFIB_Level_618, MFIB_Level_786};
|
|
|
|
// Reset all warnings
|
|
MA7_Cross_14_Warning = false;
|
|
MA7_Cross_21_Warning = false;
|
|
MA50_Break_Warning = false;
|
|
Fib_Reject_Warning = false;
|
|
MFIB_Reject_Warning = false;
|
|
Fib_Reclaim_Warning = false;
|
|
MFIB_Reclaim_Warning = false;
|
|
Fib_Break_Warning = false;
|
|
MFIB_Break_Warning = false;
|
|
MA_Reject_Warning = false;
|
|
MA_Reclaim_Warning = false;
|
|
MA_Break_Warning = false;
|
|
Stoch_Extreme_Warning = false;
|
|
Stoch_Reject_Warning = false;
|
|
Stoch_Level_Cross = false;
|
|
MA50_Warning = false;
|
|
MA140_Warning = false;
|
|
MA230_Warning = false;
|
|
MA500_Warning = false;
|
|
Pullback_Warning = false;
|
|
Retracement_Warning = false;
|
|
Band_Snap_Warning = false;
|
|
|
|
//================================================================
|
|
// STOCHASTIC ANALYSIS
|
|
//================================================================
|
|
if(Stoch_K_Current <= Stoch_Extreme_Low || Stoch_K_Current >= Stoch_Extreme_High)
|
|
Stoch_Extreme_Warning = true;
|
|
|
|
bool k_crossed_d = false;
|
|
bool near_key_level = false;
|
|
|
|
if((Stoch_K_Previous < Stoch_D_Current && Stoch_K_Current >= Stoch_D_Current) ||
|
|
(Stoch_K_Previous > Stoch_D_Current && Stoch_K_Current <= Stoch_D_Current))
|
|
{
|
|
k_crossed_d = true;
|
|
}
|
|
|
|
for(int i=0; i<5; i++)
|
|
{
|
|
if(MathAbs(Stoch_K_Current - Stoch_Levels[i]) <= 5.0)
|
|
{
|
|
near_key_level = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if(k_crossed_d && near_key_level)
|
|
Stoch_Level_Cross = true;
|
|
|
|
bool stoch_reject_down = (StochCrossDown() && Stoch_K_Current > 50);
|
|
bool stoch_reject_up = (StochCrossUp() && Stoch_K_Current < 50);
|
|
if(stoch_reject_down || stoch_reject_up || Stoch_Level_Cross)
|
|
Stoch_Reject_Warning = true;
|
|
|
|
//================================================================
|
|
// MA CROSS ANALYSIS
|
|
//================================================================
|
|
bool ma7_crossed_14_down = (MA_Previous[0] > MA_Previous[1]) && (MA_Current[0] <= MA_Current[1]);
|
|
bool ma7_crossed_14_up = (MA_Previous[0] < MA_Previous[1]) && (MA_Current[0] >= MA_Current[1]);
|
|
if(ma7_crossed_14_down || ma7_crossed_14_up)
|
|
{
|
|
MA7_Cross_14_Warning = true;
|
|
Pullback_Warning = true;
|
|
}
|
|
|
|
bool ma7_crossed_21_down = (MA_Previous[0] > MA_Previous[2]) && (MA_Current[0] <= MA_Current[2]);
|
|
bool ma7_crossed_21_up = (MA_Previous[0] < MA_Previous[2]) && (MA_Current[0] >= MA_Current[2]);
|
|
if(ma7_crossed_21_down || ma7_crossed_21_up)
|
|
{
|
|
MA7_Cross_21_Warning = true;
|
|
Retracement_Warning = true;
|
|
}
|
|
|
|
bool ma7_broke_50_down = (MA_Previous[0] > MA_Previous[3]) && (MA_Current[0] <= MA_Current[3]);
|
|
bool ma7_broke_50_up = (MA_Previous[0] < MA_Previous[3]) && (MA_Current[0] >= MA_Current[3]);
|
|
if(ma7_broke_50_down || ma7_broke_50_up)
|
|
MA50_Break_Warning = true;
|
|
|
|
//================================================================
|
|
// BAND SNAP
|
|
//================================================================
|
|
if(Current_ATR > 0.0)
|
|
{
|
|
double distance = MathAbs(current - MA_Current[0]);
|
|
double band_threshold = Current_ATR * Band_Snap_ATR_Multiplier;
|
|
if(distance >= band_threshold)
|
|
Band_Snap_Warning = true;
|
|
}
|
|
|
|
//================================================================
|
|
// FIBONACCI LEVEL ANALYSIS
|
|
//================================================================
|
|
bool at_fib = false;
|
|
int fib_level_idx = -1;
|
|
|
|
for(int i=1; i<6; i++)
|
|
{
|
|
if(NearLevel(current, PriceLevels[i], bufferPts))
|
|
{
|
|
at_fib = true;
|
|
fib_level_idx = i;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if(at_fib)
|
|
{
|
|
double fib_level = PriceLevels[fib_level_idx];
|
|
|
|
if(Stoch_Extreme_Warning || Stoch_Reject_Warning || Stoch_Level_Cross)
|
|
Fib_Reject_Warning = true;
|
|
|
|
if((prev < fib_level && current > fib_level) || (prev > fib_level && current < fib_level))
|
|
Fib_Reclaim_Warning = true;
|
|
|
|
if(MathAbs(current - fib_level) > bufferPts * 1.5)
|
|
Fib_Break_Warning = true;
|
|
}
|
|
|
|
//================================================================
|
|
// MFIB LEVEL ANALYSIS
|
|
//================================================================
|
|
bool at_mfib = false;
|
|
double mfib_level = 0;
|
|
|
|
for(int i=0; i<5; i++)
|
|
{
|
|
if(NearLevel(current, mfib_levels[i], bufferPts))
|
|
{
|
|
at_mfib = true;
|
|
mfib_level = mfib_levels[i];
|
|
break;
|
|
}
|
|
}
|
|
|
|
if(at_mfib)
|
|
{
|
|
if(Stoch_Extreme_Warning || Stoch_Reject_Warning || Stoch_Level_Cross)
|
|
MFIB_Reject_Warning = true;
|
|
|
|
if((prev < mfib_level && current > mfib_level) || (prev > mfib_level && current < mfib_level))
|
|
MFIB_Reclaim_Warning = true;
|
|
|
|
if(MathAbs(current - mfib_level) > bufferPts * 1.5)
|
|
MFIB_Break_Warning = true;
|
|
}
|
|
|
|
//================================================================
|
|
// STRONG MA ANALYSIS
|
|
//================================================================
|
|
bool at_ma50 = NearLevel(current, MA_Current[3], bufferPts);
|
|
bool at_ma140 = NearLevel(current, MA_Current[4], bufferPts);
|
|
bool at_ma230 = NearLevel(current, MA_Current[5], bufferPts);
|
|
bool at_ma500 = NearLevel(current, MA_Current[6], bufferPts);
|
|
|
|
if(at_ma50) MA50_Warning = true;
|
|
if(at_ma140) MA140_Warning = true;
|
|
if(at_ma230) MA230_Warning = true;
|
|
if(at_ma500) MA500_Warning = true;
|
|
|
|
if((at_ma50 || at_ma140 || at_ma230 || at_ma500) &&
|
|
(Stoch_Extreme_Warning || Stoch_Reject_Warning || Stoch_Level_Cross))
|
|
{
|
|
MA_Reject_Warning = true;
|
|
}
|
|
|
|
if(at_ma50 && ((prev < MA_Current[3] && current > MA_Current[3]) ||
|
|
(prev > MA_Current[3] && current < MA_Current[3])))
|
|
MA_Reclaim_Warning = true;
|
|
|
|
if(at_ma140 && ((prev < MA_Current[4] && current > MA_Current[4]) ||
|
|
(prev > MA_Current[4] && current < MA_Current[4])))
|
|
MA_Reclaim_Warning = true;
|
|
|
|
if((at_ma50 || at_ma140 || at_ma230) && MathAbs(current - MA_Current[3]) > bufferPts * 2)
|
|
MA_Break_Warning = true;
|
|
|
|
//================================================================
|
|
// PULLBACK CONFLUENCE
|
|
//================================================================
|
|
int pullback_signals = 0;
|
|
|
|
if(MA7_Cross_14_Warning) pullback_signals++;
|
|
if(Fib_Reject_Warning) pullback_signals++;
|
|
if(MFIB_Reject_Warning) pullback_signals++;
|
|
if(MA_Reject_Warning) pullback_signals++;
|
|
if(Stoch_Level_Cross) pullback_signals++;
|
|
if(Band_Snap_Warning) pullback_signals++;
|
|
if(Fib_Reclaim_Warning) pullback_signals++;
|
|
if(MFIB_Reclaim_Warning) pullback_signals++;
|
|
if(MA_Reclaim_Warning) pullback_signals++;
|
|
|
|
if(pullback_signals >= 2)
|
|
Pullback_Warning = true;
|
|
|
|
//================================================================
|
|
// WARNING CONFLUENCE COUNT
|
|
//================================================================
|
|
Warning_Confluence_Count = 0;
|
|
|
|
if(Stoch_Extreme_Warning) Warning_Confluence_Count++;
|
|
if(Stoch_Reject_Warning) Warning_Confluence_Count++;
|
|
if(Stoch_Level_Cross) Warning_Confluence_Count++;
|
|
if(MA7_Cross_14_Warning) Warning_Confluence_Count++;
|
|
if(MA7_Cross_21_Warning) Warning_Confluence_Count++;
|
|
if(MA50_Break_Warning) Warning_Confluence_Count++;
|
|
if(Fib_Reject_Warning) Warning_Confluence_Count++;
|
|
if(MFIB_Reject_Warning) Warning_Confluence_Count++;
|
|
if(MA_Reject_Warning) Warning_Confluence_Count++;
|
|
if(Fib_Reclaim_Warning) Warning_Confluence_Count++;
|
|
if(MFIB_Reclaim_Warning) Warning_Confluence_Count++;
|
|
if(MA_Reclaim_Warning) Warning_Confluence_Count++;
|
|
if(Band_Snap_Warning) Warning_Confluence_Count++;
|
|
if(MA50_Warning) Warning_Confluence_Count++;
|
|
if(MA140_Warning) Warning_Confluence_Count++;
|
|
if(MA230_Warning) Warning_Confluence_Count++;
|
|
if(MA500_Warning) Warning_Confluence_Count++;
|
|
|
|
Warning_Confluence_3Plus = (Warning_Confluence_Count >= 3);
|
|
|
|
//================================================================
|
|
// RE-ENTRY COMBO FLAGS
|
|
//================================================================
|
|
bool at_strong_ma = (MA140_Warning || MA230_Warning || MA500_Warning);
|
|
|
|
MA14_Magnet_Active = false;
|
|
if(Current_ATR > 0.0)
|
|
{
|
|
double distance_to_ma14 = MathAbs(current - MA_Current[1]);
|
|
if((distance_to_ma14 / Current_ATR) < 0.7)
|
|
MA14_Magnet_Active = true;
|
|
}
|
|
|
|
Fib_Break_Confirmed = false;
|
|
for(int i=1; i<6; i++)
|
|
{
|
|
if(MathAbs(prev - PriceLevels[i]) < bufferPts * 0.5 &&
|
|
MathAbs(current - PriceLevels[i]) > bufferPts * 2.0)
|
|
{
|
|
Fib_Break_Confirmed = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
MFIB_Break_Confirmed = false;
|
|
for(int i=0; i<5; i++)
|
|
{
|
|
if(MathAbs(prev - mfib_levels[i]) < bufferPts * 0.5 &&
|
|
MathAbs(current - mfib_levels[i]) > bufferPts * 2.0)
|
|
{
|
|
MFIB_Break_Confirmed = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
Strong_MA_Bounce = false;
|
|
if(at_strong_ma)
|
|
{
|
|
bool ma140_bounce = false, ma230_bounce = false, ma500_bounce = false;
|
|
|
|
if(MA140_Warning)
|
|
{
|
|
if((prev < MA_Current[4] && current > MA_Current[4]) ||
|
|
(prev > MA_Current[4] && current < MA_Current[4]))
|
|
ma140_bounce = true;
|
|
}
|
|
|
|
if(MA230_Warning)
|
|
{
|
|
if((prev < MA_Current[5] && current > MA_Current[5]) ||
|
|
(prev > MA_Current[5] && current < MA_Current[5]))
|
|
ma230_bounce = true;
|
|
}
|
|
|
|
if(MA500_Warning)
|
|
{
|
|
if((prev < MA_Current[6] && current > MA_Current[6]) ||
|
|
(prev > MA_Current[6] && current < MA_Current[6]))
|
|
ma500_bounce = true;
|
|
}
|
|
|
|
if((ma140_bounce || ma230_bounce || ma500_bounce) &&
|
|
(Stoch_Level_Cross || Stoch_Reject_Warning))
|
|
Strong_MA_Bounce = true;
|
|
}
|
|
|
|
Trend_Resumption = false;
|
|
if(IsBullBias() && Bull_MA50_Reclaimed()) Trend_Resumption = true;
|
|
if(IsBearBias() && Bear_MA50_Reclaimed()) Trend_Resumption = true;
|
|
} |