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

 
Roger:


Look at this line

else if (order_type = OP_SELL()

And this one.

if (order_type = OP_BUY)
 
TarasBY:

I see in the new code (which is below in the post) the default parameter passed to the function has changed:

The original version had a different Magik. I've corrected the reference to this function in my code. Look under which Magik the orders are open now and put this Magik number in your EA.


No, the magik is correct, the one for EURAUDUSD is 1111 and the one for EURUSD_GBPUSD is 1114 (another person helped me to correct it). Both trades do not close. I'm watching the total profits of EURUSD_GBPUSD, but my Expert Advisor is unable to close it. I have modified your version for EURAUD_AUDUSD - 1111 for EURUSD_GBPUSD - 1114, it still does not close deals. The feature of the owl is that you cannot test it in the tester (because two pairs are traded) - only on a demo.
 
alexey1979621:

No, the mage is correct, the one for EURAUD_AUDUSD is 1111 and the one for EURUSD_GBPUSD is 1114 (another person helped me correct it). Both trades do not close. I'm watching the total profits of EURUSD_GBPUSD, but my Expert Advisor is unable to close it. I have modified your version for EURAUD_AUDUSD - 1111 for EURUSD_GBPUSD - 1114, it still does not close deals. The feature of the owl is that I cannot test it in the tester (because two pairs are traded) - only on a demo.


Let's make some changes. Instead of

if(prof>=Profit)
   {
  for(int i=OrdersTotal()-1;i>=0;i--) 
      {
     if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
         {
     double AS=MarketInfo(OrderSymbol(), MODE_ASK);
     double BI=MarketInfo(OrderSymbol(), MODE_BID);

       if(OrderType()==OP_BUY) price=BI;
       else                    price=AS;

       OrderClose(OrderTicket(),OrderLots(),price,3,CLR_NONE);
         }
      }   
   }

put

Comment("Profit = ",prof);
if(prof>=Profit)
   {
Print("Profit is good!");
  for(int i=OrdersTotal()-1;i>=0;i--) 
      {
     if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
         {
     double AS=MarketInfo(OrderSymbol(), MODE_ASK);
     double BI=MarketInfo(OrderSymbol(), MODE_BID);

       if(OrderType()==OP_BUY) price=BI;
       else                    price=AS;
       Print("OrderTicket - ",OrderTicket()," price - ",price);
       if(!OrderClose(OrderTicket(),OrderLots(),price,3,CLR_NONE))Print ("Error - ",GetLastError());
         }
      }   
   }
run the EA, set the profit to zero and see what came out and what's in the logs.
 
Roger:


Look at this line

else if (order_type = OP_SELL()


thanks!)
 
alexey1979621:

No according to the majik everything is correct, the one for EURAUD_AUDUSD is 1111 and the one for EURUSD_GBPUSD is 1114 (another person helped to fix it). Both trades do not close. I'm watching the total profits of EURUSD_GBPUSD, but my Expert Advisor is unable to close it. I have revised your version for EURAUD_AUDUSD - 1111 for EURUSD_GBPUSD - 1114, it still does not close deals. The feature of the owl is that you cannot test it in the tester (because two pairs are traded) - only on a demo.

Firstly, you are not addressing the indicator correctly. This indicator has a lot of external parameters:

extern string Symbol1.Name      = "EURUSD";// Название инструмента 1
extern bool   Symbol1.Reverse   = false;   // Является ли инструмент 1 реверсивным (с обратной корреляцией) 
                                           // по отношению к остальным инструментам
extern string Symbol2.Name      = "USDCHF";// Название инструмента 2
extern bool   Symbol2.Reverse   = false;   // Является ли инструмент 2 реверсивным (с обратной корреляцией) 
                                           // по отношению к остальным инструментам
extern string  ___MISC___       = " == Прочие настройки ==========";
extern bool   UseVolatility     = True ;   //отрисовка с учетом волатильности
extern bool   Triangle          = True ;   // Рисовать треугольник?
extern color  Triangle.Color    = DarkSalmon; // Цвет треугольника
extern double Alert.ChannelMore = EMPTY;   // Если ширина канала больше указанной, включается сигнал
                                           //   -1 - контроль выключен.
extern double Alert.ChannelLess = EMPTY;   // Если ширина канала меньше указанной, включается сигнал
                                           //   -1 - контроль выключен.
extern string  __VOL___         = " == Расчет объемов ====";
extern int VOL.Mode             = 3;       // Режим расчета объемов для торговли
                                           //   1 - по ценам открытия
                                           //   2 - по волатильности, а если невозможно - по ценам открытия
                                           //   3 - по волатильности (если возможно) и ценам открытия
extern int VOL.PeriodATR        = 144;            // Период усреднения ATR 
extern string  ___MA___         = " == Параметры МА ценовых линий ====";

extern int MA.Slow              = 21;      // Период медленной МА
extern int MA.Fast              = 8;       // Период быстрой МА
extern int MA.Method            = 2;       // Метод аппроксимации
                                           // - MODE_SMA=0 Простое скользящее среднее 
                                           // - MODE_EMA=1 Экспоненциальное скользящее среднее 
                                           // - MODE_SMMA=2 Сглаженное скользящее среднее 
                                           // - MODE_LWMA=3 Линейно-взвешенное скользящее среднее 
extern int MA.Price             = 6;       // Расчетная цена:
                                           // - PRICE_CLOSE=0 Цена закрытия 
                                           // - PRICE_OPEN=1 Цена открытия 
                                           // - PRICE_HIGH=2 Максимальная цена 
                                           // - PRICE_LOW=3 Минимальная цена 
                                           // - PRICE_MEDIAN=4 Средняя цена, (high+low)/2 
                                           // - PRICE_TYPICAL=5 Типичная цена, (high+low+close)/3 
                                           // - PRICE_WEIGHTED=6 Взвешенная цена закрытия, (high+low+close+close)/4 

and they need to be listed when you call the indicator. If you omit them, the parameters will be taken by default, and since you want to use it for different currency pairs, this option is not suitable. And everything else can be done taking into account the changes of parameters at the start of the EA:

extern string Symbol_1 = "EURAUD";
extern string Symbol_2 = "AUDUSD";
extern double Lot_1=0.01;
extern double Lot_2=0.01;
extern double Profit=10;
extern string EXP_Comment           = "KVAZ_";
extern int    Magic                 = 1111;

string gsa_SMB[2];
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
  gsa_SMB[0] = Symbol_1;
  gsa_SMB[1] = Symbol_2;
  EXP_Comment = StringConcatenate (EXP_Comment, Symbol_1, "_", Symbol_2);
   return (0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
{
    int    li_N;
    double prof = 0., ld_Price = 0.;

    for (int i = OrdersTotal() - 1; i >= 0; i--)
    {
        OrderSelect (i, SELECT_BY_POS);
        li_N = fGet_NumSymbol (OrderSymbol(), gsa_SMB);
        if (li_N < 0) continue;
        if (OrderMagicNumber() != Magic) continue;
        prof += OrderProfit();
        Print ("Profit=", prof);
    }
    if (prof >= Profit)
    {
        for (i = OrdersTotal() - 1; i >= 0; i--)
        {
            OrderSelect (i, SELECT_BY_POS);
            li_N = fGet_NumSymbol (OrderSymbol(), gsa_SMB);
            if (li_N < 0) continue;
            if (OrderMagicNumber() != Magic) continue;
            if (OrderType() == OP_BUY) ld_Price = MarketInfo (gsa_SMB[li_N], MODE_BID);
            else if (OrderType() == OP_SELL) ld_Price = MarketInfo (gsa_SMB[li_N], MODE_ASK);
            OrderClose (OrderTicket(), OrderLots(), ld_Price, 5);
        }
    }
    double lda_Price[2],
           Line_1 = iCustom (Symbol(), 0, "Ind_2 Line+1", 0, 1), // Первый инструмент
           Line_2 = iCustom (Symbol(), 0, "Ind_2 Line+1", 1, 1); // Второй инструмент

    if (NumberOfPositions (gsa_SMB[0], -1, Magic) == 0)
    {
        lda_Price[0] = MarketInfo (gsa_SMB[0], MODE_BID);
        lda_Price[1] = MarketInfo (gsa_SMB[0], MODE_ASK);
        if (Line_1 > 0.1) if (Line_2 < -0.1)
        {OrderSend (gsa_SMB[0], OP_SELL, Lot_1, lda_Price[0], 3, 0, 0, EXP_Comment, Magic, 0, Red);}
        if (Line_1 < -0.1) if (Line_2 > 0.1)
        {OrderSend (gsa_SMB[0], OP_BUY, Lot_1, lda_Price[1], 3, 0, 0, EXP_Comment, Magic, 0, Blue);}
    }
    if (NumberOfPositions (gsa_SMB[1], -1, Magic) == 0)
    {
        lda_Price[0] = MarketInfo (gsa_SMB[1], MODE_BID);
        lda_Price[1] = MarketInfo (gsa_SMB[1], MODE_ASK);
        if (Line_1 < -0.1) if (Line_2 > 0.1)
        {OrderSend (gsa_SMB[1], OP_BUY, Lot_2, lda_Price[1], 3, 0, 0, EXP_Comment, Magic, 0, Blue);}
        if (Line_1 > 0.1) if (Line_2 < -0.1)
        {OrderSend (gsa_SMB[1], OP_SELL, Lot_2, lda_Price[0], 3, 0, 0, EXP_Comment, Magic, 0, Red);}
    }
    return (0);
}
//+------------------------------------------------------------------+
int fGet_NumSymbol (string fs_Symbol, string ar_SMB[])
{
    for (int li_IND = 0; li_IND < 2; li_IND++)
    {if (fs_Symbol == ar_SMB[li_IND]) return (li_IND);}
    return (-1);
}
//+------------------------------------------------------------------+
int NumberOfPositions(string sy="", int op=-1, int mn=1111)
{
  int i, k=OrdersTotal(), kp=0;
  if (sy=="0") sy=Symbol();
  for (i=0; i<k; i++) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
      if (OrderSymbol()==sy || sy=="") {
        if (OrderType()==OP_BUY || OrderType()==OP_SELL) {
          if (op<0 || OrderType()==op) {
            if (mn<0 || OrderMagicNumber()==mn) kp++;
          }
        }
      }
    }
  }
  return(kp);
}
//+------------------------------------------------------------------+

Read about indicator call here.

 
Roger:


Let's make some changes. Instead of

put

run the EA, set the profit to zero and see what came out and what's in the logs.


The result is ugly. With your changes and profit equal to 0, the Expert Advisor has closed all positions on Meijic 1111, 1112, 1113, 1114, 1115. Then, after 5 seconds, new orders for these Meijic symbols were opened and after 10 seconds, they all got closed and the same thing happened again. The positions were not opened in pairs, but chaotically.
 
alexey1979621:

This has turned out to be a scary one. With your changes and profit equal to 0, the EA closed all positions on Majic 1111, 1112, 1113, 1114, 1115 at all. Then, after 5 seconds, new orders for these Meijic symbols were opened and after 10 seconds, they all got closed and the same thing happened again. The positions were not opened in pairs, but chaotically.


My guiding question is: how many EAs do you have in this account?

And you had a condition - to close all orders on profit.

PS You have seen the pitfall you have with this EA - it will keep opening orders after closing, which will eventually lead to a loss. So you have to put a flag prohibiting the placing of new orders until the conditions pass and arise again.

 
TarasBY:

Firstly, you are not addressing the indicator correctly. This indicator has a lot of external parameters:

and they need to be listed when you call the indicator. If you omit them, the parameters will be taken by default, and since you want to use it for different currency pairs, this option is not suitable. Everything else can be done considering the changes of parameters at the start of the EA:

You can read about calling the indicator here.

Thank you. I know about the indicator call. But the adjustable parameters of the indicator should be listed when we apply them in testing or in operation. Since this EA cannot be tested in the tester (because two pairs are traded), it is impossible to choose these parameters on the history. Your last variant has already been implemented in a demo. I will see how the trades will close. Another small question, for two instruments trades open either in Buy or Sell. If we need one to open in Sell for one instrument and in Buy for another, what should we do? I have poked around, no luck ..... Again, thank you very much for your hard work.
 
Roger:


A guiding question - how many EAs do you have in this account?

And you did have a condition - to close all orders on profit.

PS You have seen the pitfall you have with this EA - it will keep opening orders after closing, which will eventually lead to a loss. So you have to put a flag prohibiting the placing of new orders until the conditions pass and arise again.


The Expert Advisors worked for 5 (twin brothers - for different pairs), of course with different Meijic.


Yes, we had the profit condition to close the orders but the orders were related to a certain EA, for example, with MAJIC 1114. I wrote about it from the very beginning and believed that owl does not see its own orders at closing; it turns out that it sees all orders and wants very much to close them but we do not need all of them but some specific ones.

If we take H4 period, when the indicator lines are higher than 0.1 and lower than -0.1, the condition is satisfied and the deals are opened, i.e., it is possible to take several profits at one signal (though there is an option to close deals when indicator lines converge).

 
alexey1979621:
Thank you. I know about the indicator call. But the adjustable parameters of the indicator should be listed when we apply them in testing or in operation and since this EA cannot be tested in the tester (as two pairs are involved in trading), we simply cannot choose these parameters on the history.

Something tells me that you don't fully understand what we are talking about. This indicator takes readings of two different currency pairs, these pairs are set in external settings of the indicator. And if you apply to this indicator with default parameters in different Expert Advisors on different currency pairs, you will get wrong values from it. And it does not matter if you test it or spoof it - you have to prescribe the work with the indicator correctly!
alexey1979621:
Another small question we have in two instruments trades open either to sell or to buy, but if we need one to open to sell for one instrument and another to open to buy, then how?

How you specify the conditions for opening, that's how the orders will be opened. If you do not know what the indicator says, I cannot help you.

alexey1979621:
There were 5 EAs working (twin brothers - for different pairs), of course with different Majics.

In your version, the work with the Magician is not specified correctly. The orders are opened with the specified Magik, but the check for orders in the market is performed with the default Magik. It should be like this:

NumberOfPositions (/*рабочий символ*/, -1, Magic);