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()
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; }
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 |
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 |
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:
[...] 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.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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