what the problem in this expert

Back to topics list To post a new topic, please log in or register
avatar
39
ayoub 2015.07.27 21:42
 

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);
  
   
  }
avatar
12983
WHRoeder 2015.07.28 02:53 #
 
  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()

avatar
39
ayoub 2015.07.28 18:49 #
 

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

3.stop lose and take profit

4profit order open


avatar
12983
WHRoeder 2015.07.28 19:43 #
 
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.
avatar
39
ayoub 2015.07.28 21:55 #
 
so haw can i open a simple order please
avatar
12983
WHRoeder 2015.07.28 22:20 #
 
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.
avatar
Moderator
3404
GumRai 2015.07.28 22:40 #
 
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
avatar
39
ayoub 2015.07.29 14:46 #
 
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
avatar
12983
WHRoeder 2015.07.29 15:09 #
 
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.

avatar
Moderator
3404
GumRai 2015.07.29 21:30 #
 
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

Back to topics list  

To add comments, please log in or register