Using Magicnumber to close orders....

 

Could anyone help me here? I want to search orders, find one with a certain magicnumber, then assess that order's close time to see if it is less than current time(the order has been closed), then delete an existing pending order with a different magicnumber. Can anyone code this for me? Please help!!!!! This is a great forum and I know someone can help me....I am only barely dangerous enough to mess with this coding stuff! :)

Daniel

 

> order's close time to see if it is less than current time(the order has been closed)

Just search through OrderHistory - because if its in history you know its closed :)
See one of CB's post for an example 'Need help with coding using history values'

 
forexman05:

Could anyone help me here? I want to search orders, find one with a certain magicnumber, then assess that order's close time to see if it is less than current time(the order has been closed), then delete an existing pending order with a different magicnumber. Can anyone code this for me? Please help!!!!! This is a great forum and I know someone can help me....I am only barely dangerous enough to mess with this coding stuff! :)

Daniel

I'm not sure I get exactly what you are trying to accomplish but there's no need to check order close time. If the order you are looking for is closed it will be stored in order history (MODE_HISTORY). You search for it this way:


bool found = false;
for(int k=OrdersHistoryTotal()-1;k>=0;k--)
{
      if((OrderSelect(k,SELECT_BY_POS,MODE_HISTORY))&&(OrderMagicNumber()==MagicNumber))
      {
         found = true;
         break;
      }
}

Then you search for your pending order in active trades (MODE_TRADES) and delete it like this:

if(found)
{
   for(k=OrdersTotal()-1;k>=0;k--)
   {
      if((OrderSelect(k,SELECT_BY_POS,MODE_TRADES))&&(OrderMagicNumber()==MagicNumber2))
      {
         OrderDelete(OrderTicket());
      }
   }
}


Hope this helps.

 
robofx.org wrote >>

I'm not sure I get exactly what you are trying to accomplish but there's no need to check order close time. If the order you are looking for is closed it will be stored in order history (MODE_HISTORY). You search for it this way:

Then you search for your pending order in active trades (MODE_TRADES) and delete it like this:

Hope this helps.

Yes, that is great! As far as the orderdelete, will it automatically delete the order in question(the one with Magicnumber2)? or do I need to specify somehow. THanks for the help!!!!! DAn

 
forexman05:

Yes, that is great! As far as the orderdelete, will it automatically delete the order in question(the one with Magicnumber2)? or do I need to specify somehow. THanks for the help!!!!! DAn

OrderDelete() will delete the oreder with MagicNumber2. You can replace it with the number you look for. You can also make additional checks to see the order type. Check how OrderType() works in documentation.

 
robofx.org wrote >>

OrderDelete() will delete the oreder with MagicNumber2. You can replace it with the number you look for. You can also make additional checks to see the order type. Check how OrderType() works in documentation.

THanks a ton! I think this is exactly what I needed....... Dan

Reason: