[Archive!] Any rookie question, so as not to clutter up the forum. Professionals, don't pass it by. Couldn't go anywhere without you - 2. - page 478

 
abolk:

the link https://www.mql5.com/ru/code has a warehouse full of similar ones

you gave a link to a whole huge section )))

that's funny

 

Good afternoon!

I'm asking for help, I've already killed myself, I can't figure it out!!! I need, that at achievement +20 p., SL of the order was rearranged on the price of opening, i.e. function gives out 77

 for(i=(OrdersTotal()-1); i>=0; i--) // перебор ордеров 
         { 
       if (!OrderSelect(i, SELECT_BY_POS))
      {
         continue;
      }

      if (OrderSymbol()!=Instr||OrderMagicNumber()!=MN)
          continue;
      if(OrderStopLoss()==OrderOpenPrice())
            break;    
       if (   OrderProfit()>=(MarketInfo(Symbol(),MODE_TICKVALUE)*Bezub)        ) 
   return(77);
                  
           }
   

I cannot get it to work.

 
demlin:

I need the SL of the order to be re-set to the opening price when it reaches +20 pips, i.e. the function shows 77

20 p is not calculated that way, you have to use the OrderOpenPrice() function and compare it with the current price, i.e., when the order reaches a positive or zero profit, you probably want the result to be 77, i.e:

for(i=(OrdersTotal()-1); i>=0; i--) // перебор ордеров 
         { 
            if (!OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES)) continue;
            if (OrderSymbol()!=Instr||OrderMagicNumber()!=MN)  continue;
            if(OrderStopLoss()==OrderOpenPrice()) break;    
            if ( OrderProfit()>=0)) return(77);
           }
the OrderProfit() function returns the order profit in the deposit currency, not in pips
 
Can you tell me if it is possible for an EA to get indicator data (from those that allow to do so) from another indicator. I haven't found such an opportunity in the price types.
 
IgorM:

20p is not calculated this way, you have to use the OrderOpenPrice() function and compare it with the current price, apparently you want the result 77 to be returned when the order reaches a positive or zero profit, then it looks like this:

the OrderProfit() function returns the order profit in the deposit currency, not in pips

That's roughly what I thought, I don't calculate 20 pips. They are set in the Bezub variable. I try to compare the current profit of the order in the deposit currency (OrderProfit()) and the required 20 points in the deposit currency ((MarketInfo(Symbol (),MODE_TICKVALUE)*Bezub)
 
demlin:
That's about what I thought, I'm not calculating 20 p. They're set in the Bezub variable. I'm trying to compare the current order profit in the deposit currency (OrderProfit()) and the required level of 20 p in the deposit currency ((MarketInfo(Symbol (),MODE_TICKVALUE)*Bezub)

then you forgot to take into account the current price and how many pips the price has moved since the order was placed:

(OrderOpenPrice() -Bid)*MarketInfo(Symbol(),MODE_TICKVALUE)*Bezub

ZZZEROXXX:
Please advise if I could get indicator data (the ones that allow it) from another indicator. I did not find such an opportunity in price types.

iCustom()

https://book.mql4.com/ru/samples/shared
 
IgorM:

then you forgot to take into account the current price and how many pips the price has moved since the order was placed:

(OrderOpenPrice() -Bid)*MarketInfo(Symbol(),MODE_TICKVALUE)*Bezub


Tried your scheme. Alert gives a (OrderOpenPrice() -Bid)*MarketInfo(Symbol(),MODE_TICKVALUE)*Bezub value of -0.033. Although, there is 21p in the profit ! Is this normal?
 
demlin:
Tested your scheme. Alert generates for (OrderOpenPrice() -Bid)*MarketInfo(Symbol(),MODE_TICKVALUE)*Bezub values -0.033. Although there is 21p in the profit ! Is this normal?

Sorry, I'm writing without checking, I've got it wrong here, it should work like this:

Sell:(OrderOpenPrice()-Bid)*MarketInfo(Symbol(),MODE_TICKVALUE)*lot/Point

Buy: (Ask-OrderOpenPrice())*MarketInfo(Symbol(),MODE_TICKVALUE)*lot/Point

 
IgorM:

Sorry, I'm writing without checking, I've got it wrong here, it should work like this:

Sell:(OrderOpenPrice()-Bid)*MarketInfo(Symbol(),MODE_TICKVALUE)*lot/Point

Buy: (Ask-OrderOpenPrice())*MarketInfo(Symbol(),MODE_TICKVALUE)*lot/Point

That's not pretty figures yet either. I don't think it's about the formula. The (MarketInfo(Symbol (),MODE_TICKVALUE)*Bezub) expression itself basically gives 20 for the Euro. The point is somewhere in the for loop
 
IgorM:

Sorry, I'm writing without checking, I've got it wrong here, it should work like this:

Sell:(OrderOpenPrice()-Bid)*MarketInfo(Symbol(),MODE_TICKVALUE)*lot/Point

Buy: (Ask-OrderOpenPrice())*MarketInfo(Symbol(),MODE_TICKVALUE)*lot/Point

That's not pretty figures yet either. I don't think it's about the formula. The (MarketInfo(Symbol (),MODE_TICKVALUE)*Bezub) expression itself basically gives 20 for EURUSD. It's somewhere in the for loop