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

 
yosuf:

It is painful to watch the giants of the forum fighting over trifles. This is a forum of programmers of the most powerful resource. Be polite. Suggestion:

1. If an attempt is made to switch to personalities, even in a surreptitious manner, ban for 24 hours;

2. insulting a person - one week ban;

3. repeated insults with swearing - one month ban;

4.Ignoring all previous warnings and repeating violations in a harsh form - perpetual ban.



I absolutely agree, except that, unfortunately, the moderators here are not competent enough to detect "something in disguise". It's the same with all the subtle diplomats here.
 

Sorry for the offtops, but maybe someone can tell me what it is about:

From the handbook:

"It is possible to pass parameters by reference. In this case, modification of such parameters will affect the corresponding variables in the called function passed by reference. The elements of arrays cannot be passed by reference. Parameters can be passed by reference only within the limits of a single module, such an opportunity is not provided for library functions. In order to specify that the parameter is passed by reference, the & modifier must be placed after the data type.

Arrays can also be passed by reference, all changes will be reflected in the initial array. Unlike simple parameters, arrays can be passed by reference in library functions as well".

To pass a value by reference from a library function, I have to use a proxy in the form of an array of unit dimension,

are there any other workarounds?

And why is it done that way?

 
ALXIMIKS:

Sorry for the offtops, but maybe someone can tell me what it is about:

From the handbook:

"It is possible to pass parameters by reference. In this case, modification of such parameters will affect the corresponding variables in the called function passed by reference. One cannot pass elements of arrays by reference. Parameters can be passed by reference only within the limits of a single module, such an opportunity is not provided for library functions. To specify that the parameter is passed by reference, modifier & must be placed after the data type.

Arrays can also be passed by reference, all changes will be reflected in the initial array. Unlike simple parameters, arrays can be passed by reference in library functions as well".

1. To pass a value by reference from a library function, I have to use a proxy in the form of an array of unit dimension,

are there any other workarounds?

2. why is it done that way?

1. Right. There is no other way in MQL4.

2. What exactly? If we're speaking about passing by reference, then it's for passing large volumes of data (greater than the base type's length). Not to load the stack with them. Usually, structures, classes and arrays are passed by the pointer or reference. Although the class and structure can be returned from the function through return. You can also return a reference or pointer to a class, structure or array.

 

I have this problem:

When I change the stoploss, from time to time it fails to place a stop on the last order opened. It happens quite rarely, but it shoots through from time to time.

I do not have any errors in prices. Just a scumbag sometimes does not put an order on the last position, after which the order is recalculated.

Can you tell me where I did it wrong?

//+-------------------------------------------------------------------------------------+
//|                        Управление StopLoss, TakeProfit                              |
//+-------------------------------------------------------------------------------------+
bool ProfitManagement()
{
double StopLossBuy = BuyAP+Profit*Point;                             //Вычисляем StopLoss
double TakeProfitBuy = BuyAP + Profit*Point;                  //Вычисляем цену TakeProfit
double StopLossSell = SellAP-Profit*Point;
double TakeProfitSell = SellAP - Profit*Point;
RefreshRates();
for(int good = 0; good < OrdersTotal(); good ++)     // Выбираем со всего массива ордеров
 {
 if(OrderSelect (good, SELECT_BY_POS, MODE_TRADES))             
 if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue;
 if(OrderSymbol()==Symbol()&&OrderMagicNumber()==MagicNumber)  //Выбираем ордера эксперта
   { 
//-------------------------Order Buy-----------------------------------------------------  
if (BuyCount >1)                                           //Если открыты длинные позиции
 {
 if (BuyAP < Bid)                                                //Если  мы идем по рынку  
 if (MathAbs(OrderStopLoss() - StopLossBuy) >= Tick)           // Профит не равен нужному
 if (Bid - StopLossBuy > DedZone)                    // Уровень достаточно удален от цены
 if (WaitForTradeContext())                                // Свободен ли торговый поток?
 if (OrderType() == OP_BUY)                                        // Выбираем ордера Buy
 if (!OrderModify(OrderTicket(), 0, NP(StopLossBuy), 0, 0, Lime))    // Изменяем StopLoss
  {
 Alert (Symbol()," Хрень со стопами! ",   GetLastError());
 return(false);
  }

// ну и далее по логике
 
yosuf:

It is painful to watch the giants of the forum fighting over trifles. This is a forum of programmers of the most powerful resource. Be polite. Suggestion:

1. If an attempt is made to switch to personalities, even in a surreptitious manner, ban for 24 hours;

2. insulting a person - one week ban;

3. repeated insults with swearing - one month ban;

4.Ignoring all previous warnings and repeating violations in a harsh form - perpetual ban.


And the firing squad when? There won't be?
 
Limita:

I have this problem:

When I change the stoploss, from time to time it fails to place a stop on the last order opened. It happens quite rarely, but it shoots through from time to time.

I do not have any errors in prices. Just a scumbag sometimes does not put an order on the last position, after which the order is recalculated.

Please, advise me where I did it wrong?

Explain this sequence in words:

   //-------------------------Order Buy-----------------------------------------------------  
         if (BuyCount >1) {
            if (BuyAP < Bid)                                      //Если  мы идем по рынку, то выполнится следующая  
            if (MathAbs(OrderStopLoss() - StopLossBuy) >= Tick)   // Профит не равен нужному
            if (Bid - StopLossBuy > DedZone)                      // Уровень достаточно удален от цены
            if (WaitForTradeContext())                            // Свободен ли торговый поток?
            if (OrderType() == OP_BUY)                            // Выбираем ордера Buy
            if (!OrderModify(OrderTicket(), 0, NP(StopLossBuy), 0, 0, Lime)) {
               Alert (Symbol()," Хрень со стопами! ",   GetLastError());
               return(false);
            }

In simple terms, how would you tell a mate who is far from programming

 

We want to earn, for example, 50 pips per position. StopLoss equals our average price + 50 pips .

If we have an open long position, we earn a certain amount of money on it. We set StopLoss at a certain level. Let the market grow further. If we are not earning enough money yet, we wait until we start earning enough.

We open another position in the Buy direction. The average price changes, we change the StopLoss.

And of course we set stops, follow the rules of a broker (trade flow, stop level), otherwise the broker will not understand us :)))

I hope I managed to explain :))

 
Limita:

We want to earn, for example, 50 pips per position. StopLoss equals our average price + 50 pips .

If we have an open long position, we earn a certain amount of money on it. We set StopLoss at a certain level. Let the market grow further. If we are not earning enough money yet, we wait until we start earning enough.

We open another position in the Buy direction. The average price changes, we change the StopLoss.

And of course we set stops, follow the rules of a broker (trade flow, stop level), otherwise the broker will not understand us :)))

I hope I managed to explain :))

Yeah ... I meant - the logic of those lines ...

You have ambiguous logic there, as there are no curly brackets. Which means that not every line will be satisfied if the preceding condition is satisfied

 
Limita:

I have this problem:

When I change the stoploss, from time to time it fails to place a stop on the last order opened. It happens quite rarely, but it shoots through from time to time.

I do not have any errors in prices. Just a scumbag sometimes does not put an order on the last position, after which the order is recalculated.

Please tell me where I did it wrong?


for (int good = 0; good < OrdersTotal(); good ++){                                // Выбираем со всего массива ордеров
    }    

It's better to do it this way (someone wrote that he had problems when modifying or deleting orders with your way of doing it) :

for (int good = OrdersTotal()-1; good >= 0; good --){     // Выбираем со всего массива ордеров
    }  

And why oil and butter ??? (leave one thing alone)

 if (OrderSymbol() != Symbol() || OrderMagicNumber() !=  MagicNumber) continue;
 if (OrderSymbol() == Symbol() && OrderMagicNumber() ==  MagicNumber) {          //Выбираем ордера эксперта
    }
 

And of course when we open the next buy, we immediately roll over (StopLoss equals our average price + 50 pips) on all positions .

This is the scoundrel who sometimes does not take the last position. We had 3 positions, but 4 of them opened. I forgot to put StopLoss on the fourth position.

DedZone should be held:

StopLevel = (MarketInfo(Symbol(), MODE_STOPLEVEL)*Point);       // текущий уровень стопов
FreezeLevel = (MarketInfo(Symbol(), MODE_FREEZELEVEL)*Point);        // уровень заморозки
DedZone = MathMax(StopLevel,FreezeLevel);              // Зона запрета розмещения ордеров

The DedZone calculation is in the initialization of the Expert Advisor.

Reason: