Global Take Profit for Hedged Trades MT5

MQL5 지표 전문가

명시

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++;

  }


응답함

1
개발자 1
등급
(146)
프로젝트
172
23%
중재
7
29% / 43%
기한 초과
4
2%
작업중
2
개발자 2
등급
(158)
프로젝트
226
22%
중재
15
60% / 20%
기한 초과
1
0%
로드됨
3
개발자 3
등급
(166)
프로젝트
180
32%
중재
6
50% / 50%
기한 초과
2
1%
작업중
4
개발자 4
등급
(376)
프로젝트
475
40%
중재
83
36% / 33%
기한 초과
13
3%
바쁜
5
개발자 5
등급
(56)
프로젝트
65
6%
중재
25
20% / 36%
기한 초과
4
6%
로드됨
6
개발자 6
등급
(71)
프로젝트
80
10%
중재
35
9% / 54%
기한 초과
6
8%
작업중
비슷한 주문
Utilizing the MQL5 MetaEditor Wizard, I created an Expert Advisor, having the following Signal indicators: I was able to optimize the EA and reached a backtest with the following specifications: I was able to reach a profit level of 30K, as indicated below. However, the Bot is not without faults and following the backtest, I started a forward test with real live data and the results were not so great. The EA took a
Connect from Mt5 via binary deriv account api I have mt5 indicator, need to connect with binary deriv account through api. If anyone can setup via API then contact me. everything control mt5
Hello I am looking for a developer to create an 50% retracement Indicator of the previous candle . So once a candle close the Indicator is supposed to take the full candle size from high to low and make a 61% and 50% level on that candle and I would like the candle to show until the next previous candle is done creating. After this I would look to create an ea with it possibly
Hi, I have 2 indicators which are based on the super trend , the alerts on indicator (1) does not work at all , and on the other indicator the alerts do not come on time on time, which is kind of delayed. see attached file below
Looking for an experienced developer to modify my existing TDI strategy , want to add filter for Buy and Sell Signals, Arrows are displayed on chart and what only to leave high accurate arrows Source code to be provided
I have the mq5 file, I need a buffer adding to the indicator, so it appears in the data window so I can reference it later in an EA. As the below screenshot shows, there is a median ray line from yesterday (the dashed horizontal line) - I want this value in the data window called Median Ray. I want this to be a single value per day, so todays Median Ray would be 17868, and so on each day. So I want all the Developing
I would like to develop my own indicator on metatrader 4 and tradingview. We would start with a basic version that we would improve later. It is an indicator based on several analyses and which would provide several indications. I am looking for someone who can develop on MT4 and Mt5, initially I would like to do it on mt4 and then on mt5. If you have expertise in pinescript it is a plus because I would like to
I urgently require swift assistance to convert a complex indicator into a fully functional scanner, capable of automatically sending real-time data, alerts, and notifications via email, ensuring seamless integration and prompt delivery of critical information to facilitate informed decision-making and timely action
I need to improve the code of an indicator that is too heavy and slow when running and when used with iCustom in an EA. No other changes to the indicator are requested: the original features of the indicator should remain as theay are. I'll provide the indicator after job acceptance. I request final source code mq5 file. Thank you Regards
I have a mt5 indicator that is working perfectly but I will like to make it an expert advisor to have an automated trade. I will be glad if I can get a well experienced developer to execute this project. Thanks

프로젝트 정보

예산
30+ USD
개발자에게
27 USD
기한
 1 일