|
Programmierung MQL4 Hier gehts rund ums Programmieren in MQL4. |
|
Themen-Optionen | Thema durchsuchen | Ansicht |
|
|||
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? |
|
|||
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
__________________
Ich erfülle Euch gern Eure EA-, Indikator- und Script-Programmierungswünsche auf Honorarbasis. |
|
|||
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); } |
|
|||
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); }
__________________
Ich erfülle Euch gern Eure EA-, Indikator- und Script-Programmierungswünsche auf Honorarbasis. |
Lesezeichen |
Stichworte |
breakeven, breakeven berechnen, mql4, programmierung, programmierung metatrader, programmierung mql4 |
|
|