Can someone help with the right function ?
Posted: Sun Feb 18, 2024 9:55 am
Hallo,
I want to write an indicator to mark divergences. The original code comes from an mql5 script. I can't get any further with the function to find the last through to compare it with the current one. Here is the code from mql5:
//| Search last trough |
//+------------------------------------------------------------------+
int GetIndicatorLastTrough(int shift)
{
for(int i=shift-5; i>=2; i--)
{
if(signalBuffer <= signalBuffer[i-1] && signalBuffer <= signalBuffer[i-2] &&
signalBuffer <= signalBuffer[i+1] && signalBuffer <= signalBuffer[i+2])
{
for(int j=i; j>=2; j--)
{
if(macdBuffer[j] <= macdBuffer[j-1] && macdBuffer[j] < macdBuffer[j-2] &&
macdBuffer[j] <= macdBuffer[j+1] && macdBuffer[j] < macdBuffer[j+2])
return(j);
}
}
}
return(0);
}
I want to write an indicator to mark divergences. The original code comes from an mql5 script. I can't get any further with the function to find the last through to compare it with the current one. Here is the code from mql5:
//| Search last trough |
//+------------------------------------------------------------------+
int GetIndicatorLastTrough(int shift)
{
for(int i=shift-5; i>=2; i--)
{
if(signalBuffer <= signalBuffer[i-1] && signalBuffer <= signalBuffer[i-2] &&
signalBuffer <= signalBuffer[i+1] && signalBuffer <= signalBuffer[i+2])
{
for(int j=i; j>=2; j--)
{
if(macdBuffer[j] <= macdBuffer[j-1] && macdBuffer[j] < macdBuffer[j-2] &&
macdBuffer[j] <= macdBuffer[j+1] && macdBuffer[j] < macdBuffer[j+2])
return(j);
}
}
}
return(0);
}