Take Profit Moving

 

Hello, I would like to write a script that moves the take profit of open positions.For example if open position current price is lower than 70 pips of open price than move the take profit 30 pips above the current price. Can anybody help me or tell if already exist something similar ?

Thanks, greetings from Italy,

Scheggia97

 

you need to loop through all your orders (by your unique magic no. or something like this) & find the right one or more & use OrderModify()

 
qjol !!! Thanks, the script you sent me last time is good, I am using it on live account. Now I would like to find a solution for move take profit, I think it is not imppossible but at the begin it is always difficult ..... ciao
 

I am editing this simple script that move all the take profits of only one symbol.

How can I edit the code to check "Pair4" and "Pair12" ?

Thanks in advance,

Scheggia97

#property show_inputs
extern int tp=1000;

string Pair4 = "AUDUSD";
string Pair12 = "USDJPY";


int start()
{
double spread=Ask-Bid;

int totalorders = OrdersTotal();
for(int i=totalorders-1;i>=0;i--)
{
OrderSelect(i, SELECT_BY_POS);
{
if (OrderSymbol()==Symbol()&& OrderType() == OP_BUY ) {
OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),OrderOpenPrice()+tp*Point ,0,Green);}

}          
if (OrderSymbol()==Symbol()&& OrderType() == OP_SELL ) {
OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),OrderOpenPrice()-tp*Point + spread,0,Green);}


}
return;
}
 
scheggia97:

Hello, I would like to write a script that moves the take profit of open positions.For example if open position current price is lower than 70 pips of open price than move the take profit 30 pips above the current price.

    for(int pos = OrdersTotal()-1; pos >= 0 ; pos--) if (
        OrderSelect(pos, SELECT_BY_POS)            // Only my orders w/
    &&  OrderMagicNumber() == Magic.Number         // my magic number
    &&  OrderSymbol()      == Symbol() ){          // and period and symbol
       ...
        if (oo.TP == NO_TP){                                // For disconnection
            oo.TP   = MathCeilDIR( (Bid +DIR*pips10)/pips05 // protection, use a
                                 )*pips05 -stop.to.Bid;     // leading TP, (like
            if (TPorig!=0)  MaximizeDIR(oo.TP,TPorig);      // a trailing SL.)
 

Hello WHRoeder, thanks for you kindly reply. Forgive me but I am just a beginner and I am not able to continue The MetaEditor tell me:

'Magic.Number' - variable not defined
'oo.TP' - variable not defined
'NO_TP' - variable not defined
'oo.TP' - variable not defined
'DIR' - variable not defined
'pips10' - variable not defined
'pips05' - variable not defined
'pips05' - variable not defined
'stop.to.Bid' - variable not defined
'TPorig' - variable not defined
'oo.TP' - variable not defined
'TPorig' - variable not defined
 
You need to declare variables before u use them (hence 'variables not defined'). I suggest u start here -> https://book.mql4.com//.
 
Gordon, thanks. I understand I must study. Here I can find thousands of scientific expert but very difficult to find a solution to my elementary question: Saluti dall' Italia, greetings from Italy
 
scheggia97:

Hello WHRoeder, thanks for you kindly reply. Forgive me but I am just a beginner and I am not able to continue The MetaEditor tell me:

'Magic.Number' - variable not defined
'oo.TP' - variable not defined
'NO_TP' - variable not defined
'oo.TP' - variable not defined
'DIR' - variable not defined
'pips10' - variable not defined
'pips05' - variable not defined
'pips05' - variable not defined
'stop.to.Bid' - variable not defined
'TPorig' - variable not defined
'oo.TP' - variable not defined
'TPorig' - variable not defined

scheggia97:
Gordon, thanks. I understand I must study. Here I can find thousands of scientific expert but very difficult to find a solution to my elementary question: Saluti dall' Italia, greetings from Italy


but this is a basic thing that's y he suggest u:

gordon:
[...] I suggest u start here -> https://book.mql4.com//.
 
scheggia97:
[...] but very difficult to find a solution to my elementary question [...]
Because it's too elementary... Variable declaration is explained in the very first pages of the book (https://book.mql4.com/basics/types). So please do some homework before asking such elementary questions.
 
gordon:
Because it's too elementary... Variable declaration is explained in the very first pages of the book (https://book.mql4.com/basics/types). So please do some homework before asking such elementary questions.
Gordon, don't lose your time to reply to my elementary questions. Maybe somebody can help me more than you.
Reason: