Automatic calculation of break even and TP

 

Hello guys I'm wondering if is there an EA to automaticaly calculate Break Even and Take Profit on manual trading.

Let's say I open a BUY position 0,01 Lot on eurusd at 1.10000 and TP 1.10500 (50 pips) and the trade goes against me "X" pips, then I open 0,02 Lot at 1.09700 (-30 pips), 0,03 Lot at 1.09300 (-70 pips), 0,04 Lot at 1.09000 and so on...

Considering just 2 first trades to simplify, when I open second trade (0,02) at -30 pips the EA must print on the chart the break even line and the TP of 50 pips from the BE line

Manualy calculating, BE would be at 1.09800 (0.01X20 pips= -20) + (0.02X10 pips= +20) and TP would be 1.09800 + 50 pips = 1.10300

In attachement I send a Picture to have an idea of what I need.

I don't know how to code this and sometimes the calculation is hard for me.

Thank you for your help eurusd

 
mormix:

Hello guys I'm wondering if is there an EA to automaticaly calculate Break Even and Take Profit on manual trading.

Let's say I open a BUY position 0,01 Lot on eurusd at 1.10000 and TP 1.10500 (50 pips) and the trade goes against me "X" pips, then I open 0,02 Lot at 1.09700 (-30 pips), 0,03 Lot at 1.09300 (-70 pips), 0,04 Lot at 1.09000 and so on...

Considering just 2 first trades to simplify, when I open second trade (0,02) at -30 pips the EA must print on the chart the break even line and the TP of 50 pips from the BE line

Manualy calculating, BE would be at 1.09800 (0.01X20 pips= -20) + (0.02X10 pips= +20) and TP would be 1.09800 + 50 pips = 1.10300

In attachement I send a Picture to have an idea of what I need.

I don't know how to code this and sometimes the calculation is hard for me.

Thank you for your help

Hello,

I post a function of my old project to take a idea how to can this.

double DigitPoints=0;
int MultiplierPoint=1;

//====================================================================================================================================================//
//OnInit function
//====================================================================================================================================================//
int OnInit()
  {
//------------------------------------------------------
//Broker 4 or 5 digits
   DigitPoints=MarketInfo(Symbol(),MODE_POINT);
   MultiplierPoint=1;
   if(MarketInfo(Symbol(),MODE_DIGITS)==3||MarketInfo(Symbol(),MODE_DIGITS)==5) MultiplierPoint=10;
   //---
   DigitPoints*=MultiplierPoint;
//------------------------------------------------------
   return(INIT_SUCCEEDED);
  }

//====================================================================================================================================================//
//Break even levels and lines
//====================================================================================================================================================//
void CreatBreakEvenLine()
  {
   double BuyBreakEvenLevel=0;
   double SellBreakEvenLevel=0;
   string NameOfBuyLine;
   string NameOfSellLine;
   string PREFIX="#";
//---Count levels for buy orders
   if(BuyOrders>0)
     {
      BuyBreakEvenLevel=Bid+(((PipsBuy/TotalLotBuy))*DigitPoints);
     }
//---Count levels for sell orders
   if(SellOrders>0)
     {
      SellBreakEvenLevel=Ask-(((PipsSell/TotalLotSell))*DigitPoints);
     }
//---Break even lines in screen
   NameOfBuyLine=PREFIX+" Buy Break Even Level";
   NameOfSellLine=PREFIX+" Sell Break Even Level";
//---
   if(BuyOrders>0)
     {
      //---Creat line
      if(ObjectFind(NameOfBuyLine)==-1)
        {
         ObjectCreate(NameOfBuyLine,OBJ_HLINE,0,0,0);
         ObjectSet(NameOfBuyLine,OBJPROP_COLOR,clrBlue);
         ObjectSet(NameOfBuyLine,OBJPROP_STYLE,STYLE_DOT);
         ObjectSet(NameOfBuyLine,OBJPROP_PRICE1,BuyBreakEvenLevel);
        }
      //---Move line
      if(ObjectFind(NameOfBuyLine)>-1)
        {
         if(NormalizeDouble(ObjectGet(NameOfBuyLine,OBJPROP_PRICE1),Digits)!=NormalizeDouble(BuyBreakEvenLevel,Digits)) ObjectMove(0,NameOfBuyLine,0,Time[0],BuyBreakEvenLevel);
        }
     }
//---Delete line
   if(BuyOrders==0)
     {
      if(ObjectFind(NameOfBuyLine)>-1) ObjectDelete(NameOfBuyLine);
     }
//---------------------------------------------------------------------
   if(SellOrders>0)
     {
      //---Creat line
      if(ObjectFind(NameOfSellLine)==-1)
        {
         ObjectCreate(NameOfSellLine,OBJ_HLINE,0,0,0);
         ObjectSet(NameOfSellLine,OBJPROP_COLOR,clrRed);
         ObjectSet(NameOfSellLine,OBJPROP_STYLE,STYLE_DOT);
         ObjectSet(NameOfSellLine,OBJPROP_PRICE1,SellBreakEvenLevel);
        }
      //---Move line
      if(ObjectFind(NameOfSellLine)>-1)
        {
         if(NormalizeDouble(ObjectGet(NameOfSellLine,OBJPROP_PRICE1),Digits)!=NormalizeDouble(SellBreakEvenLevel,Digits)) ObjectMove(0,NameOfSellLine,0,Time[0],SellBreakEvenLevel);
        }
     }
//---Delete line
   if(SellOrders==0)
     {
      if(ObjectFind(NameOfSellLine)>-1) ObjectDelete(NameOfSellLine);
     }
//---
  }


 
mormix:

Hello,

How do I put this in an indicator? Not very good coding

I hope that you meant that you are not very good at coding!

As it is, it appears that you are criticising the code that Nikolaos has kindly provided.

 
Keith Watford:

I hope that you meant that you are not very good at coding!

As it is, it appears that you are criticising the code that Nikolaos has kindly provided.

Sorry, I have updated my answer as I noticed that.

 
Nikolaos Pantzos:

Hello,

I post a function of my old project to take a idea how to can this.



Hi Nikolaos, how do I put this in an indicator? I am not good on coding and thank you for your help.

 
mormix: how do I put this in an indicator? I am not good on coding 
  1. MT4: Learn to code it.
    MT5: Begin learning to code it. If you don't learn MQL4/5, there is no common language for us to communicate. If we tell you what you need, you can't code it. If we give you the code, you don't know how to integrate it into yours.
  2. or pay (Freelance) someone to code it.
              Hiring to write script - General - MQL5 programming forum
We're not going to code it for you (although it could happen if you are lucky or the problem is interesting.) We are willing to help you when you post your attempt (using CODE button) and state the nature of your problem.
          No free help
 
William Roeder:
  1. MT4: Learn to code it.
    MT5: Begin learning to code it. If you don't learn MQL4/5, there is no common language for us to communicate. If we tell you what you need, you can't code it. If we give you the code, you don't know how to integrate it into yours.
  2. or pay (Freelance) someone to code it.
              Hiring to write script - General - MQL5 programming forum
We're not going to code it for you (although it could happen if you are lucky or the problem is interesting.) We are willing to help you when you post your attempt (using CODE button) and state the nature of your problem.
          No free help

Hi William, thank you for your answer, I understand what you're saying. I have some knowlege in PHP and HTML5 but I'm not very good in C++. I will read a bit more about MT4/MT5 coding and I will get there :) 

Reason: