#ifndef STRATEGYICTPRO #define STRATEGYICTPRO #include "StrategyBase.mqh" class…
- User
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
#ifndef STRATEGY_ICT_PRO #define STRATEGY_ICT_PRO #include "StrategyBase.mqh"
class StrategyICT : public IStrategy { private: string lastReason; double minRR;
public: StrategyICT() { minRR = 1.5; }
string Name() override { return "ICT Pro Strategy (ATR-FVG)"; }
string GetLastEntryReason()
{
return lastReason;
}
bool CheckEntry(double &entryPrice, double &sl, double &tp) override
{ if (_Period != PERIOD_M1) return false;
if (!IsTrendAligned())
{
lastReason = "❌ ناهماهنگ با ساختار بازار (M5)";
return false;
}
double direction = 0.0;
if (!FindFVG(entryPrice, sl, direction))
{
lastReason = "❌ FVG معتبر پیدا نشد";
return false;
}
entryPrice = (direction > 0) ? SymbolInfoDouble(_Symbol, SYMBOL_ASK)
: SymbolInfoDouble(_Symbol, SYMBOL_BID);
double risk = MathAbs(entryPrice - sl);
if (risk <= 0)
{
lastReason = "❌ فاصله غیرمنطقی SL با Entry";
return false;
}
tp = (direction > 0) ? entryPrice + risk * minRR
: entryPrice - risk * minRR;
tp = NormalizeDouble(tp, _Digits);
sl = NormalizeDouble(sl, _Digits);
entryPrice = NormalizeDouble(entryPrice, _Digits);
// ✅ شرط جدید: بررسی حداقل فاصله 20 پوینت
double pointDistanceSL = MathAbs(entryPrice - sl);
double pointDistanceTP = MathAbs(tp - entryPrice);
double minPoints = 20 * _Point;
if (pointDistanceSL < minPoints || pointDistanceTP < minPoints)
{
lastReason = "❌ فاصله SL یا TP کمتر از ۲۰ پوینت";
return false;
}
lastReason = "✅ ورود بر اساس FVG + روند تایید شده (ATR adjusted)";
return true;
}
private: bool IsTrendAligned() { double highPrev = iHigh(_Symbol, PERIOD_M5, 2); double highLast = iHigh(_Symbol, PERIOD_M5, 1); double lowPrev = iLow(_Symbol, PERIOD_M5, 2); double lowLast = iLow(_Symbol, PERIOD_M5, 1);
if (highLast > highPrev && lowLast > lowPrev)
return (iClose(_Symbol, PERIOD_M5, 0) > iOpen(_Symbol, PERIOD_M5, 0)); // صعودی
else if (highLast < highPrev && lowLast < lowPrev)
return (iClose(_Symbol, PERIOD_M5, 0) < iOpen(_Symbol, PERIOD_M5, 0)); // نزولی
return false;
}
bool FindFVG(double &entry, double &sl, double &direction)
{
for (int i = 10; i < 100; i++)
{
double high1 = iHigh(_Symbol, PERIOD_M1, i);
double low1 = iLow(_Symbol, PERIOD_M1, i);
double high2 = iHigh(_Symbol, PERIOD_M1, i - 1);
double low2 = iLow(_Symbol, PERIOD_M1, i - 1);
double high3 = iHigh(_Symbol, PERIOD_M1, i - 2);
double low3 = iLow(_Symbol, PERIOD_M1, i - 2);
int localatrHandle = iATR(_Symbol, PERIOD_M1, 14);
if (localatrHandle == INVALID_HANDLE) return false;
double atrBuffer[]; if (CopyBuffer(localatrHandle, 0, i, 1, atrBuffer) <= 0) return false;
double atr = atrBuffer[0];
if (low1 > high3) // FVG صعودی
{
direction = +1;
sl = low3 - atr * 0.8;
entry = 0; // پر میشه بعداً
return true;
}
if (high1 < low3) // FVG نزولی
{
direction = -1;
sl = high3 + atr * 0.8;
entry = 0;
return true;
}
}
return false;
}
};
#endif
نظرتو راجب این کلاس استراتژی بگو و نکات اصلاحی و در نهایت نسخه بازنویسی شده اس رو بهم بده
مشکلات عملکردی و بهینهسازی:
FindFVG یک هندل جدید ایجاد میشود که باعث مصرف منابع و کاهش عملکرد میشود.مشکلات منطقی:
risk) ممکن است در شرایط خاص مقدار صفر یا منفی تولید کند._Period: چک کردن تایمفریم با _Period ممکن است در برخی محیطها کار نکند.بهینهسازیهای پیشنهادی:
#ifndef STRATEGY_ICT_PRO
#define STRATEGY_ICT_PRO
#include "StrategyBase.mqh"
#include <Indicators/Trend.mqh>
class StrategyICT : public IStrategy
{
private:
string lastReason;
double minRR;
int atrHandle;
CiMA emaFilter;
public:
StrategyICT() : minRR(1.5), atrHandle(INVALID_HANDLE)
{
// Initialize ATR handle once
atrHandle = iATR(_Symbol, PERIOD_M1, 14);
// Initialize EMA for trend filtering (50-period)
emaFilter.Create(_Symbol, PERIOD_M5, 50, 0, MODE_EMA, PRICE_CLOSE);
}
~StrategyICT()
{
if(atrHandle != INVALID_HANDLE)
IndicatorRelease(atrHandle);
}
string Name() override { return "ICT Pro Strategy (Enhanced)"; }
string GetLastEntryReason() { return lastReason; }
bool CheckEntry(double &entryPrice, double &sl, double &tp) override
{
// Check current timeframe
if(Period() != PERIOD_M1)
{
lastReason = "❌ استراتژی فقط در تایمفریم M1 کار میکند";
return false;
}
// Trend alignment check
if(!IsTrendAligned())
{
lastReason = "❌ ناهماهنگ با روند بازار (M5)";
return false;
}
// Find most recent valid FVG
double direction = 0;
if(!FindFVG(entryPrice, sl, direction))
{
lastReason = "❌ FVG معتبر یافت نشد";
return false;
}
// Entry confirmation (close price beyond FVG)
if(!ConfirmEntry(direction, entryPrice))
{
lastReason = "❌ تأیید ورود ناموفق (عدم عبور قیمت)";
return false;
}
// Calculate TP based on risk-reward
double risk = MathAbs(entryPrice - sl);
tp = (direction > 0) ?
entryPrice + risk * minRR :
entryPrice - risk * minRR;
// Normalize prices
entryPrice = NormalizeDouble(entryPrice, _Digits);
sl = NormalizeDouble(sl, _Digits);
tp = NormalizeDouble(tp, _Digits);
// Validate minimum distance (20 points)
double minDist = 20 * _Point;
if(MathAbs(entryPrice - sl) < minDist ||
MathAbs(tp - entryPrice) < minDist)
{
lastReason = "❌ فاصله SL/TP کمتر از ۲۰ پوینت";
return false;
}
lastReason = "✅ ورود بر اساس FVG + روند + تأیید قیمت";
return true;
}
private:
bool IsTrendAligned()
{
// Improved trend filter using EMA
if(!emaFilter.RefreshRates())
return false;
double currentClose = iClose(_Symbol, PERIOD_M5, 0);
double emaValue = emaFilter.Main(0);
// Bullish trend: price above EMA
if(currentClose > emaValue)
return (iClose(_Symbol, PERIOD_M5, 0) > iOpen(_Symbol, PERIOD_M5, 0));
// Bearish trend: price below EMA
if(currentClose < emaValue)
return (iClose(_Symbol, PERIOD_M5, 0) < iOpen(_Symbol, PERIOD_M5, 0));
return false;
}
bool FindFVG(double &entry, double &sl, double &direction)
{
// Scan from most recent to oldest (last 100 bars)
for(int i = 2; i <= 100; i++)
{
double high0 = iHigh(_Symbol, PERIOD_M1, i);
double low0 = iLow(_Symbol, PERIOD_M1, i);
double high2 = iHigh(_Symbol, PERIOD_M1, i-2);
double low2 = iLow(_Symbol, PERIOD_M1, i-2);
// Bullish FVG condition
if(low0 > high2)
{
direction = +1;
entry = high2; // Potential entry level
SetStopLoss(i, direction, sl);
return true;
}
// Bearish FVG condition
else if(high0 < low2)
{
direction = -1;
entry = low2; // Potential entry level
SetStopLoss(i, direction, sl);
return true;
}
}
return false;
}
void SetStopLoss(int barIndex, double direction, double &sl)
{
double atrBuffer[];
if(CopyBuffer(atrHandle, 0, barIndex, 1, atrBuffer) > 0)
{
double atrValue = atrBuffer[0];
if(direction > 0)
sl = iLow(_Symbol, PERIOD_M1, barIndex) - atrValue * 0.8;
else
sl = iHigh(_Symbol, PERIOD_M1, barIndex) + atrValue * 0.8;
}
}
bool ConfirmEntry(double direction, double &entryPrice)
{
// Wait for price to break FVG level
double currentPrice = (direction > 0) ?
SymbolInfoDouble(_Symbol, SYMBOL_BID) :
SymbolInfoDouble(_Symbol, SYMBOL_ASK);
if(direction > 0)
return currentPrice > entryPrice;
else
return currentPrice < entryPrice;
}
};
#endif
مدیریت منابع:
CiMA برای فیلتر روند با استفاده از EMA.الگوریتمهای بهبودیافته:
ConfirmEntry برای تأیید نهایی ورود با بررسی شکست FVG.پایداری کد:
SetStopLoss.Period() به جای _Period برای سازگاری بهتر.منطق معاملاتی:
minRR.این بهبودها باعث افزایش پایداری، کاهش خطاهای زمان اجرا و بهبود دقت سیگنالهای معاملاتی میشود.