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

 
skyjet:

Hello! Looking for errors in this function.

The idea is that pending orders that have not opened should be deleted two days after they are placed.

min=1440;


Why would you want to track and delete pending orders? You should set their datetime expiration=TimeCurrent()+min*60+sec; they will be deleted themselves after min*60+sec.
 
Sepulca:

Why do you need to monitor and delete pending orders? You need to set datetime expiration=TimeCurrent()+min*60+sec; they will be deleted by themselves after min*60+sec.
Perhaps, the pending order will close according to some algorithm, so it will close in 1 day if there is another condition, for example, 2 days. 2 days.
 
Sepulca paladin80 Thanks! datetime expiration is just what we need :)
 

paladin80:

OrderOpenTime() returns the order open time.

For a pending order, this function returns zero.

 
PapaYozh:

OrderOpenTime() returns the order open time.

For a pending order, this function returns zero.

Hmm, I quickly tweaked the code without checking the functions themselves. Right, OrderOpenTime() shows the time of position opening by broker, but not the time of pending order acceptance by broker. I.e., probably, it would be better to specify the time of closing immediately in the order, or record the time of order sending in the magic number (if it's not used anyway) and compare TimeCurrent() with OrderMagicNumber( ).
 

Good afternoon. Help me deal with the custom indicator.

I am solving the problem of determining the distance to the trend line. I need to get the distance to the trend line exactly on the time frame where it is plotted (regardless of the time frame that is opened in the terminal). The current value of the trend line can be obtained using the function ObjectGetValueByShift. Since calculations can be done only by the open time, I wrote a small indicator. I was attracted by the fact that the iCustom function has the timeframe parameter, but I wonder how much this parameter is considered when calling the indicator.

Here is the indicator:


#property indicator_chart_window
#property indicator_buffers 1
//--------------------------------------------------------------------   
extern string TL_name = "TL_1";
//--------------------------------------------------------------------   
double valueBuf[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init() {
   //---- indicators
   SetIndexBuffer(0,valueBuf);
   SetIndexStyle (0,DRAW_LINE,STYLE_SOLID,1, White);
   //----
   return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit() {
   //----
   //----
   return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start() {
   int i;
   int    counted_bars = IndicatorCounted();
   //----
   i = Bars - counted_bars - 1;           // Индекс первого непосчитанного
   
   // Цикл по непосчитанным барам
   while(i>=0) {
      valueBuf[i] = NormalizeDouble(ObjectGetValueByShift(TL_name,i), Digits);
      i--;
   }     
   //----
   return(0);
}

The indicator considers the current value of the trend.
I call the indicator itself:

TL_price_now = iCustom(NULL,PERIOD_D1,"TL_value",TL_name,0,0);

Here, for example, PERIOD_D1 time is passed to the indicator as a parameter, on which the trend is plotted, and for which the distance should be calculated.

I calculate the distance to the trend simply:

dist = NormalizeDouble(TL_price_now - Bid, Digits);
It seems to be so, but not so: when switching to other timings (different from D1), the indicator returns other values (correct for the timings I switch to).
Here we have a question: to what extent a period is considered when calling the iCustom function ?
Or maybe I have messed up the indicator?
 
pako:


t = OrdersTotal();

why count???? counted???


So I did it to pass the value by reference. The logic is simple!
 
artmedia70:

In my version, the function is shorter ... :)



Yes, by the way, this way of implementation is smarter. Only in start there was more space occupied by additional functions. It turned out like this:

void FindOrders(int& massive[])
{
   int oType;
   ArrayInitialize(massiveOfOrders, 0);
   for (int i=OrdersTotal() - 1; i>=0; i--)
   {
      if (!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue;
      if (OrderSymbol() != Symbol()) continue;
      if (OrderMagicNumber() != i_magic) continue;
      
      oType = OrderType();
      massiveOfOrders[oType] = massiveOfOrders[oType] + 1;
   }
}

int start()
{
   int i, oTotal = 0, oPending = 0;
   
   FindOrders(massiveOfOrders);
   
   for (i=0; i<=7; i++)
   {
       if (i > 1 && i < 6)
       {
           oPending += massiveOfOrders[i];
       }
       if (i < 6)
       {
          oTotal += massiveOfOrders[i];
       }
   }
   pr ("FindOrders(): " + "oTotal = " + oTotal);
   pr ("FindOrders(): " + "oPending = " + oPending);

It's not like there's anything to optimise, is there?

I mean, it's much more convenient, when there's nothing at all in the start. And everything is called purely by functions. And last time it turned out that the start has a lot of all sorts of overgrowths on the main functions and overgrowths of additional ones...

 

Good day!

Please help and explain why the Expert Advisor is not working or trading?

 
nick_travel:

Good day!

Please help and explain why the Expert Advisor is not working or trading?

Maybe he wants to eat? Or waiting for a paycheck...