Download MetaTrader 5

Close ID Long/Short. pending or, not

To add comments, please log in or register
GrumpyDuckMan
565
GrumpyDuckMan  

Hello everyone,

I think that I have looked at this before.

 void ShutDown_Order()
 {

   if(OrderSelect(0,SELECT_BY_POS)==true)
   
   bool Order_Closing=OrderClose(OrderTicket(),OrderLots(),Bid,0,clrRed);
   bool TradeClose = true;
   bool TradeOpen = false;
   Alert("Closing Order failed ",GetLastError());
}

OrderSelect() at this stage, is only located to a single position placed in market. Correct?

whroeder1
16835
whroeder1  
  1. if(OrderSelect(0,SELECT_BY_POS)==true)
    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
  2. 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.

  3. bool Order_Closing=OrderClose(OrderTicket(),OrderLots(),Bid,0,clrRed);
    Assumes a buy order. Substitute OrderClosePrice(). Why is slippage zero? don't you want to close even if price is off by pips?

  4. Alert("Closing Order failed ",GetLastError());
    You don't know that anything failed. 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
Mladen Rakic
68021
Mladen Rakic  
GrumpyDuckMan:

Hello everyone,

I think that I have looked at this before.

OrderSelect() at this stage, is only located to a single position placed in market. Correct?

No - to the first order in the list of orders when selected by position.

If you are lucky then it will be only one active order :)

GrumpyDuckMan
565
GrumpyDuckMan  
Mladen Rakic:

No - to the first order in the list of orders when selected by position.

If you are lucky then it will be only one active order :)

Hello again,

You understand this is really a test EA, not the real thing? I am still investigating problems within code.

nicholishen
1391
nicholishen  
GrumpyDuckMan:

Hello again,

You understand this is really a test EA, not the real thing? I am still investigating problems within code.


Even so - it's bad practice, and so is trying to track whether or not a trade is open with global variables. Just write (and use) a function to check. 

bool IsTradeOpen()
{
   for(int i=OrdersTotal()-1;i>=0;i--)
      if(OrderSelect(i,SELECT_BY_POS)&&OrderSymbol()==_Symbol&&OrderMagicNumber()==MAGIC&&OrderType()<2)
         return true;
   return false;
}
GrumpyDuckMan
565
GrumpyDuckMan  
nicholishen:

Even so - it's bad practice, and so is trying to track whether or not a trade is open with global variables. Just write (and use) a function to check. 

Hello again,

Thank you for the help with multi orders. At the moment I am only doing single trades until I feel comfortable to expand.

nicholishen
1391
nicholishen  
GrumpyDuckMan:

Hello again,

Thank you for the help with multi orders. At the moment I am only doing single trades until I feel comfortable to expand.

If you practice bad habits..............
To add comments, please log in or register