
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
Good friends.
This topic has already been asked before. https://www.mql5.com/en/forum/147558
But I seek a different answer.
I have spent a good few days on this, and now I finally seek your help.
Firstly, I am doing this task an exercise for myself to learn MQL4.
Secondly, the original code for that indicator is so elegant that I want to replicate most of it (and learn to code efficient code).
The original code is something called pine script:
study("Volatility Stop", shorttitle="VStop", overlay=true)
length = input(20)
mult = input(2)
atr_ = atr(length)
max1 = max(nz(max_[1]), close)
min1 = min(nz(min_[1]), close)
is_uptrend_prev = nz(is_uptrend[1], true)
stop = is_uptrend_prev ? max1 - mult * atr_ : min1 + mult * atr_
vstop_prev = nz(vstop[1])
vstop1 = is_uptrend_prev ? max(vstop_prev, stop) : min(vstop_prev, stop)
is_uptrend = close - vstop1 >= 0
is_trend_changed = is_uptrend != is_uptrend_prev
max_ = is_trend_changed ? close : max1
min_ = is_trend_changed ? close : min1
vstop = is_trend_changed ? is_uptrend ? max_ - mult * atr_ : min_ + mult * atr_ : vstop1
plot(vstop, color = is_uptrend ? green : red, style=cross, linewidth=2)
Although I understand the general lines, I do not understand all of it to every detail.
This is what I have so far, but it is obviously some (or a lot of!) logic errors here.
I am asking if anyone can help me with some pseudo-code or guide me in the right direction.
Should I perhaps have an additional array to store values in?
In the original code they access values of a parameter before declaring it. What should I there?
Thanks for any help!