Take Profit Moving - page 2

 

With the below script I change the take profits of all open positions in the trade tab. Now I must add the following condiction:

change the take profit if the order profit is lower than 100 pips. I think it is easy, but not for me .....thanks, Scheggia97

#property show_inputs

extern int tp=1000;



string Pair1 = "EURCHF";
string Pair2 = "EURUSD";



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

int totalorders = OrdersTotal();
for(int i=totalorders-1;i>=0;i--)
{
OrderSelect(i, SELECT_BY_POS);

{
if (OrderSymbol()== Pair1 && OrderType() == OP_BUY ) {
OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),OrderOpenPrice()+tp*MarketInfo(Pair1,MODE_POINT),0,Green);}
}          
if (OrderSymbol()==Pair1 && OrderType() == OP_SELL ) {
OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),OrderOpenPrice()-tp*MarketInfo(Pair1,MODE_POINT) + spread,0,Green);}

{
if (OrderSymbol()== Pair2 && OrderType() == OP_BUY ) {
OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),OrderOpenPrice()+tp*MarketInfo(Pair2,MODE_POINT),0,Green);}
}          
if (OrderSymbol()==Pair2 && OrderType() == OP_SELL ) {
OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),OrderOpenPrice()-tp*MarketInfo(Pair2,MODE_POINT) + spread,0,Green);}

}
return;
}
 
if (OrderSymbol()== Pair1 && OrderType() == OP_BUY && NormalizeDouble(OrderClosePrice()-OrderOpenPrice(),2) >= tp/Point) {


if (OrderSymbol()==Pair1 && OrderType() == OP_SELL && NormalizeDouble(OrderOpenPrice()-OrderClosePrice(),2) >= tp/Point) {
 

qjol, thanks for your reply, I will study your solution later. I have found what I was looking for after one week of experiments ....

I have attached the file "TakeProfitMoving" maybe it could be helpful for some beginner like me. This script change the take profit value if the current price of a pair is less than the setting value(tp_level). It works on two different pairs but it can be enlarged by adding other pairs. Thanks again qjol, good trading to everybody !

Scheggia97


#property show_inputs

extern int tp= 200;
extern int tp_level= -1000;


extern string Pair1 = "EURUSD";
extern string Pair2 = "EURJPY";


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

int totalorders = OrdersTotal();
for(int i=totalorders-1;i>=0;i--)
{
OrderSelect(i, SELECT_BY_POS);

{
if (OrderSymbol()== Pair1 && OrderType() == OP_BUY && (( OrderProfit() - OrderCommission() ) / OrderLots() / MarketInfo( Pair1, MODE_TICKVALUE )) <= tp_level) {
OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),OrderOpenPrice()+tp*MarketInfo(Pair1,MODE_POINT),0,Green);}
}          
if (OrderSymbol()== Pair1 && OrderType() == OP_SELL && (( OrderProfit() - OrderCommission() ) / OrderLots() / MarketInfo( Pair1, MODE_TICKVALUE )) <= tp_level) {
OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),OrderOpenPrice()-tp*MarketInfo(Pair1,MODE_POINT) + spread,0,Green);}

{
if (OrderSymbol()== Pair2 && OrderType() == OP_BUY && (( OrderProfit() - OrderCommission() ) / OrderLots() / MarketInfo( Pair2, MODE_TICKVALUE )) <= tp_level) {
OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),OrderOpenPrice()+tp*MarketInfo(Pair2,MODE_POINT),0,Green);}
}          
if (OrderSymbol()== Pair2 && OrderType() == OP_SELL && (( OrderProfit() - OrderCommission() ) / OrderLots() / MarketInfo( Pair2, MODE_TICKVALUE )) <= tp_level) {
OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),OrderOpenPrice()-tp*MarketInfo(Pair2,MODE_POINT) + spread,0,Green);}

}
return;
}
Files: