Hi, I have a function called CheckOpenOrders() as below. What its supposed to do is to check whether the current Bid price matches any existing orders in a 50-pip window before I open an order. However, somehow it doesn't seem to work and the code ends up opening many orders regardless whether there are existing ones that have already been opened around the price level.
Is there something wrong with my logic or the way I'm using the APIs?
Hello, if you like my idea, you can use this function to check how pip by using Ask/Bid Mode
double TotalPips () { double totalpips,pips; totalpips=0; pips=0; for(int i=0;i<OrdersTotal();i++) { OrderSelect(i,SELECT_BY_POS,MODE_TRADES); if(OrderSymbol()!=Symbol()) continue; double point=MarketInfo(OrderSymbol(),MODE_POINT); if(OrderType()==OP_BUY) pips=(MarketInfo(OrderSymbol(),MODE_BID)-OrderOpenPrice())/point; if(OrderType()==OP_SELL) pips=(OrderOpenPrice()-MarketInfo(OrderSymbol(),MODE_ASK))/point; } return (pips); }so if my function which I share you, can be connected to your function, I think not impossible for you to use on your logic... Happy Coding brother
Hello, if you like my idea, you can use this function to check how pip by using Ask/Bid Mode
so if my function which I share you, can be connected to your function, I think not impossible for you to use on your logic... Happy Coding brother1 pip is 10 point only on a 5 digit broker. Code breaks on 4 digit brokers, exotics (e.g. USDZAR where spread is over 500 points,) and metals. Compute what a PIP is and use it, not points.
1 pip is 10 point only on a 5 digit broker. Code breaks on 4 digit brokers, exotics (e.g. USDZAR where spread is over 500 points,) and metals. Compute what a PIP is and use it, not points.
Thanks for the tip whroeder1! Though, would be great if there's anything at all you would be able to advise on my original question :)
Thanks for the tip whroeder1! Though, would be great if there's anything at all you would be able to advise on my original question :)
This is for the forex majors, not CFD and exotics. (although it would work on most)
//+------------------------------------------------------------------+ //| 50pipWindow.mq4 | //| nicholishen | //| www.reddit.com/u/nicholishenFX | //+------------------------------------------------------------------+ #property copyright "nicholishen" #property link "www.reddit.com/u/nicholishenFX" #property version "1.00" #property strict input int Magic = 0; //+------------------------------------------------------------------+ //| Script program start function | //+------------------------------------------------------------------+ void OnStart() { //--- string yes = "The Bid is currently in the pip window. No trades will be placed."; string no = "The Bid is NOT in the window, ok to place trades."; Print(IsBidInPipWindow(50) ? yes : no); } //+------------------------------------------------------------------+ bool IsBidInPipWindow(const double num_pips_in_window) { double pip= _Digits==3 || _Digits==5 ? _Point * 10 : _Point; for(int i=0;i<OrdersTotal();i++) if(OrderSelect(i,SELECT_BY_POS)&&(Magic==0||OrderMagicNumber()==Magic)&&OrderSymbol()==Symbol()) if(NormalizeDouble(MathAbs(OrderOpenPrice()-Bid)/pip,1) <= num_pips_in_window) return true; return false; }
Works great, thanks @nicholishen!!

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi, I have a function called CheckOpenOrders() as below. What its supposed to do is to check whether the current Bid price matches any existing orders in a 50-pip window before I open an order. However, somehow it doesn't seem to work and the code ends up opening many orders regardless whether there are existing ones that have already been opened around the price level.
Is there something wrong with my logic or the way I'm using the APIs?