Hi Guys,
I am trying to write some code to find the time (index) when the last two low Fractals occurred, or the last two High Fractals occurred.
I want to use their positional information to calculate Fractal divergence against an indicator.
I am struggling as the normal Fractal code uses the “lowest” function which works for the last Fractal, but does not allow an offset to find the 2nd to last Fractal.
Any help much appreciated.
B.
You can make a new variable that store the previous high fractal barindex if a new high one is found. This way, you should be able to compare the current fractal barindex to the previous one stored in a variable.
Thanks Nicolas,
I am having trouble with how to store the previous Fractal, in the code snippet (just the low Fractal):
cp = 2 //(default)
PreviousLF = -1
if low[cp] <= lowest[2*cp+1](low) then
CurrentLF = barindex
else
CurrentLF = -1
endif
I don’t know how/when to save the CurrentLF to PreviousLF
Cheers
You could do it this way instead:
cp = 2 //(default)
if low[cp] <= lowest[2*cp+1](low) then
PreviousLF = CurrentLF
CurrentLF = barindex
endif
So now you have continuously a set of 2 low fractals barindex stored.
Thanks Nicolas, wasn’t thinking 😉
Hi im trying to find the values of the previous THREE factals. Having trouble.
cp = 20
if high[cp] >= highest[2*cp+1](high) then
pprevioushf = PrevioushF
PrevioushF = CurrentHF
CurrentHF = barindex
endif
if low[cp] <= lowest[2*cp+1](low) then
ppreviouslf = PreviousLF
PreviousLF = CurrentLF
CurrentLF = barindex
endif
TOPy = high[currenthf]
TOPy1 = high[previoushF]
TOPy2 = high[pprevioushF]
BOTy = low[currentLF]
BOTy1 = low[previousLF]
BOTy2 = low[ppreviouslf
Can somebody help me?
This Nicolas’code modified to accomodate for another two places:
if low[cp] <= lowest[2*cp+1](low) then
Previous3LF = Previous2LF
Previous2LF = Previous1LF
Previous1LF = CurrentLF
CurrentLF = barindex
endif
so you can now access Previous1LF, Previous2LF and Previous3LF.
Thankyou for your reply.
If i want to find the value(high or low) of a previous factal such as ‘previous3LF’, is this code correct?
Top3 = high[previous3LF]
No, you should write:
Top3 = high[BarIndex - previous3LF]
Because if now it’s BarIndex 100 and previous3LF is 81, then you have to access the 19th previous bar to get the correct value.