Metatrader Forum | Forex Expert-Advisor | Broker & Forex Tools

Metatrader Forum | Forex Expert-Advisor | Broker & Forex Tools (http://www.expert-advisor.com/forum/index.php)
-   Programmierung MQL4 (http://www.expert-advisor.com/forum/forumdisplay.php?f=220)
-   -   Breakeven Berechnung mit Buys und Sells (http://www.expert-advisor.com/forum/showthread.php?t=6017)

dundale 02.03.18 02:50

Breakeven Berechnung mit Buys und Sells
 
Hallo alle zusammen,

vorweg ein Beispiel: nehmen wir an ich eröffne eine EURUSD-Buy-Position mit einer Lotsize von 0.03, nachdem ich 50 Pips Verlust habe, eröffne ich eine EURUSD-Sell-Position mit einer Lotsize von 0.05.

Wie errechne ich den Breakeven?

(Ich kann den Breakeven berechnen, aber nur wenn es sich um Buys ODER Sells handelt.)

Kann mir jemand helfen?

traderdoc 02.03.18 13:55

Folgende Berechnung für ein Beispiel des Open-Kurses der 0,03 Lot BuyOrder bei
1,23456 und des Open-Kurses der 0,05 Lot SellOrder um 50 Pips unter dem BuyEntry:

BE-Kurs = (0,03*1,23456 - 0,05*1,22956)/(0,03 - 0,05)

BE-Kurs = 1,22206

traderdoc

dundale 02.03.18 17:13

Vielen Dank für die schnelle Antwort. Ich habe versucht deine Formel in einen Code zu packen.

Ich bin nicht der große MQL4-Profi, aber in einem kleinen Test errechnete die Funktion den richtigen BE. Natürlich muss man noch den Spread berücksichtigen.

Kann man diesen Code so nehmen oder wie könnte man den Code noch verbessern?

Code:

double BreakevenOfAllTrades()
  {
  double Total=0,
  buy_TotalLots=0,
  buy_price= 0,
  buy_lots =0,
  buy_pricetimeslots=0,
  buy_TotalPriceTimesLots=0,
  sell_TotalLots=0,
  sell_price= 0,
  sell_lots =0,
  sell_pricetimeslots=0,
  sell_TotalPriceTimesLots=0;
  for(int cnt=0;cnt<OrdersTotal();cnt++)
    {
      if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES))
        if(OrderSymbol() == Symbol())
            if(OrderType()==OP_BUY)
              {
              buy_price = OrderOpenPrice();
              buy_lots = OrderLots();
              buy_pricetimeslots = buy_price * buy_lots;
              buy_TotalLots += buy_lots;
              buy_TotalPriceTimesLots += buy_pricetimeslots;
              }
            if(OrderType()==OP_SELL)
              {
              sell_price = OrderOpenPrice();
              sell_lots = OrderLots();
              sell_pricetimeslots = sell_price * sell_lots;
              sell_TotalLots += sell_lots;
              sell_TotalPriceTimesLots += sell_pricetimeslots;
              }
    }
  if(buy_TotalLots > sell_TotalLots || buy_TotalLots < sell_TotalLots)
      Total=(buy_TotalPriceTimesLots - sell_TotalPriceTimesLots) / (buy_TotalLots - sell_TotalLots);
  return(Total);
  }


traderdoc 02.03.18 17:36

Der Code ist korrekt und geht auch fast! nicht zu verkürzen, außer:

Code:

double BreakevenOfAllTrades()
  {
  double Total=0,
  buy_TotalLots=0,
  price= 0,
  lots =0,
  buy_pricetimeslots=0,
  buy_TotalPriceTimesLots=0,
  sell_TotalLots=0,
  sell_pricetimeslots=0,
  sell_TotalPriceTimesLots=0;
  for(int cnt=0;cnt<OrdersTotal();cnt++)
    {
      if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES))
        if(OrderSymbol() == Symbol())
            price = OrderOpenPrice();
            lots = OrderLots();
            if(OrderType()==OP_BUY)
              {
              buy_pricetimeslots = price * lots;
              buy_TotalLots += lots;
              buy_TotalPriceTimesLots += buy_pricetimeslots;
              }
            if(OrderType()==OP_SELL)
              {
              sell_pricetimeslots = price * lots;
              sell_TotalLots += lots;
              sell_TotalPriceTimesLots += sell_pricetimeslots;
              }
    }
  if(buy_TotalLots != sell_TotalLots)
      Total=(buy_TotalPriceTimesLots - sell_TotalPriceTimesLots) / (buy_TotalLots - sell_TotalLots);
  return(Total);
  }

traderdoc

dundale 04.03.18 22:46

Vielen Dank für die Hilfe.


Alle Zeitangaben in WEZ +2. Es ist jetzt 22:52 Uhr.

Powered by vBulletin® Version 3.8.5 (Deutsch)
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.6.1
Powered by vBCMS® 2.7.0 ©2002 - 2024 vbdesigns.de
Copyright ©2009 - 2023 by Expert-Advisor.com - Das Metatrader Forum