mirror of
https://github.com/softwaredevelop/mql5.git
synced 2026-08-19 15:28:06 +00:00
refactor: trend direction calculation
This commit is contained in:
@@ -107,40 +107,26 @@ int OnCalculate(const int rates_total,
|
|||||||
else
|
else
|
||||||
BufferLowerBand[i] = BufferLowerBand[i-1];
|
BufferLowerBand[i] = BufferLowerBand[i-1];
|
||||||
|
|
||||||
// --- Trend direction
|
// --- Trend direction and final Supertrend value ---
|
||||||
int trend = 0;
|
int trend = 0;
|
||||||
if(BufferSupertrend[i-1] == BufferUpperBand[i-1])
|
if(BufferSupertrend[i-1] == BufferUpperBand[i-1])
|
||||||
trend = (close[i] > BufferUpperBand[i]) ? 1 : -1; // Previous was Down
|
trend = (close[i] > BufferUpperBand[i]) ? 1 : -1;
|
||||||
else
|
else
|
||||||
trend = (close[i] < BufferLowerBand[i]) ? -1 : 1; // Previous was Up
|
trend = (close[i] < BufferLowerBand[i]) ? -1 : 1;
|
||||||
|
|
||||||
// --- Set final Supertrend value and color
|
if(trend == 1) // Uptrend
|
||||||
if(trend == 1) // Current trend is UP
|
|
||||||
{
|
{
|
||||||
BufferSupertrend[i] = BufferLowerBand[i];
|
BufferSupertrend[i] = BufferLowerBand[i];
|
||||||
BufferColor[i] = 0; // Green
|
BufferColor[i] = 0; // Green
|
||||||
|
|
||||||
// --- FIX: Create the gap on trend change ---
|
|
||||||
// If the previous trend was DOWN, invalidate its last point
|
|
||||||
if(BufferSupertrend[i-1] == BufferUpperBand[i-1])
|
|
||||||
{
|
|
||||||
BufferSupertrend[i-1] = EMPTY_VALUE;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else // Current trend is DOWN
|
else // Downtrend
|
||||||
{
|
{
|
||||||
BufferSupertrend[i] = BufferUpperBand[i];
|
BufferSupertrend[i] = BufferUpperBand[i];
|
||||||
BufferColor[i] = 1; // Red
|
BufferColor[i] = 1; // Red
|
||||||
|
|
||||||
// --- FIX: Create the gap on trend change ---
|
|
||||||
// If the previous trend was UP, invalidate its last point
|
|
||||||
if(BufferSupertrend[i-1] == BufferLowerBand[i-1])
|
|
||||||
{
|
|
||||||
BufferSupertrend[i-1] = EMPTY_VALUE;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return(rates_total);
|
return(rates_total);
|
||||||
}
|
}
|
||||||
//+------------------------------------------------------------------+
|
//+------------------------------------------------------------------+
|
||||||
|
//+------------------------------------------------------------------+
|
||||||
|
|||||||
Reference in New Issue
Block a user