Breakeven loss adjustment for a group of trades.

MQL4 Indicators Experts

Specification

The attached code segment below, takes a specific symbol and side (BUY/SELL) and calculates the average price for the group of trades and applies a breakeven so hat the sum of the trades closes at breakeven (closes at the same price).

I need a version of this BEP2 code segment I need a dollar value offset added into the price, for example if a $50 loss is specified, the applied TP to the group of open trades on the sell side, the total loss for the group of trades would be $50.


Code:

//________________________________________________________________________ 

void BEP2(string symb1, int orderType)

  {

   double avgbuy=0,avgsell=0;

   double totpricesell=0,totpricebuy=0;

   int OrderBuy=0,OrderSell=0;

   double lotbuy=0,lotsell=0;

   int ticket=0;

   double val=0;

   double poin = MarketInfo(symb1,MODE_POINT);

   int    digit= (int)MarketInfo(symb1,MODE_DIGITS);

   for(int cnt = 0; cnt < OrdersTotal(); cnt++)

     {

      if(OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES))

        {

         if(OrderSymbol()==symb1 && (OrderMagicNumber()>= magic))

           {


            if(OrderType()==OP_BUY)

              {

               OrderBuy++;

               lotbuy+=OrderLots();

               totpricebuy += (OrderOpenPrice()) * OrderLots();

              }


            if(OrderType()==OP_SELL)

              {

               OrderSell++;

               lotsell+=OrderLots();

               totpricesell += (OrderOpenPrice()) * OrderLots();

              }


           }

        }

     }


   if(OrderSell > 0 && totpricesell!=0)

      avgsell = NormalizeDouble(totpricesell / lotsell, digit);

   if(OrderBuy > 0 && totpricebuy!=0)

      avgbuy = NormalizeDouble(totpricebuy / lotbuy, digit);



   for(int cnt = 0; cnt < OrdersTotal(); cnt++)

     {

      if(OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES))

        {

         if(OrderSymbol()==symb1 && (OrderMagicNumber()>= magic) && (StringSubstr(OrderComment(),0,4)=="to #" || StringSubstr(OrderComment(),0,6)=="from #"))

           {


            if(OrderType()==OP_BUY)

              {

               ticket=OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),NormalizeDouble(avgbuy+CommisionPoint*poin,digit),0,clrYellow);

              }

            if(OrderType()==OP_SELL)

              {

               ticket=OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),NormalizeDouble(avgsell-CommisionPoint*poin,digit),0,clrYellow);

              }


           }

        }

     }


   if(ticket>0)

      ok++;


  } 


Responded

1
Developer 1
Rating
(7)
Projects
12
8%
Arbitration
3
0% / 67%
Overdue
4
33%
Free
2
Developer 2
Rating
(72)
Projects
80
10%
Arbitration
38
8% / 58%
Overdue
6
8%
Free
3
Developer 3
Rating
(390)
Projects
416
30%
Arbitration
74
19% / 72%
Overdue
52
13%
Working
4
Developer 4
Rating
Projects
0
0%
Arbitration
0
Overdue
0
Free
Similar orders
Convert Time Range Breakout Indicator to Strategy (Pine Script) I have an existing Time Range Breakout indicator on TradingView. I need a developer to convert it into a fully functional strategy with proper trade execution logic. Strategy Logic: Time Range: Define a specific time range (e.g., 03:00 – 04:30) During this time, the indicator marks the High and Low range Entry Conditions Buy when price touches the range
Hello, I’m looking for an experienced MQL4 developer to build a custom MT4 Expert Advisor based on a Koncorde-style indicator strategy. Here are the main requirements: 🔹 General Overview The EA must be a master EA , running on a single chart and managing multiple currency pairs simultaneously No need to attach EA to each chart Must support a configurable list of symbols 🔹 Indicator Requirement Develop a custom
I want to find a Developer to perform this work and settle payments in this Application. I undertake not to communicate with Applicants anywhere else except this Application, including third-party
Hi guys I’m looking for a coder who’s experienced in one script. The candidate must be familiar with fractals and self similarity. If you can’t code self similarity, please don’t bother contacting me ( respectfully). I just don’t want us to waste each others time. My budget is 100$. If that’s too low for you please, don’t contact me. Only contact me if you can code self similarity and can accept 100$. I will provide
I hope to acquire a profitable and existing expert advisor (EA) from the gold market, with complete source code, to add to our client portfolio. you can WECHAT: Faca7898 Please note EA when adding friends. It should be clarified that this does not require you to formulate or design new strategies. If you already have a verified, consistent, and production-ready EA, I am willing to purchase it immediately and engage
Core Requirements: Platform: MetaTrader 5 (MT5). Symbol: XAUUSD (Gold). Timeframes: M1 and M5 (user selectable). Trading Style: Scalping with controlled risk (not aggressive or high-risk strategies) -> adjustable, even better. Execution: Fast execution, optimized for gold market conditions. Frequence = adjustable, but there should be 10-20 trades per day. Strategy Logic: Use a reliable and conservative strategy
Eu preciso disso. A linha central do TMA (17,5,1.5) será a principal referência. Outra linha de média móvel (AVG) de 3 períodos decrescentes 2. As ordens serão as seguintes: abaixo, somente compra de TMA; acima, somente venda de TMA. O sinal de entrada será o seguinte: se o preço estiver acima da Média Móvel Tarifária (TMA), será apenas para venda; quando o preço se mantiver abaixo da Média Móvel Tarifária (AVG)
I am looking for non-repainting indicator to run in all sessions for scalping gold , happy to discuss if you have developed such indicators which can show profit and stop loss levels
Hello! I want to buy two indicators: A Support and Resistence Indicator and a Trendline Indicator. Support and Resistence Indicators needs to automatically draws Support and Resistance lines based on High and Low Candle in every time-frame (If possible time-frame needs to be in inputs and choose by me what time-frame i want indicator to draw lines) Trendline Indicator needs to automatically draws Trendline Channels
I need an experienced developer to carry out an indicator and trading robot using the following; moving averages risk ( take profit and stop loss) and maximum drawdown limits heiken ashi confirmation. trendline breakout if possible The developer will test this on a demo account that I will provide before conclusion as I don’t want anyone to waste my time trying to use chartgpt trial and error. If you can do the

Project information

Budget
30+ USD
Deadline
to 2 day(s)