[ARCHIVE!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Can't go anywhere without you - 4. - page 2

 
tara:
How about two?
Then the names are alphabetical.
 
     // Проверяем все открытые ордера---------------------------------------------------------------------------

    for(n=0,i=0;i<OrdersTotal();i++)
   {
      OrderSelect(i,SELECT_BY_POS);
      if(OrderSymbol()!=Symbol() || OrderMagicNumber()<MAGIC+1 || OrderMagicNumber()>MAGIC+3) continue;
      no=OrderMagicNumber()-MAGIC;
      
      if(no==1)
      {
         n++;
         if(OrderType()==OP_SELL) { if(OrderOpenTime()>=ltts && BSo1==OP_SELL) s1=true; 
         if(MathAbs((OrderOpenPrice()-NormalizeDouble(Bid,Digits))/Point)<Add){OS1=1;} // Запрет на открытие селл

            } else
         if(OrderType()==OP_BUY) { if(OrderOpenTime()>=lttb && BSo==OP_BUY) b1=true;
         if(MathAbs(OrderOpenPrice()-NormalizeDouble(Ask,Digits))/Point<Add){OB1=1;} // Запрет на открытие бай
         }     
      }
   }
Good afternoon.
Task is to open an order at a certain distance "Add" from an already open order.
Separate buy and sell orders are controlled.
I have written this code. It seems to be working, but sometimes the price covers a longer distance than the "Add" but the order is not opened.
I have tried prints but "Add" condition does not work correctly and I do not know what is wrong.
Maybe someone will tell me what to do?
 

Dear Sirs, I've been puzzled with a solution to a problem related to requotes.

Situation: Expert Advisor opens orders from the market with hard stops and takeovers in pips, works on a closed bar, M15. A signal to open the order is received and the Expert Advisor tries to open the order several times but it fails. On the next bar the signal repeats and the Expert Advisor opens the deal, but the rate has left the point where the first signal was given. It turns out that the stop and take will be set from the rate at which the deal was opened, rather than from the rate at which the first signal to open. I have written such a construction that when setting a stop and take, the Expert Advisor would take the price at which the first signal was received.

  if(sg==1 && TimeCurrent()-buy_time>=1800) {buy_price=Ask;buy_time=TimeCurrent();}//
  if(sg==-1 && TimeCurrent()-sell_time>=1800) {sell_price=Bid;sell_time=TimeCurrent();}//
где,
sg==1 сигнал на покупку
sg==-1 сигнал на продажу
buy_time - переменная в которую запоминаем время поступления сигнала на покупку
sell_time - переменная в которую запоминаем время поступления сигнала на продажу

при выставлении ордера стоп и тейк прибавляем/вычитаем не от текущей цены а от buy_price и sell_price

I want to explain why I want to use the first signal: stop and take sizes were selected in the tester and are sort of optimal, if you set stops/stops from the second signal, it will turn out that they are not optimal, because the rate of actual deal opening is different from the rate at the first signal.

 
evillive:

Trades in orders total 1, i.e. we never reach the oldest one. Second, it trawls orders from the most recent to the oldest, and older ones may be closed using stop or take before the trawler reaches it. In general, what is wrong, do you have error logs?


TS does not work at all, several times I noticed that "as designed" it does not close positions at all.No error logs, but how do I get them?

And as for closing orders, could you please write more details, as the EA is multi-currency, but with a limit of 1 trade on a currency at a time.

 
Stells:
Good afternoon.
Task is to open an order at a certain distance "Add" from an already open order.
Separate buy and sell orders are controlled.
I have written this code. It seems to be working, but sometimes the price covers a longer distance than the "Add" but the order is not opened.
I have tried printers but "Add" condition does not work correctly and I do not know what is wrong.
Maybe someone will tell me what to do?


Igor Kim's features, simply and conveniently.

//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |7
//+----------------------------------------------------------------------------+
//|  Версия   : 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);
}
 
Sancho77:

Dear Sirs, I've been puzzled with a solution to a problem related to requotes.

Situation: Expert Advisor opens orders from the market with hard stops and takeovers in pips, works on a closed bar, M15. A signal to open the order is received and the Expert Advisor tries to open the order several times but it fails. On the next bar the signal repeats and the Expert Advisor opens the deal, but the rate has left the point where the first signal was given. It turns out that the stop and take will be set from the rate at which the deal was opened, rather than from the rate at which the first signal to open. I have written such a construction that when setting a stop and take, the Expert Advisor would take the price at which the first signal was received.

I want to explain why I want to use the first signal: stop and take sizes were selected in the tester and are sort of optimal, if you set stops/stops from the second signal, it will turn out that they are not optimal, because the rate of actual deal opening is different from the rate at the first signal.

It turns out that the optimality is determined only by tp and sl levels, while the deal price can be any? That doesn't seem logical.
 
alsu:
It turns out that the optimality is determined only by tp and sl levels, while the deal price may be any? This doesn't seem logical.

Optimality is determined not only by a stop and take, it is mainly determined by the parameters of the signal to open the deal, I have not given these signals so as not to overload my question, signal parameters in fact do not relate to the problem in question. The deal price may be any, if the signal to open the deal is saved.

I would be grateful if you could give your opinion on the essence of my question, i.e. whether the code for calculation of levels from which a stop and take will be calculated is written correctly?

 
Sancho77:

I don't have the code handy, but I did something similar for myself, but not like that: I remembered the time of the bar at which there was a signal, and when an order was placed using this signal, I reset the signal time to zero, so on and so forth:

datetime buy_time,sell_time;
int init(){
   buy_time = 0;
   sell_time = 0;
}
int start(){
   if(buy_time==0 && Open[1]>Close[2]) buy_time = TimeCurrent();
   .......
   if(buy_time!=0){
      OrderSend(.........);
      buy_time = 0;
   }
return(0);
}
Well, if the question is about fighting only requotes, then look in Igor Kim's thread, almost all functions for placing orders have a parameter for how many times to try to place the order
 
Sancho77:

Optimality is determined not only by a stop and take, it is mainly determined by the parameters of the signal to open a deal, I have not given these signals so as not to overload my question, signal parameters in fact do not relate to the problem in question. The deal price may be any, if the signal to open the deal is saved.

I will be grateful if you tell opinion on essence of my question, i.e. whether the code, for calculation of levels from which stop and take will be calculated correctly is written?

Yes, it is written correctly but just imagine the situation: the "real" price of the deal turned out, for example, above the memorized TP - what will you do then? (and this situation is quite real - requotes are just frequent in the fast market, when the price jumps)
 
alsu:
The writing is correct but imagine the situation: the "real" price of the deal turned out to be, for example, above the memorized TP - what will you do then? (And this situation is quite real - requotes are just frequent in the fast market, when the price jumps)

Thank you for your opinion.

If the price turns out to be higher than the memorized TP then the trade will open with the minimum takeaway level, such processing is inherent in the EA.

PS By the way, I will have to try to put a position opening ban if the new price went away from the memorized price at more than a certain distance, thanks for the thought, I wish I could check it in the tester, only in trade.

Reason: