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

 
hoz:

Vadim, I would do it the way you've described! That's why I asked you a question. I thought, maybe I haven't taken something into account. I'm still observing my own logic and the logic of other programmers. Because in addition to the basic logic, I see that I need to take into account a number of factors.

RefreshRates() updates history in expert thread. MarketInfo() takes data from server. There is no need to refresh it. It is an unnecessary brake.

If it must be updated, a simple call of RefreshRates() will not give anything. We must somehow control and handle the event of the whole history arrival.

 
Hi, how do I use metaeditor?
 
crespo1985:
hello how to use metaeditor?


Well hello! Use it however you like! This is not your place to ask questions like that... This is a programmer's forum...

Zhunko:

RefreshRates() updates history in Expert Advisor's thread. MarketInfo() takes data from the server. It does not need to be updated. It is unnecessary braking.

If it must be updated, a simple call of RefreshRates() cannot do anything. We must control and handle all history event somehow.

Yes. I understand that RefreshRates() refreshes market data (their history to the current time) and then market environment variable uses the last received value. As far as I understand, this is the only logical variant. Therefore, this function is written easier and faster, and more logical and practical, and more reliable, isn't it?

double fGet_TradePrice(int fi_price,    // Цена: 0 - Bid; 1 - Ask
                       string fs_symbol)   // валютная пара
{
   double ld_price = 0.0;
   
   switch (fi_price)
   {
         case 0:
         if (fs_symbol == Symbol())
         {
             RefreshRates();
             ld_price = Bid;
         }
         else
             ld_price = MarketInfo(fs_symbol, MODE_BID);
         
         case 1:
         if (fs_symbol == Symbol())
         {
             RefreshRates();
             ld_price = Ask;
         }
         else
             ld_price = MarketInfo(fs_symbol, MODE_ASK);
   }
}
 
hoz:

Yes. I understand that RefreshRates() updates market data (its history to the current time), and then the market environment variable uses the last received value. As far as I understand, this is the only logical variant. Therefore, this function would be written easier and faster and more logical, more practical and reliable, right?

I would go like this:

double TradePrice(int    nPriceId, // Цена: 0 - Bid; 1 - Ask
                  string sSymbol)  // валютная пара
 {
  switch (nPriceId)
   {
    case 0: return(MarketInfo(sSymbol, MODE_BID));
    case 1: return(MarketInfo(sSymbol, MODE_ASK));
    default: Print("Ошибка и прочее...");
   }
  return(0);
 }

A separate function should be written to update the history.

 

2 hours trying to write a test piece, to further test different conditions.

Doesn't work!

Please give me the error.

int mm;


if (mm==0) { B=Bid; mm=1;} 

OrderSelect(0,SELECT_BY_POS,MODE_TRADES); 

if ( (Bid> B+0.0002 ) && (OrdersTotal()==0 || OrderType()==OP_SELL) ) { My_close(); My_buy (); My_modify(); }  

if ( (Bid< B-0.0002 ) && (OrdersTotal()==0 || OrderType()==OP_BUY ) ) {My_close(); My_sell (); My_modify(); }
  

the point is that orders open after 2pp in their own direction.

opens sell and ends...

 

Good afternoon! Forgive the triviality. The lines are from a robot, I've had the robot for years and basically a cycle of this kind invariably wanders from one to the other.

 for(int i=OrdersTotal()-1;i>=0;i--) 
      {  if(OrderSelect(i,SELECT_BY_POS)&&OrderSymbol()==Symbol()&&OrderMagicNumber()==magic)

Why is my order total minus one? Is it true that the loop is going for a decrease in the variable and?

 

Kim's function has the time parameter ="Date and time in seconds since 1970"

I tried 2 variants.

and both give a profit not for the current day, but a full profit over the whole history....

int t=(     TimeCurrent()-( (Hour()*3600) +(Minute()*60)+Seconds()   ) ); 
int t=(    (Hour()*3600) +(Minute()*60)+Seconds()    ); 
//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 19.02.2008                                                     |
//|  Описание : Возвращает суммарный профит в валюте депозита                  |
//|             закрытых с определённой даты позиций                           |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    sy - наименование инструмента             (""   - любой символ,         |
//|                                               NULL - текущий символ)       |
//|    op - операция                             (-1   - любая позиция)        |
//|    mn - MagicNumber                          (-1   - любой магик)          |
//|    dt - Дата и время в секундах с 1970 года  ( 0   - с начала истории)     |
//+----------------------------------------------------------------------------+
double GetProfitFromDateInCurrency(string sy="", int op=-1, int mn=-1, datetime dt=0)
{
  double p=0;
  int    i, k=OrdersHistoryTotal();

  if (sy=="0") sy=Symbol();
  for (i=0; i<k; i++) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) {
      if ((OrderSymbol()==sy || sy=="") && (op<0 || OrderType()==op)) {
        if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
          if (mn<0 || OrderMagicNumber()==mn) {
            if (dt<OrderCloseTime()) {
              p+=OrderProfit()+OrderCommission()+OrderSwap();
            }
          }
        }
      }
    }
  }
  return(p);
}
 
Dimka-novitsek:

Good afternoon! Forgive the triviality. The lines are from a robot, I've had the robot for years and basically a cycle of this kind invariably wanders from one to the other.

Why is my order total minus one? Is it true that the loop is going for a decrease in the variable and?

The loop counts an index from 0 to Total-1 or from Total-1 to 0. That's why it needs a minus sign or a lesser sign < .
 
Zhunko:

I would:

double TradePrice(int    nPriceId, // Цена: 0 - Bid; 1 - Ask
                  string sSymbol)  // валютная пара
 {
  switch (nPriceId)
   {
    case 0: return(MarketInfo(sSymbol, MODE_BID));
    case 1: return(MarketInfo(sSymbol, MODE_ASK));
    default: Print("Ошибка и прочее...");
   }
  return(0);
 }

To receive data viaMarketInfo() even for this window tool would be too expensive in terms of resources, don't you think?

Zhunko:

You should write a separate function to update the history.


I don't quite understand the logic of writing a separate function. The RefreshRates() function itself updates data of predefined variables. And Bid and Ask are predefined variables. If function RefreshRates() updates predefined variables, why write some additional function?
 
Thank you!!!