[WARNING CLOSED!] Any newbie question, so as not to clutter up the forum. Professionals, don't go by. Can't go anywhere without you. - page 1099

 
kolyango:

If an OP_BUY order is open and its Stoploss is 100 pips below its open price, but the real price has moved 80 pips or more away from the open order price, we have to move the Stoploss to 50 pips above the order open price. How would it look? I mean the code. In fact, how should we mark such a condition?

Если установленная в ордере цена Stoploss меньше цены откр. ордера, то

если настоящая цена больше или равна 80 п. от цены откр. ордера, то

перемодефицировать ордер и переставить Stoploss на 50 п. больше цены откр. ордера.

Somebody help to implement such a condition...!!!


https://www.mql4.com/ru/search/?keyword=%D1%82%D1%80%D0%B5%D0%B9%D0%BB%D0%B8%D0%BD%D0%B3
 

What is polarisation?

 


And what is the predefined variable for the price at which the StopLoss is set on the OP_BUY market order? If there is one, of course. Right?

OrderStopLoss()

 
kolyango:

And what is the predefined variable for the price at which the StopLoss is set on an OP_BUY market order? If there is one, of course.

https://www.mql5.com/ru/search/
 

If an OP_BUY order is open and its Stoploss is 100 pips below its open price, but the real price has moved 80 pips or more away from the open order price, we have to move the Stoploss to 50 pips above the order open price. How would it look? I mean the code. How should we mark such a condition?

After the orders have been tried:

Если установленная в ордере цена Stoploss меньше цены откр. ордера, то

если настоящая цена больше или равна 80 п. от цены откр. ордера, то

перемодефицировать ордер и переставить Stoploss на 50 п. больше цены откр. ордера.

Somebody help me to implement such a condition...!!

The beginning would probably be like this (1st condition)?

if (OrderOpenPrice()>OrderStopLoss())

 
kolyango:

If an OP_BUY order is open and its Stoploss is 100 pips below its open price, but the real price has moved 80 pips or more away from the open order price, we have to move the Stoploss to 50 pips above the order open price. How would it look? I mean the code. How should we mark such a condition?

After the orders have been tried:

Если установленная в ордере цена Stoploss меньше цены откр. ордера, то

если настоящая цена больше или равна 80 п. от цены откр. ордера, то

перемодефицировать ордер и переставить Stoploss на 50 п. больше цены откр. ордера.

Somebody help me to implement such a condition...!!

The beginning would probably be like this (1st condition)?

if (OrderOpenPrice()>OrderStopLoss())



if(OrderType==OP_BUY){
if(OrderStopLoss()==0.0 && SL!=0 || OrderTakeProfit()==0.0 && TP!=0)
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Bid-SL*Point,Digits),NormalizeDouble(Bid+TP*Point,Digits),0, Blue);
if(NormalizeDouble(Bid-OrderOpenPrice(),Digits)>NormalizeDouble((Trailing+MinProfit)*Point,Digits)){
if(NormalizeDouble(Bid-Trailing*Point,Digits)>OrderStopLoss() || OrderStopLoss()<=0.0)
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Bid-Trailing*Point,Digits),OrderTakeProfit(),0, Ivory);

}}

 
DhP:


if(OrderType==OP_BUY){
if(OrderStopLoss()==0.0 && SL!=0 || OrderTakeProfit()==0.0 && TP!=0)
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Bid-SL*Point,Digits),NormalizeDouble(Bid+TP*Point,Digits),0, Blue);
if(NormalizeDouble(Bid-OrderOpenPrice(),Digits)>NormalizeDouble((Trailing+MinProfit)*Point,Digits)){
if(NormalizeDouble(Bid-Trailing*Point,Digits)>OrderStopLoss() || OrderStopLoss()<=0.0)
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Bid-Trailing*Point,Digits),OrderTakeProfit(),0, Ivory);

}}

If an OP_BUY order is open and its Stoploss price is 100 pips below its open price and the real price has moved 80 pips or more away from the open order price, we have to move our Stoploss by 50 pips above the order open price. How would it look? I mean the code. How should we mark such a condition?

After the orders have been tried:



Если установленная в ордере цена Stoploss меньше цены откр. ордера, то

если настоящая цена больше или равна 80 п. от цены откр. ордера, то

перемодефицировать ордер и переставить Stoploss на 50 п. больше цены откр. ордера.

Somebody help to implement such a condition...!!!

And it will constantly modify the order depending on the real price and not only the StopLoss, but also the TakeProfit! Or will it not?


if(OrderType==OP_BUY) // Здесь понятно! Если ордер на покупку
{
if(OrderStopLoss()==0.0 && SL!=0 || OrderTakeProfit()==0.0 && TP!=0) //
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Bid-SL*Point,Digits),NormalizeDouble(Bid+TP*Point,Digits),0, Blue);
if(NormalizeDouble(Bid-OrderOpenPrice(),Digits)>NormalizeDouble((Trailing+MinProfit)*Point,Digits))
{
if(NormalizeDouble(Bid-Trailing*Point,Digits)>OrderStopLoss() || OrderStopLoss()<=0.0)
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Bid-Trailing*Point,Digits),OrderTakeProfit(),0, Ivory);
}
}
Help decipher what this code will do and under what conditions?
 
kolyango:

If an OP_BUY order is open and its Stoploss is 100 pips below its open price, but the real price has moved 80 pips or more away from the open order price, we have to move the Stoploss to 50 pips above the order open price. How would it look? I mean the code. Actually, how should we mark such a condition?

Если установленная в ордере цена Stoploss меньше цены откр. ордера, то

если настоящая цена больше или равна 80 п. от цены откр. ордера, то

перемодефицировать ордер и переставить Stoploss на 50 п. больше цены откр. ордера.

Someone help implement such a condition...!!!

I see that we do not want to think about it. But nevertheless... Take a look at this thread - you'll find a lot of ready-made functions, in particular trailing stop, which you need.

Get to grips with the code that's already working - and then you can write it exactly the way you want it...

 
kolyango:

And it will constantly modify the order depending on the real price and not only the StopLoss, but also the TakeProfit! Or not?


if(OrderType==OP_BUY)
{
if(OrderStopLoss()==0.0 && SL!=0 || OrderTakeProfit()==0.0 && TP!=0)
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Bid-SL*Point,Digits),NormalizeDouble(Bid+TP*Point,Digits),0, Blue);
if(NormalizeDouble(Bid-OrderOpenPrice(),Digits)>NormalizeDouble((Trailing+MinProfit)*Point,Digits))
{
if(NormalizeDouble(Bid-Trailing*Point,Digits)>OrderStopLoss() || OrderStopLoss()<=0.0)
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Bid-Trailing*Point,Digits),OrderTakeProfit(),0, Ivory);
}
}

At first it will only set Stop Loss and Take Profit.

Then it trawls the profit, starting from the MinProfit level.

 
DhP:

Stop Loss and Take Profit have already been set! If the set StopLoss is less than the opening price of the order, you only need to move the StopLoss above the opening price by 50 pips (to the loss) if the current price is more or equal to 80 pips from the opening price of the order. And you don't have to constantly rearrange StopLoss and TakeProfit!
Reason: