Custom indicator coding dilema
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--){
- 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
if(Hld!=0) Hlv=Hld; if(Hlv==1) ssl[i]= ...
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]);} |
| 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!
ssl[i]=iMA(Symbol(),0,Lb,0,MODE_SMA,PRICE_LOW,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.
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
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!