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
(6)
Projects
12
8%
Arbitration
1
0% / 100%
Overdue
4
33%
Free
2
Developer 2
Rating
(67)
Projects
74
7%
Arbitration
32
9% / 56%
Overdue
6
8%
Working
3
Developer 3
Rating
(374)
Projects
396
31%
Arbitration
61
20% / 67%
Overdue
49
12%
Loaded
4
Developer 4
Rating
Projects
0
0%
Arbitration
0
Overdue
0
Free
Similar orders
Hey, I would like to work again with you to create an indicator based on calculation with the last price, sort of fib. I give a pdf introducing the concept I have a source code in pinescript of the concept. Thanks
Looking for someone to build easy info panel take a look at the picture Info Panel Today profit xxxxxx week profit xxxxxxx month profit xxxxxxx Account Balance: Leveraged: Account Name: Server: Number of trade today : History Of the last 10 Profit trades Total of Profit Today $
Reverse engineer of these Eas which will be provided. Must work identical. Doesn't works more we just need to reverse engineer it so we can understand it the logic. these two stopped working after MT4 update this happened a few years ago but it was a quick fix in code and thats it
My indicator is plotting many arrows before the spikes on a chart help me how can I reduce the number of arrows I tried to fix it on metaeditor but still. I will share the indicator
I'm in need of an experienced Meta 4 expert who can solve two specific problems and improve the current Martingale and Pyramid strategies within my EA. - Bug Fix: The EA is currently facing an issue where orders are not being executed correctly. This is causing a signal matching error and leading to potential losses. The primary task is to resolve this bug and ensure the EA executes trades accurately and as intended
I need an experienced developer who can turn my simply strategy to an EA on MT5 and MT4, will be using two EMAs and MACD and a risk management setting, please message me on time so we start work on it, waiting for you
Dear expert developer I have been trading futures and mainly indices for about 5 years and would now like to automate my trading strategy with the help of an intelligently set up bot. My strategy, which would have to be implemented, is mainly based on the following indicators: CCI / RSI / MACD and Stochastic I analyze the market according to volume peaks, the daily highs and lows and the prominent points and look for
Tim: //+------------------------------------------------------------------+ //| ggjhjh.mq4 | //| Copyright 2023, MetaQuotes Ltd. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property indicator_chart_window #property indicator_buffers 1
I need a developer that can turn my strategy to an EA, We will be using Fib, some indicators and a risk management settings, please message me on time so we start work on it, waiting for you
hello developers.i am currently looking for a simple line chart custom indicator,whenever the line char makes a horizontal line and the next bar closes bullish after the horizontal line an up arrow should draw and if we get a bearish bar a down arrow should draw...the indicator should also be able to send out all types of alerts.thank you

Project information

Budget
30+ USD
For the developer
27 USD
Deadline
to 2 day(s)