Neo1986
Pine Script Rookie
Pine Script Rookie
Posts: 1
Joined: February 18th, 2024

Can someone help with the right function ?

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);
}

Return to “Request Scripts”