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

 
It's a good thing I'm not using any innovations that the more knowledgeable haven't figured out yet! :)
 
Megan:
There!) I thought I was the only one with glitches.) How would you solve this problem?



If the developers did not intend this behavior of the timer as a "foolproof", then the bug is unequivocal. After all, the timer starts in the inite, and from that point should work autonomously. You need to make a request to servicedesk.
 
the moderator seems to have read it. barabashkakvn- can he confirm that there is a problem and should he write to servicedesk?
 
Megan:
EventSetTimer(1); stands. And when there is a connection, everything works, oddly enough. There is no unloading at OnInit() . I don't know why it's like this(...

MetaTrader 4 build 660. Really, if there is no connection at the moment of terminal start, OnInit() does not happen.

Remedy: re-attach expert or switch timeframe twice.


 
barabashkakvn:

MetaTrader 4 build 660. Indeed, if there is no connection at the moment of terminal start, OnInit() does not happen.

This can be cured by a half-measure: re-attach the Expert Advisor or switch the timeframe twice.


There is a problem with it) My EA is designed to work offline(
 
Megan:
problem with that) I have an EA designed for standalone operation(


You need to write a request to servicedesk.
 

Hello. Friends, please help a newbie. I can't figure out how to load the quotes into the terminal, pre-edited in .xls file. I have been struggling with this all day.

Can I download the quotes for the terminal?

 

Hello again. Asked it myself, answered it myself: when editing the name, I chose any name but the original one. Corrected to - RTSI1440.csv and uploaded.

Thank you.

 
Top2n:

Good day!

The goal is to write an algorithm for averaging trades.

I decided to implement it by filling open positions price values into an array. As a result, it fills the array without changing. I missed something somewhere.

Zeroing of the array before the beginning:

  if (ArrayResize(array, 0) != 0) {
    return false;
  }

By the way, if OrderSelect() returns an error in at least one iteration of the loop, the results cannot be trusted. In other words, we shouldn't try to handle the remaining orders if some of them have failed. It would be more reasonable to return the error right away instead. For example, a higher-level code could react to an error in the following way: try to repeat a couple more times with this tick or cancel actions on this tick, postpone them and try again with the next tick.

It is more logical to unite Usred() and Zapis(), and the filter condition should be combined in the following way: "if (OrderSymbol() == Symbol() && OrderType() == type)". Anyway, there's no need in a repeated OrderSelect() in Zapis().

To calculate the average price of a position for individual orders, we don't have to keep everything in an array. We can calculate it on the fly.

S1 = order1_lots * order1_openprice + order2_lots * order2_openprice + ... orderN_lots * orderN_openprice.

S2 = order1_lots + order2_lots + ... + orderN_lots.

The price of the position we are looking for = S1 / S2.

If we create two variables, for S1 and for S2, set them to zero, and in the loop every time we add a corresponding value to each of the variables, then after the loop we only have to divide S1 by S2, having first checked that S2 is not 0 (in this case - error, that is, the result is NOT calculated, it does not exist). Perhaps the resulting value must also be normalized by NormalizeDouble() - it depends on algorithm if normalization is needed, and on program conventions, which function calls or is called to normalize.

In this case you won't even need an array.

If you need calculations other than the total position price, you can "return" values S1 and S2 to the called function, passing the variables themselves by reference, and return the error sign from the function. That is, the prototype of the called function could look as follows: "bool fun(double &S1, double &S2);". The calling function starts the variables, passes them to fun(), and, if fun() returns true, uses the values of the passed variables (which themselves may have different names) as S1 and S2.

 
simpleton:

If calculations other than the total position price are needed, you can "return" the values of S1 and S2 to the called function by passing the variables themselves by reference, and return the error sign from the function. That is, the prototype of the called function could look as follows: "bool fun(double &S1, double &S2);". The calling function starts variables, passes them to fun(), and, if fun() returns true, uses the values of the passed variables (which themselves may have different names) as S1 and S2.

Thank you! Roger. Except that with the error on OrderSelect, it's not clear how to stop except tocontinue.

Deleted late post, did almost the same as described.

double CenaUsrednenija(const int type,const int Magic){
double nn=0,bb=0;
 double factb=0;
  int total=OrdersTotal();

for(int i=total-1; i>=0; i--)
  {
    if (!(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))) continue;
    if (OrderSymbol() != Symbol()) continue;  

   if(OrderSelect(i,SELECT_BY_POS))
     {
      if(OrderSymbol()==Symbol())
        {
         if(OrderType()==type && OrderMagicNumber()==Magic)
           {
            double op=OrderOpenPrice();
            double llot=OrderLots();
            double itog=op*llot;
            bb=bb+itog;
            nn=nn+llot;
            factb=NormalizeDouble(bb/nn,_Digits);
        //  Print("  type= ",type," Цена открытия= ",op, " Лот= ",llot, " itog=op*llot= ",itog, " factb=bb/nn= ",factb);
        
           }
        }
     }
  }  return(factb);  
}  
Reason: