Close Order

To add comments, please log in or register
Sanbach21
38
Sanbach21  
 double MA1= iMA(NULL,0,MA_Fast,0,MODE_EMA,PRICE_CLOSE,0);
  
  
//-------------------------//
// if (Losses()<2)
//if ( Winner()<2)

if (OP_BUY==true)
{
if(Open[1]>MA1 && Close[1]<MA1)
        {
         
         !OrderClose(OrderTicket(),LotSize,Bid,3,White);
        }
 }
 
 if (OP_SELL==true)
 {
 if(Open[1]<MA1 && Close[1]>MA1)
        {
         !OrderClose(OrderTicket(),LotSize,Ask,3,White);
      
        }

 } 
  
  
   
   if(UseBreakEven)
   {
   BreakEven();
   }

   if(TotalOpenOrders()<1)
     {
      Entry_Signal();
     }
     
William Roeder
20061
William Roeder  
  1. Why did you post your MT4 question in the Root / MT5 General section instead of the MQL4 section, (bottom of the Root page?)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
    Next time post in the correct place. The moderators will likely move this thread there soon.

  2. True = non-zero, false = zero.
    if (OP_BUY==true)
    OP_BUY = zero. So you have if(false==true) which is never true.

    if (OP_SELL==true)
    OP_SELL is one. This is if(true==true) which is always true.

  3. You should be able to read your code out loud and have it make sense. You would never write if( (2+2 == 4) == true) would you? if(2+2 == 4) is sufficient. So don't write if(bool == true), just use if(bool) or if(!bool). Code becomes self documenting when you use meaningful variable names, like bool isLongEnabled where as Long_Entry sounds like a trigger price or a ticket number and "if long entry" is an incomplete sentence.

  4. !OrderClose(OrderTicket(),LotSize,Bid,3,White);
    You can not use any Trade Functions unless you select an order first.

  5. Check your return codes for errors, and report them including GLE/LE and your variable values. Don't look at GLE/LE unless you have an error. Don't just silence the compiler, it is trying to help you.
              What are Function return values ? How do I use them ? - MQL4 programming forum
              Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles

  6. Sanbach21:
    No question asked, no reply needed.
Sanbach21
38
Sanbach21  
William Roeder:
  1. Why did you post your MT4 question in the Root / MT5 General section instead of the MQL4 section, (bottom of the Root page?)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
    Next time post in the correct place. The moderators will likely move this thread there soon.

  2. True = non-zero, false = zero. OP_BUY = zero. So you have if(false==true) which is never true.

    OP_SELL is one. This is if(true==true) which is always true.

  3. You should be able to read your code out loud and have it make sense. You would never write if( (2+2 == 4) == true) would you? if(2+2 == 4) is sufficient. So don't write if(bool == true), just use if(bool) or if(!bool). Code becomes self documenting when you use meaningful variable names, like bool isLongEnabled where as Long_Entry sounds like a trigger price or a ticket number and "if long entry" is an incomplete sentence.

  4. You can not use any Trade Functions unless you select an order first.

  5. Check your return codes for errors, and report them including GLE/LE and your variable values. Don't look at GLE/LE unless you have an error. Don't just silence the compiler, it is trying to help you.
              What are Function return values ? How do I use them ? - MQL4 programming forum
              Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles

  6. No question asked, no reply needed.

Thanks William

In that moment my Keyboard stop to work, sorry

Thanks for your help ,!

Sanbach21
38
Sanbach21  
William Roeder:
  1. Why did you post your MT4 question in the Root / MT5 General section instead of the MQL4 section, (bottom of the Root page?)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
    Next time post in the correct place. The moderators will likely move this thread there soon.

  2. True = non-zero, false = zero. OP_BUY = zero. So you have if(false==true) which is never true.

    OP_SELL is one. This is if(true==true) which is always true.

  3. You should be able to read your code out loud and have it make sense. You would never write if( (2+2 == 4) == true) would you? if(2+2 == 4) is sufficient. So don't write if(bool == true), just use if(bool) or if(!bool). Code becomes self documenting when you use meaningful variable names, like bool isLongEnabled where as Long_Entry sounds like a trigger price or a ticket number and "if long entry" is an incomplete sentence.

  4. You can not use any Trade Functions unless you select an order first.

  5. Check your return codes for errors, and report them including GLE/LE and your variable values. Don't look at GLE/LE unless you have an error. Don't just silence the compiler, it is trying to help you.
              What are Function return values ? How do I use them ? - MQL4 programming forum
              Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles

  6. No question asked, no reply needed.

Hi William

I Build this Function But it don't works

void closeallopensells()
 {
    double MA1= iMA(NULL,0,MA_Fast,0,MODE_EMA,PRICE_CLOSE,0);
    
     if (Open[1]> MA1 && Close[1]<MA1)
     {
     if( OrderSelect( OrderTicket(), SELECT_BY_POS, MODE_TRADES))
     {
        if( OrderSymbol()== Symbol() && OrderType()== OP_SELL)
          {
           while( IsTradeContextBusy()) Sleep( 10); OrderClose( OrderTicket(), OrderLots(), Ask, 10, CLR_NONE);
             
               }
                 } 
                   }    
        }

 Thanks 

William Roeder
20061
William Roeder  
if( OrderSelect( OrderTicket(), SELECT_BY_POS, MODE_TRADES))
  1. What part of "You can not use any Trade Functions unless you select an order first." was unclear?
  2. A ticket is not a position.
Sanbach21
38
Sanbach21  

ok, then I have to use a For loop with order Total check open position on the pool ? 

Thanks 

To add comments, please log in or register