[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 397

 
lottamer:

It worked! Honestly, I had this idea of substituting OR for AND.... but ... :)))))))))))))))))))))

thanks ! now i understand the logic, although to count 15 closed ones, i will have to blow the code to the size of a balloon !

Can it all be squeezed into one loop ? and only substitute the parameter of the number of N trades needed ?

Here is one of the possible ways to search for N most recently closed orders, and the sought orders can be filtered by type (BUY, SELL) and profitability (loss-making, profitable):

//IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII+
//|  Автор : TarasBY, taras_bulba@tut.by                                              |
//+-----------------------------------------------------------------------------------+
//|        Функция получает Ticket следующего перед fdt_Time закрытого ордера         |
//IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII+
int fGet_TicketLastClosePos (int fi_Type = -2,          // OrderType()
                             int fi_TypeProfit = 0,     // флаг профитности ордеров: 0 - все, -1 - убыточные, 1 - прибыльные
                             datetime fdt_Time = 0)     // Точка отсчёта времени
{
    datetime ldt_CloseTime = 0, ldt_LastTime = 0;
    double   ld_Profit = 0.;
    int      li_Ticket = 0, li_Total = OrdersHistoryTotal();
//----
    for (int li_ORD = li_Total - 1; li_ORD >= 0; li_ORD--)
    {
        //if (!fCheck_MyOrders (li_ORD, fi_Type, MODE_HISTORY)) continue;
        // Здесь прописываете свою фильтрацию ордеров
        ldt_CloseTime = OrderCloseTime();
        //---- Пропускаем ордера, закрытые после указанной даты
        if (fdt_Time != 0) if (fdt_Time <= ldt_CloseTime) continue;
        if (ldt_LastTime >= ldt_CloseTime) continue;
        ld_Profit = OrderProfit();
        //---- Фильтруем ордера по профитности
        if (fi_TypeProfit > 0) if (ld_Profit < 0.) continue;
        if (fi_TypeProfit < 0) if (ld_Profit > 0.) continue;
        ldt_LastTime = ldt_CloseTime;
        li_Ticket = OrderTicket();
    }
//----
    return (li_Ticket);
}
//IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII+
//|  Автор : TarasBY, taras_bulba@tut.by                                              |
//+-----------------------------------------------------------------------------------+
//|        Функция получает Tickets N закрытых ордеров                                |
//IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII+
int fGet_TicketsLastCloseOrd (int fi_NUM,                // Количество искомых тикетов
                              int& ar_Tickets[],         // возвращаемый массив с тикетами
                              int fi_Type = -2,          // OrderType()
                              int fi_TypeProfit = 0)     // флаг профитности ордеров: 0 - все, -1 - убыточные, 1 - прибыльные
{
    int      li_cnt = 0, li_Ticket;
    datetime ldt_Time = 0;
//----
    for (int li_IND = 0; li_IND < fi_NUM; li_IND++)
    {
        li_Ticket = fGet_TicketLastClosePos (fi_Type, fi_TypeProfit, ldt_Time);
        if (li_Ticket > 0)
        {
            li_cnt++;
            ArrayResize (ar_Tickets, li_cnt);
            ar_Tickets[li_cnt-1] = li_Ticket;
            OrderSelect (li_Ticket, SELECT_BY_TICKET);
            ldt_Time = OrderCloseTime();
        }
        else break;
    }
//----
    return (li_cnt);
}

After fGet_TicketsLastCloseOrd() function is called and it returns the amount of tickets found according to the specified parameters, you can (I would do it) check with the specified amount of tickets (fi_NUM) and the value returned by the function. All collected tickets will be in the array passed to the function by reference.

And in this variant it's not important, how many of these last tickets are searched. :)

And if you need profit by these last closed orders, it's even easier:

//IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII+
//|  Автор : TarasBY, taras_bulba@tut.by                                              |
//+-----------------------------------------------------------------------------------+
//|        Функция получает Profit N последних закрытых ордеров                       |
//IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII+
double fGet_ProfitLastCloseOrd (int fi_NUM,          // Количество просчитываемых ордеров
                                int fi_Type = -2)    // OrderType()
{
    int      li_Ticket;
    double   ld_Profit = 0.;
    datetime ldt_Time = 0;
//----
    for (int li_IND = 0; li_IND < fi_NUM; li_IND++)
    {
        li_Ticket = fGet_TicketLastClosePos (fi_Type, 0, ldt_Time);
        if (li_Ticket > 0)
        {
            OrderSelect (li_Ticket, SELECT_BY_TICKET);
            ldt_Time = OrderCloseTime();
            ld_Profit += (OrderProfit() + OrderSwap() + OrderCommission());
        }
        else break;
    }
//----
    return (ld_Profit);
}
 
TarasBY:

Here is one of possible ways to search for N tickets of last closed orders, and you can filter orders by type (BUY, SELL) and profitability (loss-making, profitable):

After fGet_TicketsLastCloseOrd() function is called and it returns the amount of tickets found according to the specified parameters, you can (I would do it) check with the specified amount of tickets (fi_NUM) and the value returned by the function. All collected tickets will be in the array passed to the function by reference.

And in this variant it's not important, how many of these last tickets are searched. :)

And if you need profit by these last closed orders, it's even easier:



Thank you very much. I'll take a break, I need to figure out what's what...
 
Hello, help me solve this problem: I want one indicator to display eurobucks, dollar index and euro index, but their values are different by several orders. How can I bring them to values of the same order? Just add multipliers - I don't think it suits my taste...
 
tommy27:
Hello, help me solve this problem: I want one indicator to display eurobucks, dollar index and euro index, but their values are different by several orders. How can I bring them to values of the same order? I think it's not feasible to add multipliers...

Set min and max values of all indicators to the same
 

Good day to you, my advice to a pro: I wrote an indicator which signals I want to use in my EA. Which will work faster, the indicator function or the transferred indicator?

Thanks

 
pako:

set min. and max. for all indicators to the same

Which ones... I want all this to be shown by one indicator for 3 droline buffers.
 

tommy27:

How do you bring them to values of the same order?

the scale must be the same
 
pako:
the scale should be the same

Yes, and to do this, it makes sense to convert all three buffer values before displaying them like this:

Xn=(X-Xmin)/(Xmax-Xmin)

If you do this bluntly, you get something that looks like a horizontal line.

Well, if you use the scaling from MQ, you're good to go.

 
Thanks, I'll give it a try.
 
Zhunko:
If it does happen, it won't happen soon, maybe never.

Thanks for the reply.

But I've been using the same suspicious comparison in other code for a long time now.

And it works successfully.

int start()                                                                                                                     
{                                                                                                                       
                                                                                                                        
 double Price=iOpen (Symbol (),0,0);                                                                                                                            
 int last_order_bar = 0;                                                                                                                        
 int ot = OrdersTotal();                                                                                                                        
                                                                                                                        
 if (ot>0) //если есть ордера в рынке                                                                                                                   
 {                                                                                                                      
   if (OrderSelect (ot-1,SELECT_BY_POS))                                                                                                                        
      if (OrderType ()==OP_BUY || OrderType ()==OP_SELL )                                                                                                                       
         last_order_bar = iBarShift (Symbol (),0,OrderOpenTime ());                                                                                                             
 }                                                                                                                      
                                                                                                                        
 int last_hist_order_bar = 0;                                                                                                                   
 int oht = OrdersHistoryTotal();                                                                                                                        
                                                                                                                        
 if (oht>0)                                                                                                                     
 {                                                                                                                      
   if (OrderSelect (oht-1,SELECT_BY_POS, MODE_HISTORY))                                                                                                                         
      if (OrderType ()==OP_BUY || OrderType ()==OP_SELL)                                                                                                                        
         last_hist_order_bar = iBarShift (Symbol (),0,OrderOpenTime ());                                                                                                        
 }                                                                                                                      
                                                                                                                        
 if (ot==0 || last_order_bar>0)                                                                                                                      
    if (oht==0 || last_hist_order_bar>0) 
//===============================================================
if(Bid==Price)
if((Minute( ) ==45)&&(Minute( ) <50))
int Ticket=OrderSend(Symbol(),OP_BUY,0.1,Ask,1,Bid-1500*Point,Bid+150*Point,"jfh",123 );        
                                                                                        
}                                                                                                                       
return;
I do not understand why this condition does not work in the last case. I do not see any fundamental differences between these codes.