Forex Factory (
-   Platform Tech (
-   -   Open Position Distance calculation (

MikeFT Jan 11, 2014 5:16am | Post# 1

Open Position Distance calculation
Hello Folks,

I'd like to have a code which looks if there already is an OpenOrder within let's say 10 pips distance from current price. If so: DistanceOK=false

I know I need to look, if there is something above and if so how close.
Then if there is something below and if so how close.

I'm stuck right now and don't really know where to start. My current code is a mess and not working, so I'll spare you the upload and myself the embarassment, unless somebody really wants to see it in this current state!

Best regards.

futurespec Jan 11, 2014 7:04am | Post# 2

Try something like...

Inserted Code
bool DistanceOK(int mMagic, string mSym)
   int m, mOrdTot;
   bool mNear = false;
   mOrdTot = OrdersTotal();
   for(m = mOrdTot - 1; m >= 0; m--)
      OrderSelect(m, SELECT_BY_POS, MODE_TRADES);
      if(OrderSymbol() == mSym && OrderMagicNumber() == mMagic && (OrderType() == OP_BUY || 
            OrderType() == OP_SELL)) 
          if(MathAbs(Bid - OrderOpenPrice()) < mDist &&
             MathAbs(OrderOpenPrice() - Bid < mDist))
            mNear = true;


where you set mDist as an external var to the figure that you want.



Edit: DistanceOK(...) would be better if it was titled DistanceNotOK(...) or change around the true & false above.

MikeFT Jan 11, 2014 7:49am | Post# 3

Thank you! This should get me going.

Yes, I'll be using DistanceOK and change the true&false.

© Forex Factory