Add this with your other global variables (ORB_High, ORB_Low, etc.) so the EA only calculates the Asia trend once per day, rather than on every single tick.
Code: Select all
bool AsiaWasTrend = false;Code: Select all
bool AsiaWasTrend = false;Code: Select all
//+------------------------------------------------------------------+
//| Check if the Asia session was a one-sided trend |
//+------------------------------------------------------------------+
bool IsAsiaTrendDay(datetime asiaStart, datetime asiaEnd)
{
if(!UseAsiaTrendFilter) return false;
int startBar = iBarShift(Symbol(), PERIOD_M5, asiaStart, false);
int endBar = iBarShift(Symbol(), PERIOD_M5, asiaEnd, false);
if(startBar < 0 || endBar < 0 || startBar <= endBar) return false;
double asiaOpen = iOpen(Symbol(), PERIOD_M5, startBar);
double asiaClose = iClose(Symbol(), PERIOD_M5, endBar);
double asiaHigh = 0.0;
double asiaLow = 99999.0;
// Find the High and Low of the Asian session
for(int i = endBar; i <= startBar; i++)
{
if(High[i] > asiaHigh) asiaHigh = High[i];
if(Low[i] < asiaLow) asiaLow = Low[i];
}
// Adjust for 3/5 digit brokers to ensure pip input works correctly
double pointMultiplier = (Digits == 3 || Digits == 5) ? 10.0 : 1.0;
double minTrendPoints = AsiaTrendMinPips * pointMultiplier * Point;
double totalRange = asiaHigh - asiaLow;
double netMove = MathAbs(asiaClose - asiaOpen);
// A trend day means price moved far AND closed near the extreme (e.g., net move is > 70% of total range)
if(netMove >= minTrendPoints && netMove >= (totalRange * 0.70))
{
Print("Fade Vetoed: Asia was a directional trend. Net Move: ", netMove / pointMultiplier / Point, " pips.");
return true;
}
return false;
}Code: Select all
// 4. Mark ORB as formed once the end time passes and evaluate Asia
if(TimeCurrent() > endTime && !ORB_Formed && ORB_High > 0)
{
ORB_Formed = true;
datetime asiaStart = StringToTime(TimeToStr(TimeCurrent(), TIME_DATE) + " " + AsiaStart_Time);
datetime asiaEnd = StringToTime(TimeToStr(TimeCurrent(), TIME_DATE) + " " + AsiaEnd_Time);
// Calculate once for the day
AsiaWasTrend = IsAsiaTrendDay(asiaStart, asiaEnd);
}Code: Select all
// Trigger: Candle closes fully back inside the ORB (Short Example)
if(Close[1] < ORB_High && Open[1] < ORB_High && Bars_Outside <= MaxBarsOutside && Broke_High && !AsiaWasTrend)
{
// ... execute trade