Open Order, only if existing is x pips away


Hello folks,

I have a simple script to open an order.

I'd like to add a safety which will prevent a new order to be placed, if another Order of the same type is within a certain distance.

Example in case of a Buy Order (I know this is not real code below, but this should explain what I'm looking for):

If price of any existing BuyOrder is less than x pips above/below Bid
   Alert("There is another position already too close");

Can anybody help me out here, please?

Thank you.


WorstCases:Can anybody help me out here, please?

Since there are no slaves here, you have only three choices: Search for it, learn to code it, or pay someone. We're not going to code it FOR you. We are willing to HELP you when you post your attempt and the nature of your problem.

Just a glimps of the main idea 

   bool DoNotTradeFlag = false;
   for(int k=OrdersHistoryTotal()-1;k>=0;k--)
         if(MathAbs(OrderOpenPrice() - Bid) < XPips*Point) DoNotTradeFlag = true;
   if(!DoNotTradeFlag) Trade .....

 Of course there is many more specific things in order to produce a stable code...


Thank you Cyberfx.

The "MathAbs" was what I needed and was not aware of.

WorstCases The "MathAbs" was what I needed and was not aware of.
In other words, you haven't been bothered to learn the Book, the Documentation, or the lessons.