Does MQL4 code runs in the seqance i write code?

 

Hi,

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

Ivo 

//check if trade was closed by tp or sl
   if(not_open)
     {
      for(int pos=0; pos<OrdersHistoryTotal(); pos++) if(
         OrderSelect(pos,SELECT_BY_POS,MODE_HISTORY)
         && OrderCloseTime()>lastClose
         && OrderMagicNumber()==mn
         && OrderSymbol()==Symbol())
         //&& (OrderClosePrice()==OrderTakeProfit() || OrderClosePrice()==OrderStopLoss()))
           {//
            donefortheday=true;
            lastClose=OrderCloseTime();
           }
        }
//check if there is a new day

 curday=iTime(Symbol(),PERIOD_D1,0);
      if(curday>prevday)
        {
         prevday=iTime(Symbol(),PERIOD_D1,0);
         donefortheday=false;
         skip_sig=0;
         Last_Opensignal_High=-9999999; Last_Opensignal_low=99999;
         first=true;
         NewTP_BUY=9999;
         NewTP_SELL=0;
        }
 

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, 

Cheers 

 
Thaddeus_39:

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, 

Cheers 

Thanks man.

But still cant find whats the problem with my code, it doesnt want to turn donefortheday=false after new day has started 

 
ivolux:

Thanks man.

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.

Cheers 

 
ivolux: But still cant find whats the problem with my code, it doesnt want to turn donefortheday=false after new day has started 
Thaddeus_39: Try replacing prevday = iTime(Symbol(),PERIOD_D1,0); with prevday = iTime(NULL,PERIOD_D1,0);
  1. Print your variables before and inside your ifs and find out why.
  2. They are identical, irrelevant.
Reason: