Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 214

 
artmedia70:

I wrote an example WITHOUT your code. This is an example of where there are curly braces { } and where there are none... I wrote which lines will be executed and when. I just wanted you to understand how to organize logic in your code. YOU DON'T HAVE CURLY BRACES... So see in my example what happens in this case.

You don't need to guess!!!!!!!!!!!!!! Just try to understand...


Thank you very much. Tomorrow, with a clear head, I'll try to put things into perspective.
 

Good evening, could you tell me how to implement the following task?

There is an entry in a trade at certain conditions. then comes the share, but here is the problem, how to make the share do not open if the price is closer than a certain distance from the previous trade. If price is closer to the previous entry (it dont matter if it was the first or 5,10 etc) than 30 pips then the order should not open.

Thanks for the answers.

 
teplovoz:

Good evening, could you tell me how to implement the following task?

There is an entry in a trade at certain conditions. then comes the share, but here is the problem, how to make the share do not open if the price is closer than a certain distance from the previous trade. If price is closer to the previous entry (it dont matter if it was the first or 5,10 etc) than 30 pips then the order should not open.

Thank you for your replies.

Between the market and the closest position, i guess so.

Function

//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 19.02.2008                                                     |
//|  Описание : Возвращает расстояние в пунктах между рынком и ближайшей       |
//|             позицей                                                        |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    sy - наименование инструмента   ("" или NULL - текущий символ)          |
//|    op - торговая операция          (    -1      - любая позиция)           |
//|    mn - MagicNumber                (    -1      - любой магик)             |
//+----------------------------------------------------------------------------+
int DistMarketAndPos(string sy="", int op=-1, int mn=-1) {
  double d, p;
  int i, k=OrdersTotal(), r=1000000;

  if (sy=="" || sy=="0") sy=Symbol();
  p=MarketInfo(sy, MODE_POINT);
  if (p==0) if (StringFind(sy, "JPY")<0) p=0.0001; else p=0.01;
  for (i=0; i<k; i++) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
      if ((OrderSymbol()==sy) && (op<0 || OrderType()==op)) {
        if (mn<0 || OrderMagicNumber()==mn) {
          if (OrderType()==OP_BUY) {
            d=MathAbs(MarketInfo(sy, MODE_ASK)-OrderOpenPrice())/p;
            if (r>d) r=NormalizeDouble(d, 0);
          }
          if (OrderType()==OP_SELL) {
            d=MathAbs(OrderOpenPrice()-MarketInfo(sy, MODE_BID))/p;
            if (r>d) r=NormalizeDouble(d, 0);
          }
        }
      }
    }
  }
  return(r);
}

Call

if(DistMarketAndPos()>30)
   {
//открываемся
   }
 
r772ra:
between the market and the closest position, I guess so.

I understand the logic, how do I calculate the opening price of the last trade?
 
Addition above
 
I understand that the price is returned by OrderOpenPrice()
I understand that the order can be selected with the function OrderSelect(), but how do I select the latter?
 
r772ra:
Addendum above

didn't get it...
 
teplovoz:

I don't understand...


Understand what, exactly?

 
r772ra:


What exactly?


what do you mean by the addition above?

In general the meaning is :

if(Bid<=(N-30*Point) && another condition)

{

Open a sell order;

}

N is the open price of the last order - how do I know it?

 
teplovoz:


what does adding above mean?

The general idea is this :

if(Bid<=(N-30*Point) && one more condition)

{

Open a sell order;

}

N is the open price of the last order, so how do I know it?

More


This function returns the opening price of the last open position

 N = PriceOpenLastPos();
Reason: