I am trying to lock in HH (Highest High) and LL (Lowest Low) based on the below loop. However when I print, it looks like both HH and LL are resetting to both Bid and Ask on every tick, and not "locking".
Of course it resets every tick. You do it in your code.
double HH = 0; double LL = 1000; if (Ask > HH) { HH = Ask; } if (Bid < LL) { LL = Bid; }
Maybe you should use a static variable and not reset it every tick.
Topics concerning MT4 and MQL4 have their own section.
In future please post in the correct section.
I have moved your topic to the MQL4 and Metatrader 4 section.
Hi Keith,
Thanks a lot for the reply.
The issue with a static variable from my reading of the docs is that the HH and LL will lock permanently, and this will cause a problem for subsequent / simulataneous orders - is that right? I wanted a way that HH and LL will reset after the trade has been closed (anywhere).
Also was looking at the forum to see if it was possible to hire a private teacher for MQL4 to get answers for questions I am spending too long to figure out myself when I get stuck? Any recommendations?
You simply reset the static variable when you want it reset.
Hiring a teacher could be expensive and any recommendations are not allowed in the forum.
Probably, every question that you may have has already been answered in the forum. You can learn a lot just by reading.
Is it possible to store the HH and LL of every ticket in an Array, and have the array reset for only open orders?
Is it possible to store the HH and LL of every ticket in an Array, and have the array reset for only open orders?
Is there any reason that you don't want to use a normal trailing stop and reset the actual SL for the order?
Is there any reason that you don't want to use a normal trailing stop and reset the actual SL for the order?
I dont want to send SL or TP to the broker, I would rather kep them invisible if possible
I dont want to send SL or TP to the broker, I would rather kep them invisible if possible
Well you already know how to do a 2 dimensional array.
Declare an array globally to store the ticket # and calculated SL.
Add to the array whenever you open a new trade.
Of course you will need to remove the trade from the array when the trade is closed.
I took this snippet of code from another EA -
I just wanted to clarify something that didnt make sense to me here
This is a declaration of a 2 dimensional array with 90 rows and 3 columns
int ordticket[90][2]
But here
ordticket[orders][0] = OrderOpenTime(); ordticket[orders][1] = OrderTicket();
The first column seems to be orders (since it appears first in the square brackets), AND OrderOpenTime() since OrederOpenTime() has an index of 0?
I took this snippet of code from another EA -
I just wanted to clarify something that didnt make sense to me here
This is a declaration of a 2 dimensional array with 90 rows and 3 columns
But here
The first column seems to be orders (since it appears first in the square brackets), AND OrderOpenTime() since OrederOpenTime() has an index of 0?
It is an array with the first dimension of 90 elements 0-89 and a second dimension of 2 elements 0-1
I took this snippet of code from another EA -
I just wanted to clarify something that didnt make sense to me here
This is a declaration of a 2 dimensional array with 90 rows and 3 columns
int ordticket[90][2]
But here
ordticket[orders][0] = OrderOpenTime(); ordticket[orders][1] = OrderTicket();
The first column seems to be orders (since it appears first in the square brackets), AND OrderOpenTime() since OrederOpenTime() has an index of 0?
[orders] is the index. orders is an int variable, it could just as easily be called index. But as this relates to orders in a list, it is called orders.
The array ordticket is declared with 90 indexes (0 to 89) and each index has 2 elements (0 and 1).
AS the array is an integer array it can also store datetime as it can be represented as an integer.
I don't know why you store the OrderOpenTime as you don't seem to use it in your code.
You probably want to declare a double array as you can store both the ticket number (as a double) and the stop loss. As you calculate any new value for the stop loss you can update the array.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
wondering whether someone may be able to point out what I'm doing wrong here.
Just for background I am very new to MQL4 (or coding at all)
I wrote the following code to act as a virtual trailing stop loss.
I am trying to lock in HH (Highest High) and LL (Lowest Low) based on the below loop. However when I print, it looks like both HH and LL are resetting to both Bid and Ask on every tick, and not "locking".
I had three questions:
(The ~ are just placeholders for now - can be ignored, I will correct that)
Thanks a lot!