tenlau: I understand reading the code ssl takes values only when Hld!=0 So where am I wrong?
if(Hld!=0) Hlv=Hld; if(Hlv==1) ssl[i]= ...
The ssl[i] is set by Hlv not by the Hld and Hlv is never set to zero.for(int i=Bars-Lb;i>=0;i--){ if(Close[i]>iMA(Symbol(),0,Lb,0,MODE_SMA,PRICE_HIGH,i+1))
The iMA looks back Lb values [i+1 .. i+1+(LB-1)] so to avoid looking past the end the for should befor(int i=Bars-1-Lb;i>=0;i--){
WHRoeder:
What you said is clear for me. Let me put the question some other way. What happens when Hld is set to 0? From the code I understand that Hlv is set to 1 or -1 ONLY when Hld is NOT 0. So for Hld=0 there is no ssl[i] value (BECAUSE there is NO Hlv value). But if you look on a chart that has this indicator attached you will see that, for Hld=0, ssl[i]=ssl[i+1] (in words that is ssl takes its previous value). WHY is my question, how is this possible?
- The ssl[i] is set by Hlv not by the Hld and Hlv is never set to zero.
- The iMA looks back Lb values [i+1 .. i+1+(LB-1)] so to avoid looking past the end the for should be
tenlau: So for Hld=0 there is no ssl[i] value
Wrong. Hld does not set ssl, Hlv does.if(Hld!=0) Hlv=Hld; if(Hlv==1) ssl[i]= ...
WHRoeder:
Wrong. Hld does not set ssl, Hlv does.
Excuse me, maybe I'm stupid but I want to learn why am I so :). So I insist in other way:There are plenty situations when Hld is zero (from the first if() of the code). WHAT is the value of ssl[i] in this case and please explain WHY.
Wrong. Hld does not set ssl, Hlv does.
| So what if Hld is zero. The code set's ssl from the moving average according to Hlv. Your Print("Hld=1") may be wrong. Hld could be zero, but Hlv is not. Change your Print statements to output both variables. | if(Hlv==1) {ssl[i]=iMA(Symbol(),0,Lb,0,MODE_SMA,PRICE_LOW,i+1); Print("Hld=1 si ssl(i)=",ssl[i]);} else {ssl[i]=iMA(Symbol(),0,Lb,0,MODE_SMA,PRICE_HIGH,i+1); Print("Hld=-1 si ssl(i)=",ssl[i]);} |
WHRoeder:
| So what if Hld is zero. The code set's ssl from the moving average according to Hlv. Your Print("Hld=1") may be wrong. Hld could be zero, but Hlv is not. Change your Print statements to output both variables. |
I think i find myself the answer. Hlv is a global variable that is "keeping" its value over for() loop iteration, obviously if it is not changed by code (if(Hld!=0) Hlv=Hld;...). SO; WHEN Hld is 0 THE ACTUAL Hlv TAKES NO NEW VALUE IN THE ACTUAL LOOP (IT ACTUALY REMAINS WITH THE VALUE FROM THE PAST LOOP/LOOPS).
THAT IS THE REASON ssl[i]=ssl[i+1]Please confirm that I am right in my judgment!
tenlau: THAT IS THE REASON ssl[i]=ssl[i+1]
ssl[i] is never equal to ssl[i+1]. It is set by the moving average, it may be close but it will never be equal.
ssl[i]=iMA(Symbol(),0,Lb,0,MODE_SMA,PRICE_LOW,i+1)
WHRoeder:
ssl[i] is never equal to ssl[i+1]. It is set by the moving average, it may be close but it will never be equal.
ssl[i] is never equal to ssl[i+1]. It is set by the moving average, it may be close but it will never be equal.
Sorry, my mistake. By "ssl[i] = ssl[i+1]" I wanted to say that they take the same iMA calculation, I mean if ssl[i+1] was from PRICE_HIGH ssl[i] will also be from PRICE_HIGH. Same for PRICE_LOW. Because if Hld=0 Hlv[i]=Hlv[i+1] in the for() loop.
Now, am I right?
Yes
WHRoeder:
Yes
Happy that, at last, we find consensus :)
Yes
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hello, first a little introduction: I am newbie to mql4 and coding. I try to understand a simple well known custom indicator to be able to code my own one. But I can not understand it. So this is the code:
Now my dilema:
Running the code I saw that when Hld==0 the indicator plot the previous value. I mean ssl[i]=ssl[i+1].
But if I read the code I can not see where is this. In my opinion, as I understand the code, the value of ssl[i] when Hld==0 should be EMPTY_VALUE ie 2147483647 (0x7FFFFFFF) because as I understand reading the code ssl takes values only when Hld!=0
So where am I wrong?
Thanks in advance for all answers!