Order info by Symbol

 
Anyone know of a way to call up order info by symbol? I don't need to call up an exact order just any order with a certain symbol to check the takeprofit point.
 
Tony Chavez: Anyone know of a way to call up order info by symbol? I don't need to call up an exact order just any order with a certain symbol to check the takeprofit point.

I am assuming you want a solution in coding and in that case, just cycle through all the orders until OrderSymbol() matches.

Please read the documentation and learn MQL coding first, since it is obvious you have very little knowledge and experience with it. Alternatively, hire someone at the Freelance section to code it for you.

OrderSymbol - Trade Functions - MQL4 Reference
OrderSymbol - Trade Functions - MQL4 Reference
  • docs.mql4.com
OrderSymbol - Trade Functions - MQL4 Reference
 
Fernando Carreiro:

I am assuming you want a solution in coding and in that case, just cycle through all the orders until OrderSymbol() matches.

Please read the documentation and learn MQL coding first, since it is obvious you have very little knowledge and experience with it. Alternatively, hire someone at the Freelance section to code it for you.

//////You think this would work?

for(int 2_pos_5=OrdersTotal()-1; 2_pos_5>=0; 2_pos_5--)
     {
      OrderSelect(2_pos_5,SELECT_BY_POS,MODE_TRADES);
      if(OrderSymbol() != Symbol()) continue;
      if(OrderSymbol() == Symbol())
         if(OrderType() == OP_BUY)
           BuyTP = OrderTakeProfit();
     }

Sorry I wasn't looking for a handout just advise.

 
Tony Chavez:
//////You think this would work?

for(int 2_pos_5=OrdersTotal()-1; 2_pos_5>=0; 2_pos_5--)
     {
      OrderSelect(2_pos_5,SELECT_BY_POS,MODE_TRADES);
      if(OrderSymbol() != Symbol()) continue;
      if(OrderSymbol() == Symbol())
         if(OrderType() == OP_BUY)
           BuyTP = OrderTakeProfit();
     }

Sorry I wasn't looking for a handout just advise.

Did you try it and did it do what you wanted? Did it even compile?

  • Don't start variable names with numbers!
  • Check your function return values
  • Learn proper code logic
  • Use a Magic number to differentiate your orders from other EA's
// Please note that this will cycle through ALL the orders
// and update your BuyTP and SellTP multiple times

for(int pos = OrdersTotal() - 1; pos >= 0; pos-- )
{
   if( OrderSelect( pos, SELECT_BY_POS, MODE_TRADES ) )
   {
      if( ( OrderMagicNumber() == myMagic ) &&
          ( OrderSymbol()      == _Symbol )    )
      {
         switch( OrderType() )
         {
            case OP_BUY:
               BuyTP  = OrderTakeProfit();
               break;
              
            case OP_SELL:
               SellTP = OrderTakeProfit();
               break;
         }
      }
   }
}


 
Fernando Carreiro:

Did you try it and did it do what you wanted? Did it even compile?

  • Don't start variable names with numbers!
  • Check your function return values
  • Learn proper code logic
  • Use a Magic number to differentiate your orders from other EA's
// Please note that this will cycle through ALL the orders
// and update your BuyTP and SellTP multiple times

for(int pos = OrdersTotal() - 1; pos >= 0; pos-- )
{
   if( OrderSelect( pos, SELECT_BY_POS, MODE_TRADES ) )
   {
      if( ( OrderMagicNumber() == myMagic ) &&
          ( OrderSymbol()      == _Symbol )    )
      {
         switch( OrderType() )
         {
            case OP_BUY:
               BuyTP  = OrderTakeProfit();
               break;
              
            case OP_SELL:
               SellTP = OrderTakeProfit();
               break;
         }
      }
   }
}


I am going to have to read more because neither the way I had it setup or the way you have it gets OrderTakeProfit to give a value to the variables.

 
Tony Chavez: I am going to have to read more because neither the way I had it setup or the way you have it gets OrderTakeProfit to give a value to the variables.

Then show your full code. A code snippet is only as good as the how it is implemented and where it is placed in the overall code structure.

In this case it should be placed somewhere in the OnTick() event handling sequence.

If you show your full code we can verify if it is used correctly or if there are other problems you are not aware of.

PS! Also, please don't write inside the quoted text!

 
for(pos = pos - 1; pos >= 0; pos-- )
{
   if( OrderSelect( pos, SELECT_BY_POS, MODE_TRADES ) )
   {
      if(   ( OrderSymbol()      == _Symbol )    )
      {
         switch( OrderType() )
         {
            case OP_BUY:
               BuyTP  = OrderTakeProfit();
               break;
              
            case OP_SELL:
               SellTP = OrderTakeProfit();              
               break;
         }
      }
   }
}
    
     if(BuyTP > Ask+.05){    
    
     } else {
    
     BuyTP = Ask + 0.05;
    
     }
    
//////////////////// Check buy take profit level ///////////////////////////////
    
     if(SellTP < Bid - 0.05){    
    
     } else {
    
     SellTP = Bid - 0.05;
    
     }
I figured out the issue somewhat now I just have the issue of that only the BuyTP gets populated SellTP does not. The reason neither were populating was due to me having another OrdersTotal loop running before this one once I commented it out this one runs and populates the BuyTP.
 
This would be so much easier and not needed if the system was designed to let you set different TP for every order even if you currently have an open order for that pair.
 
Fernando Carreiro: PS! Also, please don't write inside the quoted text!
Don't add text inside quoted text, put it outside. MQL4 Forum editor problem - MQL4 forum
 
whroeder1:

Don't add text inside quoted text, put it outside. MQL4 Forum editor problem - MQL4 forum

@whroeder1: F.Y.I., even if your comments are directed at the OP, every time you reply to one one of my posts, I'm the one that gets notified (via the Mobile app) instead of the OP.

So, it might be best if you reply to one of the OP's posts and then add your comments according, so that he is the one that gets notified of your reply instead of me.

 
News to me, I don't have notifications. Wilco.
Reason: