Find OrderOpenPrice closet to current Price-Level

 

Hi,


I need a function where I can find out the OrderTicket() or OrderOpenPrice() of the order, that is the most closet to the current price-level (e.g. price-level = (Ask+Bid/2) )

I'm currently creating a kind of Grid-Trader


thanks for any help or hint

 
So write an OrderSelect loop and find it. Show us your attempt (using the CODE button) and state the nature of your problem.
          No free help (2017)
Magic number only allows an EA to identify its trades from all others. Using OrdersTotal/OrdersHistoryTotal (MT4) or PositionsTotal (MT5), directly and/or no Magic number/symbol filtering on your OrderSelect / Position select 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 programming forum (2013)
          PositionClose is not working - MQL5 programming forum (2020.02.21)
          MagicNumber: "Magic" Identifier of the Order - MQL4 Articles (2006)
          Orders, Positions and Deals in MetaTrader 5 - MQL5 Articles (1 February 2011)

You need one Magic Number for each symbol/timeframe/strategy. Trade current timeframe, one strategy, and filter by symbol requires one MN.

 
Browse the order book, compute difference between current price an orders open price, save it in register if it is smaller as well as the ticket number. At the end of the loop the register will contains the data looked for.