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

 

All is selected normally, but the errors are strange, I can't figure it out with the tester.

It says that I closed lot 0.3 and sold lot 0.7 at the same time. Is this how part of a deal is closed in the tester? I don't know where such volumes come from; I don't see any information about such volumes in my Expert Advisor.

   for(Counter1=0;Counter1<OrdersTotal();Counter1++)
     {
     if(OrderSelect(Counter1,SELECT_BY_POS,MODE_TRADES) == false) break;
     if(OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber)
       {
       if(OrderType() == OP_BUY)
         {
         
         BuyOpened = 1;
         if((Bid - OrderOpenPrice()) / Point >= TrailingLevel1 && (Bid - OrderOpenPrice()) / Point < TrailingLevel2)
           {
           // Перенести в безубыток
           }
         }
       if(OrderType() == OP_SELL)
         {
         TrailingPrice1 = OrderOpenPrice() - TrailingLevel1*Point;
         MyOrderStopLoss1 = NormalizeDouble(OrderStopLoss(),4);
         MyOrderStopLoss1 = OrderOpenPrice() - BreakEven*Point;
         SellOpened = 1;
         if((OrderOpenPrice() - Ask) / Point >= TrailingLevel1 && (OrderOpenPrice() - Ask) / Point < TrailingLevel2 && OrderStopLoss() != MyOrderStopLoss1)
           {
           ClosingLot = OrderLots() / 100 * ClosingPercent;
           ClosingLot = NormalizeDouble(ClosingLot,3);
           OrderClose(OrderTicket(),ClosingLot,Ask,Slippage,Yellow);
           OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice() - BreakEven*Point,OrderTakeProfit(),OrderExpiration(),Black);
           }
         }
       }
     }
 
sss2019:

All is selected normally, but the errors are strange, I can't figure it out with the tester.

It says that I closed lot 0.3 and sold lot 0.7 at the same time. Is this how part of a deal is closed in the tester? Also, I don't know where such volumes come from when a part of a trade is closed and then opens 0.16, 0.24, 0.12; the Expert Advisor does not have such volumes.

yes, this is how part of the close is displayed - first all is closed, then part is open


i have two questions:

1) how do you know what not to close next?

on the next tick, the condition will be fulfilled again for this function

2) if I am not mistaken, the order ticket changes after the partial closing, i.e.

OrderClose(OrderTicket(),ClosingLot,Ask,Slippage,Yellow);
           OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice() - BreakEven*Point,OrderTakeProfit(),OrderExpiration(),Black);
           

there will be no change in the second line


3) And let's not forget normalisation...

 
ilunga:

yes, this is how the closing of a part is displayed - first all closed, then the open part


two questions immediately:

1) how do you know there is no need to close further?

the condition on the next tick will be fulfilled again for this function

2) if I am not mistaken, the order ticket changes after the partial closing, i.e.

there will be no change in the second line


3) And let's not forget about normalization...


Is the ticket really changing? That must be the reason for all the errors. Then why does not the ticket change when the order is changed manually? I need to know for sure if the ticket changes or not.
 


Really changing, thank you very much
 
I heard that when you get a price from a currency pair for further work with it, it should be normalized, for example, a price got from a minimum and it should be normalized to set it to a stop loss, is this true?
 
sss2019:
I heard that when you get a price from a currency pair, you need to normalize it, e.g. you get a price from a low and you need to normalize it to a stop loss, is this true?

Yes, but we mean the normalization at the moment of setting it to Ordersend/OrderModify/... before these functions you can work with it and perform operations
 
sergeev:

Yes. But the normalisation is meant at the moment of substitution in Ordersend/OrderModify/... before these functions you can work with it and perform operations

How many digits should it be normalised to? By default, the price seems to have 4 digits after the decimal point, even for five-digit price values, at least Low[0] and High[0] always have only 4 digits after the decimal point, I tried to output it via Alert or via Print,
 
sss2019:

How many digits should it be normalized to? By default price seems to have 4 digits after decimal point, even for five-digit value, at least Low[0] and High[0] always have only 4 digits after decimal point, I tried to output it via Alert or via Print,

by default the Digits price has digits after the decimal point

and Alert and Print output only 4 by default. Use string DoubleToStr( double value, int digits) for more.

 

Help then implement a trailing stop, like this. Sell order

         if((OrderOpenPrice() - Ask) / Point > Trailing) //Если прибыль в пунктах больше чем уровень трейлинг стопа
           {
           NewStopLoss = Ask + TrailingLevel2*Point;
           double NewStopLoss2 = 9999;
           if(NewStopLoss2 > NewStopLoss)
             {
             NewStopLoss2 = NewStopLoss;
             }
           OrderModify(OrderTicket(),OrderOpenPrice(),NewStopLoss2,OrderTakeProfit(),OrderExpiration(),Black);
           }

The problem is, stop loss should only be rolled forward, but in my order it also rolls backward.

________________________________

My question is gone, sorry.

 
sss2019:

Help then implement a trailing stop, like this. Sell order

The problem is, stop loss should only be moved forward, but I also have it moved backward.

double NewStopLoss2 = 9999;
           if(NewStopLoss2 > NewStopLoss)
             {
             NewStopLoss2 = NewStopLoss;
             }

is equivalent to

NewStopLoss2 = NewStopLoss;