Open trade based on the time

 

Hi guys,

I am new to MQL4 and interest to learn the language. I have think of a tutorial for myself, a simple but difficult for those who don't know the syntax.

I am trying to construct a code for a timebased trade. The idea is at below. Anyone can help me to define the function the properly? Thanks in advance.

(Please use MQL4 language because I don't have MQL5 developer install yet.) 

Constant: EnterTime

Variable: ActiveTime /*This is the network time*/

Extern Variable: Volume, TakeProfit, Stop Loss 

 

Set  EnterTime = 1500 server time

ActiveTime = Network time (this value is dynamic)

If ActiveTime == Entertime

 Opentrade = (Long/short, Volume, TakeProfit, StopLoss)

End If  

 
Beginner1111:

I am new to MQL4 and interest to learn the language. I have think of a tutorial for myself, a simple but difficult for those who don't know the syntax.

Constant: EnterTime

Set  EnterTime = 1500 server time

ActiveTime = Network time (this value is dynamic)

If ActiveTime == Entertime

 Opentrade = (Long/short, Volume, TakeProfit, StopLoss)


  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it.
    Even for your pseudo code.
  2. learn to code
  3. Create a script, the externs allow the Human to enter the values before launching. Once the order opens the script exits. (If you want an EA, then you don't want the while and sleep/refresh.)
  4. Can't use ActiveTime == Entertime because there may not be a tick that second.
    extern datetime EnterTime = 0;
    
    int start(){
       while(!IsStopped()){
          datetime ActiveTime = TimeCurrent();
          if(ActiveTime >= Entertime){
             int ticket = OrderSend(...
             if(ticket < 0) Alert(...
             break;
          }
          Sleep(1000); RefreshRates();
       } // while
    }  // start
Reason: