[ARCHIVE] Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 3. - page 87

 
FOReignEXchange:


Who likes what they like. Everyone's handwriting is different. Maybe you've got it right, but I think it's sloppy.

I wouldn't do it that way.

First, I'm not quite sure why I should declare a variable there and what the point is in it, I don't understand it either.

Secondly, the line PriceBuy = Ask; is located right after the OrderSend function. And as far as I understand, calculations are immediately passed to the next line as soon as this function finishes its execution. I don't think the Ask price can change. I try to write everything as simple as possible, reducing the number of characters, if it doesn't interfere with normal operation of the program. I can assign a value the same way as you do, I don't see a problem here. I wrote what was the first and easiest thing that came to mind.

I have written a Pips Expert Advisor once and entered a contest in which the minimum profit to be taken into account is 5 pips. I set TP=5, SL=10 in my EA and went for a walk. I came home in the evening and looked into the terminal and was disappointed. My Pips Expert Advisor closed most of my trades with profit, but the profit of some of them was 4 points and even 3, and not 5, which I needed. By the way, SL was sometimes not 10, but 11 or 12 points...

Why? I'm sure you know the answer! :D

Here is a real life situation, in which I have stopped counting Ask and Bid prices as opening prices of orders. If 1-2 points is not significant for you, it is OK. For me it is the little things that are important.

 
MaxZ:

Why not? I'm sure you know the answer! :D

Nah. I first thought it was because the spread was not counted.

Were there any trades where the profit was 6-7 pips?

 
FOReignEXchange:
Nah. I first thought it was because the spread has not been calculated.

Shit... To quote myself:

MaxZ:

Third: if Slippage is specified in the OrderSend trade function and We want to open a Buy order, it is not necessarily that the order will open exactly at the Ask price, since it takes a certain amount of time to execute a trade order given by the OrderSend function and the price can move away from this value.

And what price value are we tying TP and SL to? To Ask... The price has changed, but TP and SL has not moved anywhere.

 
MaxZ:

To what price value do we fix TP and SL? To Ask... The price has changed, but TP and SL has not moved anywhere.

I can't guarantee that my spelling is absolutely correct. But I do it this way all the time when I need to. I haven't noticed anything wrong with it.

I cannot say anything about your case, where you had a fixation of profit less than 5 pips, because I haven't seen the code.

 

Was:

if (Opn_B)
{
   Alert("Попытка открыть ордер Buy...");
   RefreshRates();
   SL =  Ask-StopLoss*Point;
   TP =  Ask+TakeProfit*Point;
   Ticket = OrderSend(Symb, OP_BUY , Lots, Ask, Slippage, SL, TP, NULL, MAGIC, 0, Blue);
   if (Ticket > 0)
   {
      Alert("Открыт ордер Buy ", Ticket, ".");
      Opn_B = False;
   }
   else
      Alert("Ошибка: ", GetLastError());
}

Became:

if (Opn_B)
{
   Alert("Попытка открыть ордер Buy...");
   RefreshRates();
   SL = Ask-StopLoss*Point;
   TP = Ask+TakeProfit*Point;
   Ticket = OrderSend(Symb, OP_BUY , Lots, Ask, Slippage, SL, TP, NULL, MAGIC, 0, Blue);
   if (Ticket > 0)
   {
      if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES))
      if (OrderCloseTime() == 0)
      {
         Alert("Открыт ордер Buy ", Ticket, ".");
         Opn_B = False;
         
         if (NormalizeDouble(OrderOpenPrice()-OrderStopLoss(), Digits) != NormalizeDouble(StopLoss*Point, Digits))
         {
            SL = OrderOpenPrice()-StopLoss*Point;
            TP = OrderOpenPrice()+TakeProfit*Point;
            
            Alert("Попытка модифицировать ордер Buy ", Ticket, "...");
            if (OrderModify(Ticket, OrderOpenPrice(), SL, TP, 0, Blue))
               Alert("Ордер Buy ", Ticket, " модифицирован.");
            else
               Alert("Ошибка: ", GetLastError());
         }
      }
      else
         Alert("Да ну нафиг!?");
   }
   else
      Alert("Ошибка: ", GetLastError());
}

The principle is this. But it's actually a little more complicated than that...

How many lines? Really? :)))

 
MaxZ:

Was:

Became:

The principle is this. But it's actually a little more complicated than that...

How many lines? Really? :)))


??? I don't get it. Where are the SL and TP in the first example?
 
FOReignEXchange:

??? I don't get it. Where are the SL and TP in the first example?

I only showed the principle. All right, then. Added.

MaxZ:

The principle is this. But it's actually a little more complicated than that...

If the order does not open at the stated price, there may be an error when modifying the order and We will run into the same rake... That's why we actually try to modify the order more than once if it has a positive Ticket... We just don't want to copy all the code. It's cumbersome. But the principle is explained.
 
Ah, I see. SL and TP are standing before the OrderSend function. Maybe that was the problem?
 
FOReignEXchange:
Ah, I see. SL and TP are standing before the OrderSend function. Maybe that was the problem?
What could be the problem? By the time SL and TP are calculated, the price will have time to change? ;)))
 
MaxZ:
What could be the problem with that? By the time SL and TP are calculated, will the price have time to change??? ;)))

I told you that while the OrderSend function is running, the price might change. So we have to assign it afterwards, when it has already changed.