Global Take Profit for Hedged Trades MT5

MQL5 Indicatori Esperti

Specifiche

I currently have a simple function in MT4, which sets a global take profit for the trades open and the hedged trades.

//--- Setup Global Take Profit
   if(was_trade)
     {
      orders_total = OrdersTotal();
      for(index = orders_total - 1; index >= 0; index--)
        {
         if(!OrderSelect(index, SELECT_BY_POS, MODE_TRADES))
            continue;
         if(OrderMagicNumber() != vInpMagic || OrderSymbol() != m_symbol)
            continue;
         order_type = OrderType();
         if(m_direction > 0)
           {
            if(order_type == OP_BUY)
               res = OrderModify(OrderTicket(), OrderOpenPrice(), OrderStopLoss(), level, 0);
            if(order_type == OP_SELL)
               res = OrderModify(OrderTicket(), OrderOpenPrice(), level, 0.0, 0);
           }
         if(m_direction < 0)
           {
            if(order_type == OP_BUY)
               res = OrderModify(OrderTicket(), OrderOpenPrice(), level, 0.0, 0);
            if(order_type == OP_SELL)
               res = OrderModify(OrderTicket(), OrderOpenPrice(), OrderStopLoss(), level, 0);
           }
        }
     }
  }

In MT5, I have this which sets a Take Profit for the group of trades on one side. What I need is for this PIP_TP code to be able set a group take profit for the hedged trades as well (trades with a defined magic number, that is the same as the inverse side - but a Stop Loss instead of a take profit.


void PIP_TP(const string symb, int orderType = -1, long magical = 0)
  {
   double avg_price=0;
   double totprice=0;
   int Order_cnt=0;
   double lots=0;
   bool ticket=false;


   for(int cnt = 0; cnt < PositionsTotal(); cnt++)
     {
      if(position.SelectByIndex(cnt))
        {
         if(position.PositionType()!= orderType)
            continue;
         if(position.Magic() != magical)
            continue;
         if(position.Symbol()!=symb)
            continue;

         Order_cnt++;
         lots+=position.Volume();
         totprice += (position.PriceOpen()) * position.Volume();
        }
     }

   if(Order_cnt==0)
      return;

   int digit= (int)SymbolInfoInteger(symb,SYMBOL_DIGITS);
   
   double ask = SymbolInfoDouble(symb, SYMBOL_ASK);
   double pipleveldiff = ask * 0.0001;
   double poin = NormalizeDouble(pipleveldiff, digit);

   if(Order_cnt == 10) // Max Trades
      poin = 0;

   if(Order_cnt > 0 && totprice!=0)
      avg_price = NormalizeDouble(totprice / lots, digit);


   for(int cnt = 0; cnt < PositionsTotal(); cnt++)
     {
      if(position.SelectByIndex(cnt))
        {
         if(position.PositionType()!= orderType)
            continue;
         if(position.Magic() != magical)
            continue;
         if(position.Symbol()!=symb)
            continue;
         double current_takeprofit = position.TakeProfit();
         if(position.PositionType()==OP_BUY && current_takeprofit != 0 && current_takeprofit < NormalizeDouble(avg_price+poin,digit)) continue;
         if(position.PositionType()==OP_SELL && current_takeprofit != 0 && current_takeprofit > NormalizeDouble(avg_price-poin,digit)) continue;
         
         if(position.PositionType()==OP_BUY && current_takeprofit != NormalizeDouble(avg_price+poin,digit))
           {
            ticket=trade.PositionModify(position.Ticket(),position.StopLoss(),NormalizeDouble(avg_price+poin,digit));
            //  mod_cnt++;
           }
         if(position.PositionType()==OP_SELL && current_takeprofit != NormalizeDouble(avg_price-poin,digit))
           {
            ticket=trade.PositionModify(position.Ticket(),position.StopLoss(),NormalizeDouble(avg_price-poin,digit));
            // mod_cnt++;
           }
        }
     }
   if(ticket)
      ok++;

  }


Con risposta

1
Sviluppatore 1
Valutazioni
(157)
Progetti
187
26%
Arbitraggio
8
25% / 38%
In ritardo
5
3%
Caricato
2
Sviluppatore 2
Valutazioni
(177)
Progetti
243
21%
Arbitraggio
17
65% / 18%
In ritardo
1
0%
In elaborazione
3
Sviluppatore 3
Valutazioni
(169)
Progetti
185
32%
Arbitraggio
6
50% / 50%
In ritardo
2
1%
Caricato
4
Sviluppatore 4
Valutazioni
(397)
Progetti
502
38%
Arbitraggio
83
37% / 33%
In ritardo
13
3%
Occupato
5
Sviluppatore 5
Valutazioni
(58)
Progetti
66
6%
Arbitraggio
27
19% / 37%
In ritardo
4
6%
Caricato
6
Sviluppatore 6
Valutazioni
(72)
Progetti
80
10%
Arbitraggio
36
8% / 53%
In ritardo
6
8%
In elaborazione
Ordini simili
Im looking for an coder to code an EA: Trade management 1. opening trades according to the indicator 2. trades settings to choose from like: open all trades according to the signal open only trade 1,2,3 or 4 % per trade ( example 50/30/20 of the lot settings, with 4 trades it would be for example 50/30/10/10) 3. SL/Trailing settings: Move SL to entry after hitting TP1/TP2 or TP3 moving SL by % keep the original SL
Hi I'm looking to have 2 of my pinescript strategies converted to MQL5 and was wondering if you could first give me a quote for the more simple strategy and then for both the simple and complex strategy together. The simple strategy is a MACD crossover type thing that uses a special EMA script that filters out some ranging price action and also fractal candles for the stop loss. The second strategy is market
I want grate robot for making profits that know when to start a good trade and close a trade and must be active all time to avoid lost of money
I have developed a very strong TradingView strategy in Pine Script but unfortunately, a third-party connector is requiired and in my opinion, I want a more direct connection. I am not brilliant at coding, but I have coded the majority of the MT5 code and I would like you to make sure that the MT5 code matches my TradingView script and executes the same way as the TradingView script that I will provide if you are
Mbeje fx 50+ USD
I like to own my robot that why I want to build my own.i like to be a best to every robot ever in the life to be have more money
I need an MT5 EA that can do the following: I have to give the EA a price in advance, when the price is reached the EA has to automatically place a buy stop or sell stop order 0.5 pips below or above the price. Is this possible
Dr Pattern 30+ USD
good day i need the service of the seaso coder to help me fix my ea The Job required 1 knowledge of Mt4 and Mt5 indicator coding 2. Telegram code 3. ability to code indicator to work on multiple Time frame combine to trade 4 Ability to Join two or three indicator on same ir different time frame if you have these skill please let chart i will discuss the details of the Job inside to you The required day including
Good day, I want someone to help me create a universal news filter with on/off switch, with start and end settings, and drawdown control with magic number of EAs, etc. Thanks
Hello, I am looking for a professional programmer to optimize my existing EA integrating it with ChatGPT to analyze currencies using various methods to make the right trading decisions. i want it to be an EA that can be trusted to carry trade with the help of chat gpt and also have a very low drawdown
Hello, I am looking for a professional programmer to create a trading expert on the MT4 platform, integrating it with ChatGPT to analyze currencies using various methods to make the right trading decisions. Further details will be provided to the applicants later

Informazioni sul progetto

Budget
30+ USD
Per lo sviluppatore
27 USD
Scadenze
a 1 giorno(i)