Download MetaTrader 5

what the problem in this expert

To add comments, please log in or register
ayoublaser
99
ayoublaser  

hi,

i build this expert but it can't place orders ,Is there a mistake



void OnTick()
  {

  double vpoint  = MarketInfo("EURUSD",MODE_POINT);
  double SL=50*vpoint;
  double TP=100*vpoint;
 int total=OrdersTotal();

  for(int pos=0;pos<total;pos++)
 
  if(OrderSelect(pos,SELECT_BY_POS,MODE_TRADES))
  OrderProfit();
  int ticket=OrderSend(Symbol(),OP_BUY,1,Ask,3,SL,TP,"op buy/1",123,0,clrBlue);
  double a=OrderProfit();
  Comment("profit order select",a);
  
   
  }
whroeder1
14779
whroeder1  
  1. What do you think this line does?
    for(int pos=0;pos<total;pos++) if(OrderSelect(pos,SELECT_BY_POS,MODE_TRADES)) OrderProfit();

  2. Check your return codes (OrderSend) and find out why. What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
  3. What price are you setting your SL/TP to?
  4. Which order do you think a refers to?
    double a=OrderProfit()

ayoublaser
99
ayoublaser  

1.if not order, open a just one new order

3.stop lose and take profit

4profit order open

whroeder1
14779
whroeder1  
ayoub:

1.if not order, open a just one new order

3.stop lose and take profit

4profit order open

  1. The line does nothing. It doesn't check for anything.
  2. Ignored
  3. SL=50*vpoint is not a price
  4. If there is only one open order (from the send,) there is no selected order. If there are two open orders, it is the previous one.
ayoublaser
99
ayoublaser  
so haw can i open a simple order please
whroeder1
14779
whroeder1  
You won't answer any question so you won't learn. learn to code it, or pay someone. We're not going to code it FOR you. We are willing to HELP you when you post your attempt (using SRC) and the nature of your problem.
Keith Watford
Moderator
9641
Keith Watford  
ayoub:
so haw can i open a simple order please
  Check if an order is already open
  if Yes
     {
     Do nothing
     }
  if No
     {
     Do I want to open a Buy or a Sell
     if Buy
        {
        Caculate SL at Ask minus SL amount
        Caculate TP at Ask plus TP amount
        Send Buy order at Ask, with calculated SL and TP
        Check if OrderSend was successful, if not print an error report
        }
     if Sell
        {
        Caculate SL at Bid plus SL amount
        Caculate TP at Bid minus TP amount
        Send Sell order at Bid, with calculated SL and TP
        Check if OrderSend was successful, if not print an error report
        }
     
     }
Write code to do exactly what you would do if opening a trade manually
ayoublaser
99
ayoublaser  
GumRai:
Write code to do exactly what you would do if opening a trade manually
I want just to know why it not open order when i use the previous code
what the error code or code forget
whroeder1
14779
whroeder1  
ayoub: I want just to know why it not open order when i use the previous code
If you had answered my questions, you would know why.
Keith Watford
Moderator
9641
Keith Watford  
ayoub:
I want just to know why it not open order when i use the previous code
what the error code or code forget

WHRoeder has already pointed you in the right direction and in my post

     Do I want to open a Buy or a Sell
     if Buy
        {
        Caculate SL at Ask minus SL amount
        Caculate TP at Ask plus TP amount
        Send Buy order at Ask, with calculated SL and TP
        Check if OrderSend was successful, if not print an error report
        }
     if Sell
        {
        Caculate SL at Bid plus SL amount
        Caculate TP at Bid minus TP amount
        Send Sell order at Bid, with calculated SL and TP
        Check if OrderSend was successful, if not print an error report
        }

 Calculate your SL and TP properly

To add comments, please log in or register