Can somebody please help me understand function use in below code in plain english?
what would be the value of P and how it will be used?
what is the meaning of TD_Supply(H) & TD_Demand(L)?
return ( P > Ref(P, 1) AND P > Ref(P, -1) AND P > Ref(C, -2));
return ( P < Ref(P, 1) AND P < Ref(P, -1) AND P < Ref(C, -2));
ShowTDP = ParamToggle("Show TD Pionts", "No|Yes", 1);
str = "";
PlotShapes(TD_Supply(H)*shapeSmallCircle, colorRed, 0, H, H*.001);
PlotShapes(TD_Demand(L)*shapeSmallCircle, colorGreen, 0, L, -L*.001);
Plot(C, "", IIf(C>O,colorGreen, colorRed), styleCandle);
The key is to understand the REF function:
function TD_Supply(P) is called like this (with parameter HIGH):
Therefore its body will become:
HIGH > Ref(HIGH, 1) AND HIGH > Ref(HIGH, -1) AND HIGH > Ref(C, -2)
a) HIGH > Ref(HIGH, 1) means current bar HIGH is higher than the NEXT bar HIGH (looks into the future).
b) HIGH > Ref(HIGH, -1) means current bar HIGH is higher than the PREVIOUS bar HIGH.
c) HIGH > Ref(C, -2) means current bar HIGH is higher than the CLOSE from 2 bars ago.
If conditions a, b and c are ALL TRUE, then function TD_Supply(P) will return TRUE.
Apply similar logic to function TD_Demand(P).
Thanks Bob for clear explanation!
Now i understand that P is just Variable that will be used to call H/L/C/O.
You are welcome.
Actually we call P a "parameter" (see https://en.wikipedia.org/wiki/Parameter_(computer_programming) ).
It does behave as a variable and you are right, its purpose is to take whatever value we give it.
So if we set
Then P will take the values of xx, ie (2*H+L)/MA(C, 15);
Sorry Bob, I have poor understanding on the Programming side & I am trying to learn it.
The Example that you have given about "xx" gave me more clarity how better we can use this and get the values that we desire.
You do need moderate programming skils to use AFL efficiently.