how does this program ever come to market? what's wrong here?

 

extern double lots=0.1; 
int ticket=0; 
extern int stoploss=300; 
extern int takeprofit=500;
int aperto=0;
//+------------------------------------------------------------------+

int start()


double mc1 = iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,1);
double mc2 = iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_BASE,1); 
double mc01 = iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_MAIN,0); 
double mc02 = iMACD(NULL,0,12,26,9,PRICE_CLOSE,MODE_BASE,0); 



if( mc1<mc2 && mc01<mc02 &&aperto==0) 



ticket=OrderSend(Symbol(),OP_BUY,lots,Ask,3,Ask-stoploss*Point,Ask+takeprofit*Point,"compro",12345,0,clrAzure); 

}

if(OrderSelect(ticket,SELECT_BY_TICKET)==true && OrderCloseTime()>0)




{

aperto=0;

}


for(int cnt=0;cnt<OrdersTotal();cnt++)
      bool select=OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if (OrderType()==OP_BUY && mc01<mc02) 
bool ris =OrderClose(ticket,lots,Bid,clrAquamarine);

return(0);

}

 
  1. When you post code please use the SRC button! Please edit your post.
              General rules and best pratices of the Forum. - General - MQL5 programming forum

  2. ticket=OrderSend(Symbol(),OP_BUY,lots,Ask,3,Ask-stoploss*Point,Ask+takeprofit*Point,"compro",12345,0,clrAzure);
    You buy at the Ask and sell at the Bid.
    • Your buy order's TP/SL are triggered when the Bid reaches it. Not the Ask.
    • Your sell order's TP/SL will be triggered when the Ask reaches it. To trigger at a specific Bid price, add the average spread.
                MODE_SPREAD (Paul) - MQL4 and MetaTrader 4 - MQL4 programming forum - Page 3
    • The charts show Bid prices only. Turn on the Ask line to see how big the spread is (Tools -> Options {control-O} -> charts -> Show ask line.)

  3. Check your return codes for errors and report them.
              What are Function return values ? How do I use them ? - MQL4 and MetaTrader 4 - MQL4 programming forum
              Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles

  4. for(int cnt=0;cnt<OrdersTotal();cnt++)
          bool select=OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
    Using OrdersTotal directly and/or no Magic number filtering on your OrderSelect loop means your code is incompatible with every EA (including itself on other charts and manual trading.)
              Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 and MetaTrader 4 - MQL4 programming forum

  5. if( mc1<mc2 && mc01<mc02 &&aperto==0) ticket=OrderSend(..
    if (OrderType()==OP_BUY && mc01<mc02) bool ris =OrderClose(ticket,lots,Bid,clrAquamarine);
    It can only open when mc01<mc02 and it closes when mc01<mc02.
Reason: