Basic Code Syntax

 
Hello all.

I am trying to develop a basic MQL expert advisor for fully automated trading. I have looked around and haven't found very many tutorials on how to write EAs. Below I have attempted to write a simple EA, but am not sure about the syntax.

int ilots = 100
 
//open position
//if no other postions are on
if(OpenOrders < 1) {
    //if it is monday through friday
    if(DayOfWeek()!=0 & if(DayOfWeek()!=6) {
          //if the market is open
        ?????? {
            //if the spread is small
            if ask - bid < 3 pips {
                //if volatility has been high enough over the last M minutes (if high – low of last half hour > 10 pips)
                if high(PERIOD_M30) - low(PERIOD_M30) > 10 pips { 
                    //current price is 8 pips higher than open 10 minutes ago
                    if (((Ask-Bid)/2)+Bid) > open(PERIOD_M10) + 10 pips) 
                        //then buy
ticket=OrderSend(Symbol(),OP_BUY,ilots,Ask,3,sl,tp,NULL,0,0,Green);
                        return(0);
                    //else if current price is 8 pips higher than open 10 minutes ago
                    if (((Ask-Bid)/2)+Bid) < (open(PERIOD_M10) - 10 pips)
                        //then sell
                        ticket=OrderSend(Symbol(),OP_SELL,ilots,Bid,3,sl,tp,NULL,0,0,RED);
                        return(0);
                    }
                }
            }
        }
    }
}
 
//close position
//if position is on
if(OpenOrders > 0) {
    //then if position loses [3-10] pips
    //I have used the average of bid and ask to adjust for times when the spread may jump
    if ((OrderOpenPrice() - ((Ask-Bid)/2)+Bid) > 3 pips {
        //then close position
        OrderClose(order_id,1,Ask,3,Red);
             return(0);
    }
    if (((Ask-Bid)/2)+Bid) - (OrderOpenPrice()) > 20 pips {
        //then close position
        OrderClose(order_id,1,Ask,3,Red);
             return(0);
    }
}
 
Dear Ryan,
I suggest you start here which will help you avoid basic mistakes like & instead of && and not putting your conditions into brackets and will walk you towards more complex stuff. Begin with basic programs, write your code in the MetaEditor and learn from the mistakes it shows you in the debugger log. Good luck.
Reason: