what the problem in this expert

 

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);
  
   
  }
 
  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()

 

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

3.stop lose and take profit

4profit order open

 
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.
 
so haw can i open a simple order please
 
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.
 
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
 
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
 
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.
 
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

Reason: