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

 

Problem with Symbol() MT4:

2 functions to illustrate:

string   SymbolOK()
{

   string   value;
   string   argument = "ANYTHING";

   if(false)
   {
      value = argument;
   }

   return(value);

}

string   SymbolPROBLEM()
{

   string   value;
   string   argument = Symbol();

   if(false)
   {
      value = argument;
   }

   return(value);

}

Execution of the first one outputs an empty string:

int start()
{
   Comment(SymbolOK());
   return(0);
}

But the second function outputs a string ID "EURUSD" (well, depends on the chart, but outputs, although according to the logic of the function it should be an empty string):

int start()
{
   Comment(SymbolPROBLEM());
   return(0);
}

Help me understand what is wrong? Thank you

 
rigonich:

You do not have an order selected in the Trade () function.

By the way. What is the point of selecting an order in the Trade() function? I am calling the function OrdersModifying() where the order is selected and it is modified there. I.e., the initial variant was correct!
 
hoz:


There is such a thing. Here's the fix.

And the modification function is here:

Strange But there are no stops and takes on the output again.



OrderSelect(g_ticket,SELECT_BY_TICKET) before the line if(OrderStopLoss() == 0 || OrderTakeProfit() == 0)
 
TUNGUS:


History, History_Draw - they work like Expert Advisors during testing.

You need something like this to watch corrections in history by given parameters


In the history or on the chart? If yes, then what kind of data do you want to see in the chart window, in a separate window, printed as a table, in the form of different coloured candles, or as a line connecting the start and end of the movement?
 
rigonich:

OrderSelect(g_ticket,SELECT_BY_TICKET) before the line if(OrderStopLoss() == 0 || OrderTakeProfit() == 0)


That's what I did:

bool Trade (int signal)
{
  int total = OrdersTotal() - 1;
  
  FindOrders();

  if(signal == SIGNAL_BUY)                                                          // Если сигнал на покупку и открытых ордеров нет..
    if(!OpenBuy())                                                                  // открываем лимитный ордер на покупку
      return(false);                                                                
      
  if(signal == SIGNAL_SELL)                                                       // Если сигнал на продажу и открытых ордеров нет..
     if(!OpenSell())
       return(false);                                                              // открываем лимитный ордер на продажу

    if(OrderSelect(g_ticket,SELECT_BY_TICKET,MODE_TRADES) == true)
    {
      if(OrderStopLoss() == 0 || OrderTakeProfit() == 0)
        OrdersModifying();                                                             // Модифицируем ордер, добавим SL и TP
    }    
 // if(UseBU == true)
   //  MovingStopLossToBU();                                                         // Перевод в б.у. по достижению некоторого значения TP

  return(true);
}

There are no stops and takeovers. The log says error 130, saying the stops are wrong. I do not see the reason.

 
hoz:


That's what I did:

There are no stops and takeovers. The log says error 130, saying that the stops are wrong. I don't see the reason.


Without ifs, justOrderSelect(g_ticket,SELECT_BY_TICKET,MODE_TRADES);, and you can leave it in OrdersModifying()

//+------------------------------------------------------------------+

void OrdersModifying()

{

OrderSelect(g_ticket,SELECT_BY_TICKET,MODE_TRADES);

if(g_type == OP_BUY)

{

if(i_sl != 0)sl = NormalizeDouble(OrderOpenPrice() - i_sl*pt,Digits); // If the stop loss input parameter is not 0

// Get the value of Stop Loss for the selected order

if(i_tp != 0)tp = NormalizeDouble(OrderOpenPrice() + i_tp*pt,Digits); // If the TakeProfit input parameter is not equal to 0, then...

// obtain the TakeProfit value for the selected order

}

if(g_type == OP_SELL)

{

if(i_sl != 0)sl = NormalizeDouble(OrderOpenPrice() + i_sl*pt,Digits); // If the input parameter of the stop loss is not 0

// Get the value of Stop Loss for the selected order

if(i_tp != 0)tp = NormalizeDouble(OrderOpenPrice() - i_tp*pt,Digits); // If the TakeProfit input parameter is not equal to 0, then...

// obtain the TakeProfit value for the selected order

}

if(sl != 0 || tp != 0) // If the obtained values of sl and tp are not equal to 0, then..

{

OrderModify(OrderTicket(),OrderOpenPrice(),sl,tp,OrderOpenTime() + 86400,Lime); // Modify order

}

}


 
anton.veksler:

Problem with Symbol() MT4:

2 functions to illustrate:

Execution of the first one outputs an empty string:

But the second function outputs a string ID "EURUSD" (well, depends on the chart, but outputs, although according to the logic of the function it should be an empty string):

Help me understand what is wrong? Thank you


You cannot use reserved names(value) when declaring your variables, call _value
 
hoz:


That's what I did:

There are no stops and takeovers. The log says error 130, saying that the stops are wrong. I don't see the reason.

And they won't!

  double sl = 0, tp = 0;                                           // тут присвоили по нулям
  
  for(int i=total; i>=0; i--)
  {
    if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) == true)           // Если ордер есть и он выбран..
    {
      if(g_type == OP_BUY)
      {
        if(i_sl != 0) // замените на if(sl == 0)                   // Если входной параметр стоп-лосса не равен 0, то..
           sl = NormalizeDouble(OrderOpenPrice() - SL*pt,Digits);  // Если по нулям, тогда выполнится условие!
 

Vitaly, I did as you said, but nothing has changed. Apparently the bug is buried somewhere else.

Before I had everything (opening orders - modification and transfer to b.w. when the set price level is reached) and everything worked. It was like this:

bool Trade (int signal)
{
  FindOrders();
  
  double sl = 0, tp = 0;

  if(signal == SIGNAL_BUY)                                                          // Если сигнал на покупку и открытых ордеров нет...
    if(!OpenBuy())                                                           // открываем лимитный ордер на покупку
      return(false);
        
  if(signal == SIGNAL_SELL)                               // Если сигнал на продажу и открытых ордеров нет..
    if(!OpenSell())                                                          // Открываем лимитный ордер на продажу
      return(false);
  
  int total = OrdersTotal() - 1;
  for(int i=total; i>=0; i--)
  {
    if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) == true)                            // Если ордер есть и он выбран..
    {
      if(g_type == OP_BUY)
      {
        if(i_sl != 0)                                                                 // Если входной параметр стоп-лосса не равен 0, то..
           sl = NormalizeDouble(OrderOpenPrice() - i_sl*pt,Digits);                    // Получаем значение стоп-лосса для выбранного ордера
        if(i_tp != 0)                                                                 // Если входной параметр тейкпрофита не равен 0, то..
           tp = NormalizeDouble(OrderOpenPrice() + i_tp*pt,Digits);                    // Получаем значение тейкпрофита для выбранного ордера
      }
      if(g_type == OP_SELL)
      {
        if(i_sl != 0)                                                                 // Если входной параметр стоп-лосса не равен 0, то..
           sl = NormalizeDouble(OrderOpenPrice() + i_sl*pt,Digits);                // Получаем значение стоп-лосса для выбранного ордера
        if(i_tp != 0)                                                                 // Если входной параметр тейкпрофита не равен 0, то..
           tp = NormalizeDouble(OrderOpenPrice() - i_tp*pt,Digits);                // Получаем значение тейкпрофита для выбранного ордера
      }
      if(sl != 0 || tp != 0)                                                            // Если полученные значения sl и tp не равныы 0, то..
      {
        OrderModify(OrderTicket(),OrderOpenPrice(),sl,tp,OrderOpenTime() + 86400,Lime);      // Модифицируем ордер
      }
    }
  }

  return(true);
}

Now, as I've broken everything down into specific specialised functions, it's all stopped working soooo much. I've tried it both ways, nothing works. no stops are set.

 
borilunad:

And they won't!

 double sl = 0, tp = 0;                                           // тут присвоили по нулям
  
  for(int i=total; i>=0; i--)
  {
    if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) == true)           // Если ордер есть и он выбран..
    {
      if(g_type == OP_BUY)
      {
        if(i_sl != 0) // замените на if(sl == 0)                   // Если входной параметр стоп-лосса не равен 0, то..
           sl = NormalizeDouble(OrderOpenPrice() - SL*pt,Digits);  // Если по нулям, тогда выполнится условие!

Where's the logic in that? I'd like to understand... Here is the function:

void OrdersModifying()
{
  int total = OrdersTotal() - 1;
  double sl = 0, tp = 0;
  
  for(int i=total; i>=0; i--)
  {
    if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES) == true)                            // Если ордер есть и он выбран..
    {
      if(g_type == OP_BUY)
      {
        if(i_sl != 0)                                                                 // Если входной параметр стоп-лосса не равен 0, то..
           sl = NormalizeDouble(OrderOpenPrice() - i_sl*pt,Digits);                    // Получаем значение стоп-лосса для выбранного ордера
        if(i_tp != 0)                                                                 // Если входной параметр тейкпрофита не равен 0, то..
           tp = NormalizeDouble(OrderOpenPrice() + i_tp*pt,Digits);                    // Получаем значение тейкпрофита для выбранного ордера
      }
      if(g_type == OP_SELL)
      {
        if(i_sl != 0)                                                                 // Если входной параметр стоп-лосса не равен 0, то..
           sl = NormalizeDouble(OrderOpenPrice() + i_sl*pt,Digits);                // Получаем значение стоп-лосса для выбранного ордера
        if(i_tp != 0)                                                                 // Если входной параметр тейкпрофита не равен 0, то..
           tp = NormalizeDouble(OrderOpenPrice() - i_tp*pt,Digits);                // Получаем значение тейкпрофита для выбранного ордера
      }
      if(sl != 0 || tp != 0)                                                            // Если полученные значения sl и tp не равныы 0, то..
      {
        OrderModify(OrderTicket(),OrderOpenPrice(),sl,tp,OrderOpenTime() + 86400,Lime);      // Модифицируем ордер
      }
    }
  }
}

If the input variables i_sl and i_tp are not equal to zero, we get the stop and take prices that will already be in the order - sl andtp. After that I will check if we have calculatedsl andtp here (if for shorts):

 if(i_sl != 0)                                                                 // Если входной параметр стоп-лосса не равен 0, то..
           sl = NormalizeDouble(OrderOpenPrice() + i_sl*pt,Digits);                // Получаем значение стоп-лосса для выбранного ордера
        if(i_tp != 0)                                                                 // Если входной параметр тейкпрофита не равен 0, то..
           tp = NormalizeDouble(OrderOpenPrice() - i_tp*pt,Digits);                // Получаем значение тейкпрофита для выбранного ордера
      }

If the values are obtained, then they cannot be zero... because they will be changed! These are variables that we get sequentially by code context.

And here, I checked if we found the values of stop and take. How can they be zero after all the conditions?

if(sl != 0 || tp != 0)                                                            // Если полученные значения sl и tp не равныы 0, то..
      {
        OrderModify(OrderTicket(),OrderOpenPrice(),sl,tp,OrderOpenTime() + 86400,Lime);      // Модифицируем ордер
      }
Reason: