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

 
hoz:

Help is urgently needed, I'm totally confused. Here is the trading function and the order modification function:

I currently have order modification not working, although when several functions were in one, everything worked. But I want all the functions to be separated for convenience. In general, I would like to have functionOrdersModifying to modify orders. I understand that logically it should be pasted into Trade function where I have pasted it, but we have to pass 2 parameters sl and tp from functionOrdersModifying into it.

Have I correctly passed the sl and tp variables through the parameters of theOrdersModifying function ?

You first do sl = 0; tp = 0; and then if(sl != 0 || tp != 0).
 
rigonich:
You first do sl = 0; tp = 0; and then if(sl != 0 || tp != 0).


Vitaly, the point is clear there. Look:

void OrdersModifying(double& sl, double& tp)
{
  int total = OrdersTotal() - 1;
  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(g_ticket,OrderOpenPrice(),sl,tp,OrderOpenTime() + 86400,Lime);      // Модифицируем ордер
      }
    }
  }
}

In the beginning sl = 0; tp = 0; Then I find the normalized values of sl and tp that will already be in the order based on i_sl and i_tp entered by the user. And then I check ifsl andtp are not equal to zero, i.e. they have changed after I declared them at the beginning of the function, then we modify the order.

And ifsl andtp are equal to zero, it means that these parameters have not been calculated... as I understand it. Once I obtain the values of these variables, they will immediately become non-zero, and we can modify the order... Does it make sense?

 
hoz:


Vitaly, the point is clear there. See:

In the beginning sl = 0; tp = 0; Then I based on the i_sl and i_tp entered by the user I find the normalized values of sl and tp which will already be in the order. And then I check ifsl andtp are not equal to zero, i.e. they have changed after I declared them at the beginning of the function, then we modify the order.

And ifsl andtp are equal to zero, it means that these parameters have not been calculated... as I understand it. Once I obtain the values of these variables, they will immediately become non-zero, and we can modify the order... Does it make sense?



Sorry, I didn't see something, no glasses and no colour, but why pass parameters to this function, and by reference as well? If i_sl,g_type... are global variables, it will work without parameters, and if you need to change them (variables after modification), do it in the same function after modification.
 
rigonich:

Sorry, I didn't see something, I'm not wearing glasses or any colour, but why should we pass parameters into this function, and by reference, too? If i_sl,g_type... are global variables, it will work without parameters, and if you need to change them (variables after modification), do it in the same function after modification.


Orders are sent byOpenBuy() andOpenSell() functions, but theOrdersModifying()function modifies the orders

I.e. if, for example, the modification function is placed inTrade function(int signal) orOpenBuy() andOpenSell(), then sl and tp values obtained inOrdersModifying() function should be passed there anyway.These values are missing in that function.

 
hoz:


The orders are sent by functionsOpenBuy() andOpenSell(), but they are modified by functionOrdersModifying()

I.e. if, for example, the modification function is placed inTrade function(int signal) orOpenBuy() andOpenSell(), then sl and tp values obtained inOrdersModifying() function should be passed there anyway.These values are missing in that function.


In your case, functionsOpenBuy() andOpenSell() place orders without std and then, if the orders are placed, they are modified using functionOrdersModifying() . I don't see any need to place somewhere else the functionOrdersModifying() and pass any parameters into it. Youjust need to declare sl and tpvariables in this function. int sl = 0, tp = 0;

Sorry, not int, a double.

 
rigonich:

YourOpenBuy() andOpenSell() functionsplace orders without sl and so on, and then, if the orders are placed, they are modified using theOrdersModifying() function. I don't see any need to place somewhere else the functionOrdersModifying() and pass any parameters into it. Youjust need to declare sl and tpvariables in this function. int sl = 0, tp = 0;


At the moment I have such a trading function:

bool Trade (int signal)
{
  FindOrders();

  if(signal == SIGNAL_BUY)                                                          // Если сигнал на покупку и открытых ордеров нет..
    if(!OpenBuy())                                                                  // открываем лимитный ордер на покупку
      return(false);                                                                
      
  if(signal == SIGNAL_SELL)                                                       // Если сигнал на продажу и открытых ордеров нет..
     if(!OpenSell())
       return(false);                                                              // открываем лимитный ордер на продажу
  
  if(OrderStopLoss() == 0 && OrderTakeProfit() == 0)
    OrdersModifying();                                                             // Модифицируем ордер, добавим SL и TP
    
  if(UseBU == true)
     MovingStopLossToBU();                                                         // Перевод в б.у. по достижению некоторого значения TP

  return(true);
}

Modification does not take place.

 
hoz:


At the moment I have such a trading function:

Modification does not take place.


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

I don't understand what you want from the script.


You need a program, which, when launched in the archive charts

The price movement sections will be visually marked with the specified parameters in terms of strength and time of the movement.

For example - a correction of 400 points made in 30 minutes. And so for the whole year, all corrections within this range.

It is impossible to visually observe them manually. Distortions. I would like to have colour coding that would allow to see them right away.

___

I've looked, there are different "Histoty" programs. But they only visualize the account history.

But I have not found a segment of the price by the filters I have specified.

 
rigonich:

You don't have an order selected in the Trade () function.


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

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);                                                              // открываем лимитный ордер на продажу
       
  for(int i=total; i>=0; i--)
  {
    if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
    {
      if(OrderStopLoss() == 0 || OrderTakeProfit() == 0)
        OrdersModifying();                                                             // Модифицируем ордер, добавим SL и TP
    }
  }    
 // if(UseBU == true)
   //  MovingStopLossToBU();                                                         // Перевод в б.у. по достижению некоторого значения TP

  return(true);
}

And the modification function is this:

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);      // Модифицируем ордер
      }
    }
  }
}

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

 
TUNGUS:


We need a program that, when launched in the archive charts

The price movement sections will be visually marked with the specified parameters in terms of strength and time of the movement.

For example - a correction of 400 points made in 30 minutes. And so for the whole year, all corrections within this range.

It is impossible to visually observe them manually. Distortions. I would like to have colour coding that would allow to see them right away.

___

I've looked, there are different "Histoty" programs. But they only visualize the account history.

But I couldn't find a segment of the price according to the given filters.


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

I need something like this, to watch the corrections in the history by the given parameters.

Reason: