I'm sorry if this is stupid question, but I'm new to coding.
Does the code I write in MQL4 is read by MT4 in the order i write code?
I`m asking this as I have 2 peaces of code contradicting one and another. But wondering if in this case the last code will be used over the first one?
Here is the code I'm laking about, its about function donefortheday, i need to turn this function to false at change of the day, but since I use donefortheday in previous function that return true for it, this doesn't seem to work for me?
Thanks for any help
//check if trade was closed by tp or sl
for(int pos=0; pos<OrdersHistoryTotal(); pos++) if(
//&& (OrderClosePrice()==OrderTakeProfit() || OrderClosePrice()==OrderStopLoss()))
//check if there is a new day
A quick answer to your first question is YES, the code is executed in the order it is written.
If(not_open) is true, the variable donefortheday = true.
Then, if(curday>prevday) is true, donefortheday = false.
So, basically, if both 'ifs ' hold, donefortheday will first become true and then false.
It looks to me that, as long as you have no opened orders, this will always happen because (curday > prevday) will always be true.
So you need a legitimate condition to execute donefortheday = false.
By 'legitimate condition' I mean a condition that can be made false.
I hope I could help,
But still cant find whats the problem with my code, it doesnt want to turn donefortheday=false after new day has started
Try replacing prevday = iTime(Symbol(),PERIOD_D1,0); with
prevday = iTime(NULL,PERIOD_D1,0);
Do the same for "curday".
Let me know how it goes.
To add comments, please log in or register