I have five HLine Objects and I would like to automatically select the one that is closest to the bid price. is it even possible?
//+------------------------------------------------------------------+ //| Script program start function | //+------------------------------------------------------------------+ void OnStart() { //--- long id=ChartID(); string name,minname; double diff,mindiff=SHORT_MAX,bid=SymbolInfoDouble(_Symbol,SYMBOL_BID),price=0,minprice=0; for(int i=0;i<ObjectsTotal(ChartID(),0,OBJ_HLINE);i++) { name=ObjectName(id,i,0,OBJ_HLINE); if((diff=MathAbs(bid-(price=ObjectGetDouble(id,name,OBJPROP_PRICE))))<mindiff) { mindiff=diff; minname=name; minprice=price; } } //--- Comment(minname," @ ",DoubleToString(minprice,_Digits)," is closest to ",DoubleToString(bid,_Digits)); } //+------------------------------------------------------------------+

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register