I want to Calculate, Current Bar Low, how many bars away from LATEST Lowest Low (Look Back Period is 6 Period excluding Current Bar = Total bars 7)
For this purpose I am using the function called
LLV = Lowest Low Value
It works fine in most cases, but it failed to work in those cases, when two or more lows are with same value.
I am giving the example below, when it works good and when its not
Example 1 (Working Good)
Left to Right
Low (6 Bar Back) 325
Low (5 Bar Back) 327
Low (4 Bar Back) 328
Low (3 Bar Back) 329
Low (2 Bar Back) 330
Low (1 Bar Back) 331
Low ((Current Bar) 332
Expected output : 6
Actual output : 6
Example 2 (Working Wrongly)
Left to Right
Low (6 Bar Back) 335
Low (5 Bar Back) 327
Low (4 Bar Back) 328
Low (3 Bar Back) 327
Low (2 Bar Back) 330
Low (1 Bar Back) 331
Low ((Current Bar) 332
Expected output : 3
Actual output : 5
The low of 327 which has been same in 5 bars back and also in 3 bars back.
LLV function takes into account, the 5 bars back value low (327) (Oldest Lowest Low, but bars since LATEST lowest low)
but the LATEST low is occurred in 3 bars back (low is same 327)
To resolve this, I tried to use the nested If else statement since there is no else if statement.
but for comparing custom variable, it doesn't supports and no output is not appearing
here is my codes, for the doing the above tasks
//For finding Lowest low for previous 6 bars
PCL6 = LLV(Ref(L,-1),6);
//Nested If else section
if (PCL6 == Ref(Low,0))
{
xyz=0;
}
else
{
if (PCL6 == Ref(Low,-1))
{ xyz=1;
}
else
{
if (PCL6 == Ref(Low,-2))
{ xyz=2;
}
else
{if (PCL6 == Ref(Low,-3))
{ xyz=3; }
else
{if (PCL6 == Ref(Low,-4))
{ xyz=4; }
else
{if (PCL6 == Ref(Low,-5))
{ xyz=5; }
else
{if (PCL6 == Ref(Low,-6))
{ xyz=6; }
}
}
}
}
}
}
Plot(xyz,"No of Bars Since Latest Lowest Low",colorTurquoise);
Please help me to resolve this problem.